From b4e1360f59afda5115e76306dec883b8fea8dc46 Mon Sep 17 00:00:00 2001 From: Sawyer Blatz Date: Tue, 17 Mar 2020 12:35:00 -0700 Subject: [PATCH] For #3086: Adds settings animations (#9187) --- .../fenix/settings/SettingsFragment.kt | 27 ++++++- app/src/main/res/anim/slide_in_left.xml | 11 +++ app/src/main/res/anim/slide_in_right.xml | 11 +++ app/src/main/res/anim/slide_out_left.xml | 11 +++ app/src/main/res/anim/slide_out_right.xml | 11 +++ app/src/main/res/navigation/nav_graph.xml | 73 ++++++++++++++++++- app/src/main/res/xml/preferences.xml | 3 +- buildSrc/src/main/java/AndroidComponents.kt | 1 - 8 files changed, 144 insertions(+), 4 deletions(-) create mode 100644 app/src/main/res/anim/slide_in_left.xml create mode 100644 app/src/main/res/anim/slide_in_right.xml create mode 100644 app/src/main/res/anim/slide_out_left.xml create mode 100644 app/src/main/res/anim/slide_out_right.xml diff --git a/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt index b50314cf2..f7e529aa1 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt @@ -18,8 +18,11 @@ import androidx.preference.Preference import androidx.preference.Preference.OnPreferenceClickListener import androidx.preference.PreferenceCategory import androidx.preference.PreferenceFragmentCompat +import androidx.recyclerview.widget.RecyclerView +import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main +import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import mozilla.components.concept.sync.AccountObserver @@ -43,7 +46,7 @@ import org.mozilla.fenix.ext.showToolbar import org.mozilla.fenix.settings.account.AccountAuthErrorPreference import org.mozilla.fenix.settings.account.AccountPreference -@Suppress("LargeClass") +@Suppress("LargeClass", "TooManyFunctions") class SettingsFragment : PreferenceFragmentCompat() { private val accountObserver = object : AccountObserver { @@ -114,6 +117,8 @@ class SettingsFragment : PreferenceFragmentCompat() { showToolbar(getString(R.string.settings_title)) update() + + view!!.findViewById(R.id.recycler_view)?.hideInitialScrollBar(lifecycleScope) } private fun update() { @@ -165,6 +170,10 @@ class SettingsFragment : PreferenceFragmentCompat() { @Suppress("ComplexMethod", "LongMethod") override fun onPreferenceTreeClick(preference: Preference): Boolean { + // Hide the scrollbar so the animation looks smoother + val recyclerView = view!!.findViewById(R.id.recycler_view) + recyclerView.isVerticalScrollBarEnabled = false + val directions: NavDirections? = when (preference.key) { resources.getString(R.string.pref_key_search_settings) -> { SettingsFragmentDirections.actionSettingsFragmentToSearchEngineFragment() @@ -301,6 +310,18 @@ class SettingsFragment : PreferenceFragmentCompat() { } } + // Extension function for hiding the scroll bar on initial loading. We must do this so the + // animation to the next screen doesn't animate the initial scroll bar (it ignores + // isVerticalScrollBarEnabled being set to false). + private fun RecyclerView.hideInitialScrollBar(scope: CoroutineScope) { + scope.launch { + val originalSize = scrollBarSize + scrollBarSize = 0 + delay(SCROLL_INDICATOR_DELAY) + scrollBarSize = originalSize + } + } + /** * Updates the UI to reflect current account state. * Possible conditions are logged-in without problems, logged-out, and logged-in but needs to re-authenticate. @@ -366,4 +387,8 @@ class SettingsFragment : PreferenceFragmentCompat() { accountPreferenceCategory?.isVisible = false } } + + companion object { + private const val SCROLL_INDICATOR_DELAY = 10L + } } diff --git a/app/src/main/res/anim/slide_in_left.xml b/app/src/main/res/anim/slide_in_left.xml new file mode 100644 index 000000000..85c5fe8c4 --- /dev/null +++ b/app/src/main/res/anim/slide_in_left.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/app/src/main/res/anim/slide_in_right.xml b/app/src/main/res/anim/slide_in_right.xml new file mode 100644 index 000000000..b6d875e57 --- /dev/null +++ b/app/src/main/res/anim/slide_in_right.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/app/src/main/res/anim/slide_out_left.xml b/app/src/main/res/anim/slide_out_left.xml new file mode 100644 index 000000000..551342459 --- /dev/null +++ b/app/src/main/res/anim/slide_out_left.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/app/src/main/res/anim/slide_out_right.xml b/app/src/main/res/anim/slide_out_right.xml new file mode 100644 index 000000000..240992691 --- /dev/null +++ b/app/src/main/res/anim/slide_out_right.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index 6e96515a0..5204decfa 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -62,7 +62,6 @@ -