From d30d91af2490a5865e4087e707db89920de987ba Mon Sep 17 00:00:00 2001 From: ekager Date: Thu, 16 Jan 2020 15:10:51 -0800 Subject: [PATCH] For #6396 For #6737 For #6553 - Update sync engine checkboxes and send telemetry once, removes feature flags for logins --- .../java/org/mozilla/fenix/FeatureFlags.kt | 5 --- .../fenix/settings/SettingsFragment.kt | 8 ----- .../account/AccountSettingsFragment.kt | 35 +++++++++++-------- .../res/xml/account_settings_preferences.xml | 8 ++--- app/src/main/res/xml/preferences.xml | 1 - 5 files changed, 23 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt index 5134a58b6100..672fcecc3a16 100644 --- a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt +++ b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt @@ -34,11 +34,6 @@ object FeatureFlags { */ val progressiveWebApps = Config.channel.isNightlyOrDebug - /** - * Gives option in Settings to see logins and sync logins - */ - val logins = Config.channel.isNightlyOrDebug - /** * Disables FxA Application Services Web Channels feature */ 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 50359f907703..d16c78e34976 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt @@ -24,7 +24,6 @@ import mozilla.components.concept.sync.OAuthAccount import mozilla.components.concept.sync.Profile import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.Config -import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.R import org.mozilla.fenix.R.string.pref_key_about @@ -120,7 +119,6 @@ class SettingsFragment : PreferenceFragmentCompat() { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.preferences, rootKey) - updatePreferenceVisibilityForFeatureFlags() } override fun onResume() { @@ -181,12 +179,6 @@ class SettingsFragment : PreferenceFragmentCompat() { ) } - private fun updatePreferenceVisibilityForFeatureFlags() { - findPreference(getPreferenceKey(pref_key_passwords))?.apply { - isVisible = FeatureFlags.logins - } - } - @Suppress("ComplexMethod", "LongMethod") override fun onPreferenceTreeClick(preference: Preference): Boolean { val directions: NavDirections? = when (preference.key) { diff --git a/app/src/main/java/org/mozilla/fenix/settings/account/AccountSettingsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/account/AccountSettingsFragment.kt index 0de6b84c2c60..fd903a9f2108 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/account/AccountSettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/account/AccountSettingsFragment.kt @@ -33,7 +33,6 @@ import mozilla.components.service.fxa.manager.SyncEnginesStorage import mozilla.components.service.fxa.sync.SyncReason import mozilla.components.service.fxa.sync.SyncStatusObserver import mozilla.components.service.fxa.sync.getLastSynced -import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.R import org.mozilla.fenix.components.FenixSnackbar import org.mozilla.fenix.components.StoreProvider @@ -166,12 +165,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() { val historyNameKey = getPreferenceKey(R.string.pref_key_sync_history) findPreference(historyNameKey)?.apply { setOnPreferenceChangeListener { _, newValue -> - requireComponents.analytics.metrics.track(Event.PreferenceToggled( - preferenceKey = historyNameKey, - enabled = newValue as Boolean, - context = context - )) - SyncEnginesStorage(context).setStatus(SyncEngine.History, newValue) + SyncEnginesStorage(context).setStatus(SyncEngine.History, newValue as Boolean) @Suppress("DeferredResultUnused") context.components.backgroundServices.accountManager.syncNowAsync(SyncReason.EngineChange) true @@ -181,12 +175,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() { val bookmarksNameKey = getPreferenceKey(R.string.pref_key_sync_bookmarks) findPreference(bookmarksNameKey)?.apply { setOnPreferenceChangeListener { _, newValue -> - requireComponents.analytics.metrics.track(Event.PreferenceToggled( - preferenceKey = bookmarksNameKey, - enabled = newValue as Boolean, - context = context - )) - SyncEnginesStorage(context).setStatus(SyncEngine.Bookmarks, newValue) + SyncEnginesStorage(context).setStatus(SyncEngine.Bookmarks, newValue as Boolean) @Suppress("DeferredResultUnused") context.components.backgroundServices.accountManager.syncNowAsync(SyncReason.EngineChange) true @@ -266,9 +255,8 @@ class AccountSettingsFragment : PreferenceFragmentCompat() { } val loginsNameKey = getPreferenceKey(R.string.pref_key_sync_logins) findPreference(loginsNameKey)?.apply { - isVisible = FeatureFlags.logins isEnabled = syncEnginesStatus.containsKey(SyncEngine.Passwords) - isChecked = syncEnginesStatus.getOrElse(SyncEngine.Passwords) { false } + isChecked = syncEnginesStatus.getOrElse(SyncEngine.Passwords) { true } } } @@ -327,6 +315,21 @@ class AccountSettingsFragment : PreferenceFragmentCompat() { } } + private fun setEnginesDisabledWhileSyncing(isSyncing: Boolean) { + val bookmarksNameKey = getPreferenceKey(R.string.pref_key_sync_bookmarks) + findPreference(bookmarksNameKey)?.apply { + isEnabled = !isSyncing + } + val historyNameKey = getPreferenceKey(R.string.pref_key_sync_history) + findPreference(historyNameKey)?.apply { + isEnabled = !isSyncing + } + val loginsNameKey = getPreferenceKey(R.string.pref_key_sync_logins) + findPreference(loginsNameKey)?.apply { + isEnabled = !isSyncing + } + } + private val syncStatusObserver = object : SyncStatusObserver { override fun onStarted() { lifecycleScope.launch { @@ -334,6 +337,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() { view?.announceForAccessibility(getString(R.string.sync_syncing_in_progress)) pref?.title = getString(R.string.sync_syncing_in_progress) pref?.isEnabled = false + setEnginesDisabledWhileSyncing(true) } } @@ -350,6 +354,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() { } // Make sure out sync engine checkboxes are up-to-date. updateSyncEngineStates() + setEnginesDisabledWhileSyncing(false) } } diff --git a/app/src/main/res/xml/account_settings_preferences.xml b/app/src/main/res/xml/account_settings_preferences.xml index 104b4c7e0be2..e48a82c33bd9 100644 --- a/app/src/main/res/xml/account_settings_preferences.xml +++ b/app/src/main/res/xml/account_settings_preferences.xml @@ -2,8 +2,7 @@ - + @@ -27,10 +26,9 @@ android:title="@string/preferences_sync_history" /> + android:title="@string/preferences_sync_logins" />