-
Notifications
You must be signed in to change notification settings - Fork 1.3k
For #6396 For #6553 - Update sync engine checkboxes and send telemetry once #7777
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,12 +166,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 | ||
|
@@ -181,12 +176,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 | ||
|
@@ -327,13 +317,25 @@ class AccountSettingsFragment : PreferenceFragmentCompat() { | |
} | ||
} | ||
|
||
private fun setEnginesDisabledWhileSyncing(isSyncing: Boolean) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was weird behavior when you could interact with the toggles while syncing #6553 so I disabled them while syncing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds like a good solution to me |
||
listOf( | ||
R.string.pref_key_sync_bookmarks, | ||
R.string.pref_key_sync_history, | ||
R.string.pref_key_sync_logins | ||
) | ||
.map { getPreferenceKey(it) } | ||
.map { findPreference<CheckBoxPreference>(it) } | ||
.forEach { it?.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) | ||
} | ||
} | ||
|
||
|
@@ -350,6 +352,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() { | |
} | ||
// Make sure out sync engine checkboxes are up-to-date. | ||
updateSyncEngineStates() | ||
setEnginesDisabledWhileSyncing(false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like we're intentionally leaving the keys disabled in |
||
} | ||
} | ||
|
||
|
@@ -359,6 +362,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() { | |
val pref = findPreference<Preference>(getPreferenceKey(R.string.pref_key_sync_now)) | ||
pref?.let { | ||
pref.title = getString(R.string.preferences_sync_now) | ||
// We want to only enable the sync button, and not the checkboxes here | ||
pref.isEnabled = true | ||
|
||
val failedTime = getLastSynced(requireContext()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are already tracking these events in
SettingsFragment
so we were getting 2 pings here every time someone changed their setting (#6396).