parent
c7d3f00a9e
commit
23edd2559d
|
@ -59,6 +59,7 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
job = Job()
|
||||
updateSignInVisibility()
|
||||
}
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
|
@ -161,9 +162,6 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse
|
|||
// Observe account changes to keep the UI up-to-date.
|
||||
accountManager.register(this, owner = this)
|
||||
|
||||
// TODO an authenticated state will mark 'preferenceSignIn' as invisible; currently that behaviour is non-ideal:
|
||||
// a "sign in" UI will be displayed at first, and then quickly animate away.
|
||||
// Ideally we don't want it to be displayed at all.
|
||||
updateAuthState(accountManager.authenticatedAccount())
|
||||
accountManager.accountProfile()?.let { updateAccountProfile(it) }
|
||||
}
|
||||
|
@ -293,6 +291,7 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse
|
|||
|
||||
override fun onLoggedOut() {
|
||||
updateAuthState()
|
||||
updateSignInVisibility()
|
||||
}
|
||||
|
||||
override fun onProfileUpdated(profile: Profile) {
|
||||
|
@ -301,6 +300,12 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse
|
|||
|
||||
// --- Account UI helpers ---
|
||||
private fun updateAuthState(account: OAuthAccount? = null) {
|
||||
// Cache the user's auth state to improve performance of sign in visibility
|
||||
org.mozilla.fenix.utils.Settings.getInstance(context!!).setHasCachedAccount(account != null)
|
||||
}
|
||||
|
||||
private fun updateSignInVisibility() {
|
||||
val hasCachedAccount = org.mozilla.fenix.utils.Settings.getInstance(context!!).hasCachedAccount
|
||||
val preferenceSignIn =
|
||||
findPreference<Preference>(context!!.getPreferenceKey(pref_key_sign_in))
|
||||
val preferenceFirefoxAccount =
|
||||
|
@ -308,7 +313,7 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse
|
|||
val accountPreferenceCategory =
|
||||
findPreference<PreferenceCategory>(context!!.getPreferenceKey(pref_key_account_category))
|
||||
|
||||
if (account != null) {
|
||||
if (hasCachedAccount) {
|
||||
preferenceSignIn?.isVisible = false
|
||||
preferenceSignIn?.onPreferenceClickListener = null
|
||||
preferenceFirefoxAccount?.isVisible = true
|
||||
|
|
|
@ -100,6 +100,9 @@ class Settings private constructor(context: Context) {
|
|||
else -> appContext.getString(R.string.preference_light_theme)
|
||||
}
|
||||
|
||||
val hasCachedAccount: Boolean
|
||||
get() = preferences.getBoolean(appContext.getPreferenceKey(R.string.pref_key_cached_account), false)
|
||||
|
||||
private val autoBounceQuickActionSheetCount: Int
|
||||
get() = (preferences.getInt(appContext.getPreferenceKey(R.string.pref_key_bounce_quick_action), 0))
|
||||
|
||||
|
@ -172,6 +175,12 @@ class Settings private constructor(context: Context) {
|
|||
)
|
||||
}
|
||||
|
||||
fun setHasCachedAccount(isCached: Boolean) {
|
||||
preferences.edit()
|
||||
.putBoolean(appContext.getPreferenceKey(R.string.pref_key_cached_account), isCached)
|
||||
.apply()
|
||||
}
|
||||
|
||||
private val SitePermissionsRules.Action.id: Int
|
||||
get() {
|
||||
return when (this) {
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
<string name="pref_key_sync_now" translatable="false">pref_key_sync_now</string>
|
||||
<string name="pref_key_sync_history" translatable="false">pref_key_sync_history</string>
|
||||
<string name="pref_key_sign_out" translatable="false">pref_key_sign_out</string>
|
||||
<string name="pref_key_cached_account" translatable="false">pref_key_cached_account</string>
|
||||
|
||||
<!-- Search Settings -->
|
||||
<string name="pref_key_show_search_suggestions" translatable="false">pref_key_show_search_suggestions</string>
|
||||
|
|
Loading…
Reference in New Issue