mirror of
https://github.com/YTVanced/VancedManager
synced 2025-01-03 14:10:59 +00:00
implemented a better way to animate welcome activity
This commit is contained in:
parent
8c4b8332e8
commit
ae1d5691ac
20 changed files with 115 additions and 271 deletions
|
@ -11,8 +11,6 @@ import com.vanced.manager.model.SponsorModel
|
|||
import com.vanced.manager.ui.viewmodels.HomeViewModel
|
||||
import com.vanced.manager.utils.LIGHT
|
||||
import com.vanced.manager.utils.currentTheme
|
||||
import com.vanced.manager.utils.defPrefs
|
||||
import com.vanced.manager.utils.managerTheme
|
||||
|
||||
class SponsorAdapter(
|
||||
private val context: Context,
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package com.vanced.manager.adapter
|
||||
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import com.vanced.manager.ui.fragments.GrantRootFragment
|
||||
import com.vanced.manager.ui.fragments.SelectAppsFragment
|
||||
import com.vanced.manager.ui.fragments.WelcomeFragment
|
||||
|
||||
class WelcomePageAdapter(activity: FragmentActivity) : FragmentStateAdapter(activity) {
|
||||
|
||||
override fun getItemCount(): Int = 3
|
||||
|
||||
override fun createFragment(position: Int): Fragment {
|
||||
return when (position) {
|
||||
0 -> WelcomeFragment()
|
||||
1 -> SelectAppsFragment()
|
||||
2 -> GrantRootFragment()
|
||||
else -> throw IllegalArgumentException("Unknown fragment")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,21 +1,84 @@
|
|||
package com.vanced.manager.ui
|
||||
|
||||
import android.animation.Animator
|
||||
import android.animation.ValueAnimator
|
||||
import android.os.Bundle
|
||||
import android.view.animation.AccelerateDecelerateInterpolator
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.navigation.findNavController
|
||||
import com.vanced.manager.R
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import com.vanced.manager.adapter.WelcomePageAdapter
|
||||
import com.vanced.manager.databinding.ActivityWelcomeBinding
|
||||
import kotlin.math.abs
|
||||
|
||||
class WelcomeActivity : AppCompatActivity() {
|
||||
|
||||
private val navHost by lazy { findNavController(R.id.welcome_navhost) }
|
||||
private lateinit var viewPager2: ViewPager2
|
||||
private lateinit var binding: ActivityWelcomeBinding
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_welcome)
|
||||
binding = ActivityWelcomeBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
viewPager2 = binding.welcomeViewpager
|
||||
viewPager2.apply {
|
||||
adapter = WelcomePageAdapter(this@WelcomeActivity)
|
||||
isUserInputEnabled = false
|
||||
setPageTransformer { page, position ->
|
||||
page.apply {
|
||||
val pageWidth = width
|
||||
//Thank you, fragula dev!
|
||||
when {
|
||||
position > 0 && position < 1 -> {
|
||||
alpha = 1f
|
||||
translationX = 0f
|
||||
}
|
||||
position > -1 && position <= 0 -> {
|
||||
alpha = 1.0f - abs(position * 0.7f)
|
||||
translationX = -pageWidth * position / 1.3F
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (!navHost.popBackStack())
|
||||
finish()
|
||||
if (viewPager2.currentItem == 0) {
|
||||
super.onBackPressed()
|
||||
} else {
|
||||
navigateTo(viewPager2.currentItem - 1)
|
||||
}
|
||||
}
|
||||
|
||||
fun navigateTo(position: Int) {
|
||||
viewPager2.currentPosition = position
|
||||
}
|
||||
|
||||
//Shit way to implement animation duration, but at least it works
|
||||
private var ViewPager2.currentPosition: Int
|
||||
get() = currentItem
|
||||
set(value) {
|
||||
val pixelsToDrag: Int = width * (value - currentItem)
|
||||
val animator = ValueAnimator.ofInt(0, pixelsToDrag)
|
||||
var previousValue = 0
|
||||
animator.apply {
|
||||
addUpdateListener { valueAnimator ->
|
||||
val currentValue = valueAnimator.animatedValue as Int
|
||||
val currentPxToDrag = (currentValue - previousValue).toFloat()
|
||||
fakeDragBy(-currentPxToDrag)
|
||||
previousValue = currentValue
|
||||
}
|
||||
addListener(object : Animator.AnimatorListener {
|
||||
override fun onAnimationStart(animation: Animator?) { beginFakeDrag() }
|
||||
override fun onAnimationEnd(animation: Animator?) { endFakeDrag() }
|
||||
override fun onAnimationCancel(animation: Animator?) {}
|
||||
override fun onAnimationRepeat(animation: Animator?) {}
|
||||
})
|
||||
interpolator = AccelerateDecelerateInterpolator()
|
||||
duration = 500
|
||||
start()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package com.vanced.manager.ui.core
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
|
||||
open class SlidingConstraintLayout : ConstraintLayout {
|
||||
|
||||
constructor(context: Context) : super(context)
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(
|
||||
context,
|
||||
attrs
|
||||
)
|
||||
|
||||
var xFraction: Float
|
||||
get() {
|
||||
val width = width
|
||||
return if (width != 0)
|
||||
x / getWidth()
|
||||
else
|
||||
x
|
||||
}
|
||||
set(xFraction) {
|
||||
val width = width
|
||||
val newWidth =
|
||||
if (width > 0)
|
||||
xFraction * width
|
||||
else
|
||||
(1).toFloat()
|
||||
x = newWidth
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
package com.vanced.manager.ui.core
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.LinearLayout
|
||||
|
||||
open class SlidingLinearLayout: LinearLayout {
|
||||
|
||||
constructor(context: Context?) : super(context)
|
||||
constructor(context: Context?, attrs: AttributeSet?) : super(
|
||||
context,
|
||||
attrs
|
||||
)
|
||||
|
||||
var yFraction: Float
|
||||
get() {
|
||||
val height = height
|
||||
return if (height != 0)
|
||||
y / height
|
||||
else
|
||||
y
|
||||
}
|
||||
set(yFraction) {
|
||||
val height = height
|
||||
val newHeight =
|
||||
if (height > 0)
|
||||
yFraction * height
|
||||
else
|
||||
(1).toFloat()
|
||||
y = newHeight
|
||||
}
|
||||
|
||||
var xFraction: Float
|
||||
get() {
|
||||
val width = width
|
||||
return if (width != 0)
|
||||
x / getWidth()
|
||||
else
|
||||
x
|
||||
}
|
||||
set(xFraction) {
|
||||
val width = width
|
||||
val newWidth =
|
||||
if (width > 0)
|
||||
xFraction * width
|
||||
else
|
||||
(1).toFloat()
|
||||
x = newWidth
|
||||
}
|
||||
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package com.vanced.manager.ui.core
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
|
||||
open class SlidingSwipeRefreshLayout : SwipeRefreshLayout {
|
||||
|
||||
constructor(context: Context?) : super(context!!)
|
||||
constructor(context: Context?, attrs: AttributeSet?) : super(
|
||||
context!!,
|
||||
attrs
|
||||
)
|
||||
|
||||
var xFraction: Float
|
||||
get() {
|
||||
val width = width
|
||||
return if (width != 0)
|
||||
x / getWidth()
|
||||
else
|
||||
x
|
||||
}
|
||||
set(xFraction) {
|
||||
val width = width
|
||||
val newWidth =
|
||||
if (width > 0)
|
||||
xFraction * width
|
||||
else
|
||||
(1).toFloat()
|
||||
x = newWidth
|
||||
}
|
||||
}
|
|
@ -5,13 +5,13 @@ import android.view.LayoutInflater
|
|||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.core.content.edit
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.adapter.SelectAppsAdapter
|
||||
import com.vanced.manager.core.ui.base.BindingFragment
|
||||
import com.vanced.manager.databinding.FragmentSelectAppsBinding
|
||||
import com.vanced.manager.ui.WelcomeActivity
|
||||
|
||||
class SelectAppsFragment : BindingFragment<FragmentSelectAppsBinding>() {
|
||||
|
||||
|
@ -52,6 +52,6 @@ class SelectAppsFragment : BindingFragment<FragmentSelectAppsBinding>() {
|
|||
selectAdapter.apps.forEach { app ->
|
||||
prefs.edit { putBoolean("enable_${app.tag}", app.isChecked) }
|
||||
}
|
||||
findNavController().navigate(SelectAppsFragmentDirections.selectAppsToGrantRoot())
|
||||
(requireActivity() as WelcomeActivity).navigateTo(2)
|
||||
}
|
||||
}
|
|
@ -3,9 +3,9 @@ package com.vanced.manager.ui.fragments
|
|||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.vanced.manager.core.ui.base.BindingFragment
|
||||
import com.vanced.manager.databinding.FragmentWelcomeBinding
|
||||
import com.vanced.manager.ui.WelcomeActivity
|
||||
|
||||
class WelcomeFragment : BindingFragment<FragmentWelcomeBinding>() {
|
||||
|
||||
|
@ -20,10 +20,8 @@ class WelcomeFragment : BindingFragment<FragmentWelcomeBinding>() {
|
|||
}
|
||||
|
||||
private fun bindData() {
|
||||
binding.welcomeGetStarted.setOnClickListener { navigateToWelcome() }
|
||||
}
|
||||
|
||||
private fun navigateToWelcome() {
|
||||
findNavController().navigate(WelcomeFragmentDirections.welcomeToSelectApps())
|
||||
binding.welcomeGetStarted.setOnClickListener {
|
||||
(requireActivity() as WelcomeActivity).navigateTo(1)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<objectAnimator
|
||||
android:duration="@android:integer/config_mediumAnimTime"
|
||||
android:valueType="floatType"
|
||||
android:valueFrom="1.0"
|
||||
android:valueTo="0"
|
||||
android:propertyName="xFraction" />
|
||||
|
||||
</set>
|
|
@ -1,11 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<objectAnimator
|
||||
android:duration="@android:integer/config_mediumAnimTime"
|
||||
android:valueType="floatType"
|
||||
android:valueFrom="0"
|
||||
android:valueTo="1.0"
|
||||
android:propertyName="xFraction" />
|
||||
|
||||
</set>
|
|
@ -1,19 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<objectAnimator
|
||||
android:duration="@android:integer/config_longAnimTime"
|
||||
android:valueType="floatType"
|
||||
android:valueFrom="0"
|
||||
android:valueTo="-0.3"
|
||||
android:propertyName="xFraction" />
|
||||
|
||||
|
||||
<objectAnimator
|
||||
android:duration="@android:integer/config_longAnimTime"
|
||||
android:propertyName="alpha"
|
||||
android:valueFrom="1"
|
||||
android:valueTo="0.3"
|
||||
android:valueType="floatType" />
|
||||
|
||||
</set>
|
|
@ -1,19 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<objectAnimator
|
||||
android:duration="@android:integer/config_longAnimTime"
|
||||
android:valueType="floatType"
|
||||
android:valueFrom="-0.3"
|
||||
android:valueTo="0"
|
||||
android:propertyName="xFraction" />
|
||||
|
||||
|
||||
<objectAnimator
|
||||
android:duration="@android:integer/config_longAnimTime"
|
||||
android:propertyName="alpha"
|
||||
android:valueFrom="0.3"
|
||||
android:valueTo="1"
|
||||
android:valueType="floatType" />
|
||||
|
||||
</set>
|
|
@ -1,10 +0,0 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="?attr/toolbarIconColor"
|
||||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-6h2v6zM13,9h-2L11,7h2v2z"/>
|
||||
|
||||
</vector>
|
|
@ -1,16 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
<androidx.viewpager2.widget.ViewPager2
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/welcome_viewpager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.WelcomeActivity">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/welcome_navhost"
|
||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:defaultNavHost="true"
|
||||
app:navGraph="@navigation/welcome_navigation" />
|
||||
</RelativeLayout>
|
||||
android:layout_height="match_parent" />
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.vanced.manager.ui.core.SlidingConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?colorSurface">
|
||||
|
@ -9,14 +10,16 @@
|
|||
android:id="@+id/grant_root_header"
|
||||
android:text="@string/are_you_rooted"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
style="@style/WelcomeHeaderTitle" />
|
||||
style="@style/WelcomeHeaderTitle"
|
||||
tools:ignore="MissingConstraints" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/grant_root_description"
|
||||
android:text="@string/willing_to_use_root"
|
||||
android:textSize="13sp"
|
||||
app:layout_constraintTop_toBottomOf="@id/grant_root_header"
|
||||
style="@style/WelcomeHeaderSubtitle" />
|
||||
style="@style/WelcomeHeaderSubtitle"
|
||||
tools:ignore="MissingConstraints" />
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/grant_root_fab"
|
||||
|
@ -64,4 +67,5 @@
|
|||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:maxImageSize="48dp" />
|
||||
</com.vanced.manager.ui.core.SlidingConstraintLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.vanced.manager.ui.core.SlidingConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -37,4 +37,4 @@
|
|||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:maxImageSize="48dp" />
|
||||
|
||||
</com.vanced.manager.ui.core.SlidingConstraintLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.vanced.manager.ui.core.SlidingConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
@ -28,4 +28,5 @@
|
|||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
</com.vanced.manager.ui.core.SlidingConstraintLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<navigation
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/welcome_navigation"
|
||||
app:startDestination="@id/fragment_welcome">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/fragment_welcome"
|
||||
android:name="com.vanced.manager.ui.fragments.WelcomeFragment"
|
||||
tools:layout="@layout/fragment_welcome">
|
||||
|
||||
<action
|
||||
android:id="@+id/welcome_to_select_apps"
|
||||
app:destination="@id/fragment_select_apps"
|
||||
app:enterAnim="@animator/fragment_enter_right"
|
||||
app:exitAnim="@animator/welcome_exit"
|
||||
app:popEnterAnim="@animator/welcome_pop_enter"
|
||||
app:popExitAnim="@animator/fragment_exit_right"/>
|
||||
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/fragment_select_apps"
|
||||
android:name="com.vanced.manager.ui.fragments.SelectAppsFragment">
|
||||
|
||||
<action
|
||||
android:id="@+id/select_apps_to_grant_root"
|
||||
app:destination="@id/fragment_grant_root"
|
||||
app:enterAnim="@animator/fragment_enter_right"
|
||||
app:exitAnim="@animator/welcome_exit"
|
||||
app:popEnterAnim="@animator/welcome_pop_enter"
|
||||
app:popExitAnim="@animator/fragment_exit_right"/>
|
||||
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/fragment_grant_root"
|
||||
android:name="com.vanced.manager.ui.fragments.GrantRootFragment" />
|
||||
|
||||
</navigation>
|
|
@ -1,7 +1,6 @@
|
|||
<resources>
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
|
||||
<dimen name="twelvedp">12dp</dimen>
|
||||
<dimen name="stdp">16dp</dimen>
|
||||
<dimen name="top_header_margin">128dp</dimen>
|
||||
|
||||
|
|
|
@ -130,11 +130,6 @@
|
|||
<item name="android:textColor">?colorLinkImage</item>
|
||||
</style>
|
||||
|
||||
<style name="AboutDevNames" parent="Widget.AppCompat.TextView">
|
||||
<item name="android:textSize">15sp</item>
|
||||
<item name="android:textColor">?colorWelcomeHeaderSubtitle</item>
|
||||
</style>
|
||||
|
||||
<style name="WelcomeHeaderSubtitle" parent="Widget.AppCompat.TextView">
|
||||
<item name="android:layout_width">match_parent</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
|
|
Loading…
Reference in a new issue