diff --git a/app/src/main/java/com/vanced/manager/adapter/SponsorAdapter.kt b/app/src/main/java/com/vanced/manager/adapter/SponsorAdapter.kt index ba6413ce..acb87edf 100644 --- a/app/src/main/java/com/vanced/manager/adapter/SponsorAdapter.kt +++ b/app/src/main/java/com/vanced/manager/adapter/SponsorAdapter.kt @@ -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, diff --git a/app/src/main/java/com/vanced/manager/adapter/WelcomePageAdapter.kt b/app/src/main/java/com/vanced/manager/adapter/WelcomePageAdapter.kt new file mode 100644 index 00000000..40c1cab1 --- /dev/null +++ b/app/src/main/java/com/vanced/manager/adapter/WelcomePageAdapter.kt @@ -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") + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/vanced/manager/ui/WelcomeActivity.kt b/app/src/main/java/com/vanced/manager/ui/WelcomeActivity.kt index f4a3c7dc..d823ba9e 100644 --- a/app/src/main/java/com/vanced/manager/ui/WelcomeActivity.kt +++ b/app/src/main/java/com/vanced/manager/ui/WelcomeActivity.kt @@ -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() + } + } + } \ No newline at end of file diff --git a/app/src/main/java/com/vanced/manager/ui/core/SlidingConstraintLayout.kt b/app/src/main/java/com/vanced/manager/ui/core/SlidingConstraintLayout.kt deleted file mode 100644 index 2010b8dd..00000000 --- a/app/src/main/java/com/vanced/manager/ui/core/SlidingConstraintLayout.kt +++ /dev/null @@ -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 - } -} diff --git a/app/src/main/java/com/vanced/manager/ui/core/SlidingLinearLayout.kt b/app/src/main/java/com/vanced/manager/ui/core/SlidingLinearLayout.kt deleted file mode 100644 index 208634cf..00000000 --- a/app/src/main/java/com/vanced/manager/ui/core/SlidingLinearLayout.kt +++ /dev/null @@ -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 - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/vanced/manager/ui/core/SlidingSwipeRefreshLayout.kt b/app/src/main/java/com/vanced/manager/ui/core/SlidingSwipeRefreshLayout.kt deleted file mode 100644 index 144591fe..00000000 --- a/app/src/main/java/com/vanced/manager/ui/core/SlidingSwipeRefreshLayout.kt +++ /dev/null @@ -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 - } -} \ No newline at end of file diff --git a/app/src/main/java/com/vanced/manager/ui/fragments/SelectAppsFragment.kt b/app/src/main/java/com/vanced/manager/ui/fragments/SelectAppsFragment.kt index 07fc19b7..799d804e 100644 --- a/app/src/main/java/com/vanced/manager/ui/fragments/SelectAppsFragment.kt +++ b/app/src/main/java/com/vanced/manager/ui/fragments/SelectAppsFragment.kt @@ -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() { @@ -52,6 +52,6 @@ class SelectAppsFragment : BindingFragment() { selectAdapter.apps.forEach { app -> prefs.edit { putBoolean("enable_${app.tag}", app.isChecked) } } - findNavController().navigate(SelectAppsFragmentDirections.selectAppsToGrantRoot()) + (requireActivity() as WelcomeActivity).navigateTo(2) } } \ No newline at end of file diff --git a/app/src/main/java/com/vanced/manager/ui/fragments/WelcomeFragment.kt b/app/src/main/java/com/vanced/manager/ui/fragments/WelcomeFragment.kt index 3cffe219..3b6f309b 100644 --- a/app/src/main/java/com/vanced/manager/ui/fragments/WelcomeFragment.kt +++ b/app/src/main/java/com/vanced/manager/ui/fragments/WelcomeFragment.kt @@ -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() { @@ -20,10 +20,8 @@ class WelcomeFragment : BindingFragment() { } private fun bindData() { - binding.welcomeGetStarted.setOnClickListener { navigateToWelcome() } - } - - private fun navigateToWelcome() { - findNavController().navigate(WelcomeFragmentDirections.welcomeToSelectApps()) + binding.welcomeGetStarted.setOnClickListener { + (requireActivity() as WelcomeActivity).navigateTo(1) + } } } \ No newline at end of file diff --git a/app/src/main/res/animator/fragment_enter_right.xml b/app/src/main/res/animator/fragment_enter_right.xml deleted file mode 100644 index 85e54d48..00000000 --- a/app/src/main/res/animator/fragment_enter_right.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/res/animator/fragment_exit_right.xml b/app/src/main/res/animator/fragment_exit_right.xml deleted file mode 100644 index 7e5bc218..00000000 --- a/app/src/main/res/animator/fragment_exit_right.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/res/animator/welcome_exit.xml b/app/src/main/res/animator/welcome_exit.xml deleted file mode 100644 index f81d59cf..00000000 --- a/app/src/main/res/animator/welcome_exit.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/animator/welcome_pop_enter.xml b/app/src/main/res/animator/welcome_pop_enter.xml deleted file mode 100644 index 1facda88..00000000 --- a/app/src/main/res/animator/welcome_pop_enter.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_info_black_24dp.xml b/app/src/main/res/drawable/ic_info_black_24dp.xml deleted file mode 100644 index 44ff6b4a..00000000 --- a/app/src/main/res/drawable/ic_info_black_24dp.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - diff --git a/app/src/main/res/layout/activity_welcome.xml b/app/src/main/res/layout/activity_welcome.xml index 91ee392c..c591147d 100644 --- a/app/src/main/res/layout/activity_welcome.xml +++ b/app/src/main/res/layout/activity_welcome.xml @@ -1,16 +1,6 @@ - - - - \ No newline at end of file + android:layout_height="match_parent" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_grant_root.xml b/app/src/main/res/layout/fragment_grant_root.xml index 3fd26bb2..88d201de 100644 --- a/app/src/main/res/layout/fragment_grant_root.xml +++ b/app/src/main/res/layout/fragment_grant_root.xml @@ -1,6 +1,7 @@ - @@ -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" /> + style="@style/WelcomeHeaderSubtitle" + tools:ignore="MissingConstraints" /> - \ No newline at end of file + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_select_apps.xml b/app/src/main/res/layout/fragment_select_apps.xml index a8d3211c..624835c1 100644 --- a/app/src/main/res/layout/fragment_select_apps.xml +++ b/app/src/main/res/layout/fragment_select_apps.xml @@ -1,5 +1,5 @@ - - + diff --git a/app/src/main/res/layout/fragment_welcome.xml b/app/src/main/res/layout/fragment_welcome.xml index 478e0e95..1ee2b2fd 100644 --- a/app/src/main/res/layout/fragment_welcome.xml +++ b/app/src/main/res/layout/fragment_welcome.xml @@ -1,5 +1,5 @@ - - + + diff --git a/app/src/main/res/navigation/welcome_navigation.xml b/app/src/main/res/navigation/welcome_navigation.xml deleted file mode 100644 index 775ab980..00000000 --- a/app/src/main/res/navigation/welcome_navigation.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index ebb0e226..a781c629 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,7 +1,6 @@ - 12dp 16dp 128dp diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index f67eda09..89ee5444 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -130,11 +130,6 @@ ?colorLinkImage - -