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

Commit

Permalink
For #6396 For #6737 For #6553 - Update sync engine checkboxes and sen…
Browse files Browse the repository at this point in the history
…d telemetry once, removes feature flags for logins
  • Loading branch information
ekager committed Jan 16, 2020
1 parent 9998a3d commit 2e452cd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
5 changes: 0 additions & 5 deletions app/src/main/java/org/mozilla/fenix/FeatureFlags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -166,12 +165,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
val historyNameKey = getPreferenceKey(R.string.pref_key_sync_history)
findPreference<CheckBoxPreference>(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
Expand All @@ -181,12 +175,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
val bookmarksNameKey = getPreferenceKey(R.string.pref_key_sync_bookmarks)
findPreference<CheckBoxPreference>(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
Expand Down Expand Up @@ -266,9 +255,8 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
}
val loginsNameKey = getPreferenceKey(R.string.pref_key_sync_logins)
findPreference<CheckBoxPreference>(loginsNameKey)?.apply {
isVisible = FeatureFlags.logins
isEnabled = syncEnginesStatus.containsKey(SyncEngine.Passwords)
isChecked = syncEnginesStatus.getOrElse(SyncEngine.Passwords) { false }
isChecked = syncEnginesStatus.getOrElse(SyncEngine.Passwords) { true }
}
}

Expand Down Expand Up @@ -327,13 +315,29 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
}
}

private fun setEnginesDisabledWhileSyncing(isSyncing: Boolean) {
val bookmarksNameKey = getPreferenceKey(R.string.pref_key_sync_bookmarks)
findPreference<CheckBoxPreference>(bookmarksNameKey)?.apply {
isEnabled = !isSyncing
}
val historyNameKey = getPreferenceKey(R.string.pref_key_sync_history)
findPreference<CheckBoxPreference>(historyNameKey)?.apply {
isEnabled = !isSyncing
}
val loginsNameKey = getPreferenceKey(R.string.pref_key_sync_logins)
findPreference<CheckBoxPreference>(loginsNameKey)?.apply {
isEnabled = !isSyncing
}
}

private val syncStatusObserver = object : SyncStatusObserver {
override fun onStarted() {
lifecycleScope.launch {
val pref = findPreference<Preference>(getPreferenceKey(R.string.pref_key_sync_now))
view?.announceForAccessibility(getString(R.string.sync_syncing_in_progress))
pref?.title = getString(R.string.sync_syncing_in_progress)
pref?.isEnabled = false
setEnginesDisabledWhileSyncing(true)
}
}

Expand All @@ -350,6 +354,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
}
// Make sure out sync engine checkboxes are up-to-date.
updateSyncEngineStates()
setEnginesDisabledWhileSyncing(false)
}
}

Expand Down
8 changes: 3 additions & 5 deletions app/src/main/res/xml/account_settings_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
<!-- 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/. -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<androidx.preference.Preference
android:key="@string/pref_key_sync_now"
android:title="@string/preferences_sync_now" />
Expand All @@ -27,10 +26,9 @@
android:title="@string/preferences_sync_history" />

<androidx.preference.CheckBoxPreference
android:defaultValue="false"
android:defaultValue="true"
android:key="@string/pref_key_sync_logins"
android:title="@string/preferences_sync_logins"
app:isPreferenceVisible="false" />
android:title="@string/preferences_sync_logins" />

<androidx.preference.EditTextPreference
android:key="@string/pref_key_sync_device_name"
Expand Down

0 comments on commit 2e452cd

Please sign in to comment.