Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

For #3086: Adds settings animations #9187

Merged
merged 1 commit into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -114,6 +117,8 @@ class SettingsFragment : PreferenceFragmentCompat() {
showToolbar(getString(R.string.settings_title))

update()

view!!.findViewById<RecyclerView>(R.id.recycler_view)?.hideInitialScrollBar(lifecycleScope)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use the kotlin view getter here? view?.recycler_view?.hideInitialScrollbar(lifecycleScope)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, no. I tried this, and it doesn't work. My guess is that it's because we don't have direct access to the recycler view. This is actually one Android is generating based on the build in PreferenceFragment.

}

private fun update() {
Expand Down Expand Up @@ -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<RecyclerView>(R.id.recycler_view)
recyclerView.isVerticalScrollBarEnabled = false

val directions: NavDirections? = when (preference.key) {
resources.getString(R.string.pref_key_search_settings) -> {
SettingsFragmentDirections.actionSettingsFragmentToSearchEngineFragment()
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -366,4 +387,8 @@ class SettingsFragment : PreferenceFragmentCompat() {
accountPreferenceCategory?.isVisible = false
}
}

companion object {
private const val SCROLL_INDICATOR_DELAY = 10L
}
}
11 changes: 11 additions & 0 deletions app/src/main/res/anim/slide_in_left.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="-50%" android:toXDelta="0%"
android:interpolator="@android:interpolator/decelerate_quad"
android:duration="275"/>
<alpha android:fromAlpha="0" android:toAlpha="1.0"
android:duration="275" />
</set>
11 changes: 11 additions & 0 deletions app/src/main/res/anim/slide_in_right.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="50%" android:toXDelta="0%"
android:interpolator="@android:interpolator/decelerate_quad"
android:duration="275"/>
<alpha android:fromAlpha="0" android:toAlpha="1.0"
android:duration="275" />
</set>
11 changes: 11 additions & 0 deletions app/src/main/res/anim/slide_out_left.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0%" android:toXDelta="-50%"
android:interpolator="@android:interpolator/decelerate_quad"
android:duration="275"/>
<alpha android:fromAlpha="1.0" android:toAlpha="0"
android:duration="275" />
</set>
11 changes: 11 additions & 0 deletions app/src/main/res/anim/slide_out_right.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0%" android:toXDelta="50%"
android:interpolator="@android:interpolator/decelerate_quad"
android:duration="275"/>
<alpha android:fromAlpha="1.0" android:toAlpha="0"
android:duration="275" />
</set>
73 changes: 72 additions & 1 deletion app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
<fragment
android:id="@+id/homeFragment"
android:name="org.mozilla.fenix.home.HomeFragment"
app:enterAnim="@anim/zoom_out_fade"
tools:layout="@layout/fragment_home">
<action
android:id="@+id/action_homeFragment_to_turnOnSyncFragment"
Expand Down Expand Up @@ -91,6 +90,10 @@
app:destination="@id/historyFragment" />
<action
android:id="@+id/action_homeFragment_to_settingsFragment"
app:enterAnim="@anim/fade_in_up"
app:exitAnim="@anim/fade_out"
app:popExitAnim="@anim/fade_out_down"
app:popEnterAnim="@anim/fade_in"
app:destination="@id/settingsFragment" />
<action
android:id="@+id/action_homeFragment_to_createCollectionFragment"
Expand Down Expand Up @@ -385,55 +388,123 @@
app:popUpTo="@+id/settingsFragment" />
<action
android:id="@+id/action_settingsFragment_to_dataChoicesFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/dataChoicesFragment"
app:popUpTo="@+id/settingsFragment" />
<action
android:id="@+id/action_settingsFragment_to_sitePermissionsFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/sitePermissionsFragment" />
<action
android:id="@+id/action_settingsFragment_to_loginsFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/loginsFragment" />
<action
android:id="@+id/action_settingsFragment_to_accessibilityFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/accessibilityFragment" />
<action
android:id="@+id/action_settingsFragment_to_accountSettingsFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/accountSettingsFragment" />
<action
android:id="@+id/action_settingsFragment_to_searchEngineFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/searchEngineFragment" />
<action
android:id="@+id/action_settingsFragment_to_turnOnSyncFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/turnOnSyncFragment" />
<action
android:id="@+id/action_settingsFragment_to_aboutFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/aboutFragment" />
<action
android:id="@+id/action_settingsFragment_to_customizationFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/customizationFragment" />
<action
android:id="@+id/action_settingsFragment_to_privateBrowsingFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/privateBrowsingFragment" />
<action
android:id="@+id/action_settingsFragment_to_trackingProtectionFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/trackingProtectionFragment" />
<action
android:id="@+id/action_settingsFragment_to_deleteBrowsingDataFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/deleteBrowsingDataFragment" />
<action
android:id="@+id/action_settingsFragment_to_accountProblemFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/accountProblemFragment" />
<action
android:id="@+id/action_settingsFragment_to_deleteBrowsingDataOnQuitFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/deleteBrowsingDataOnQuitFragment" />
<action
android:id="@+id/action_settingsFragment_to_defaultBrowserSettingsFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/defaultBrowserSettingsFragment" />
<action
android:id="@+id/action_settingsFragment_to_localeSettingsFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/localeSettingsFragment" />
<action
android:id="@+id/action_settingsFragment_to_addonsFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/addonsManagementFragment" />
</fragment>
<fragment
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.preference.PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<androidx.preference.Preference
Expand Down
1 change: 0 additions & 1 deletion buildSrc/src/main/java/AndroidComponents.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
object AndroidComponents {
const val VERSION = "37.0.20200317130045"
}