1
0
Fork 0

For #6396 For #6553 - Update sync engine checkboxes and send telemetry once

master
ekager 2020-01-16 15:10:51 -08:00 committed by Emily Kager
parent dbf711e112
commit 053e5b8065
2 changed files with 23 additions and 15 deletions

View File

@ -72,7 +72,8 @@ class SettingsFragment : PreferenceFragmentCompat() {
lifecycleScope.launch { lifecycleScope.launch {
updateAccountUIState( updateAccountUIState(
context = context, context = context,
profile = profile ?: context.components.backgroundServices.accountManager.accountProfile() profile = profile
?: context.components.backgroundServices.accountManager.accountProfile()
) )
} }
} }
@ -107,7 +108,11 @@ class SettingsFragment : PreferenceFragmentCompat() {
try { try {
context?.let { context -> context?.let { context ->
context.components.analytics.metrics.track( context.components.analytics.metrics.track(
Event.PreferenceToggled(key, sharedPreferences.getBoolean(key, false), context) Event.PreferenceToggled(
key,
sharedPreferences.getBoolean(key, false),
context
)
) )
} }
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
@ -185,7 +190,6 @@ class SettingsFragment : PreferenceFragmentCompat() {
findPreference<Preference>(getPreferenceKey(pref_key_passwords))?.apply { findPreference<Preference>(getPreferenceKey(pref_key_passwords))?.apply {
isVisible = FeatureFlags.logins isVisible = FeatureFlags.logins
} }
findPreference<PreferenceCategory>(getPreferenceKey(R.string.pref_key_advanced))?.apply { findPreference<PreferenceCategory>(getPreferenceKey(R.string.pref_key_advanced))?.apply {
isVisible = FeatureFlags.fenixLanguagePicker isVisible = FeatureFlags.fenixLanguagePicker
} }

View File

@ -166,12 +166,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
val historyNameKey = getPreferenceKey(R.string.pref_key_sync_history) val historyNameKey = getPreferenceKey(R.string.pref_key_sync_history)
findPreference<CheckBoxPreference>(historyNameKey)?.apply { findPreference<CheckBoxPreference>(historyNameKey)?.apply {
setOnPreferenceChangeListener { _, newValue -> setOnPreferenceChangeListener { _, newValue ->
requireComponents.analytics.metrics.track(Event.PreferenceToggled( SyncEnginesStorage(context).setStatus(SyncEngine.History, newValue as Boolean)
preferenceKey = historyNameKey,
enabled = newValue as Boolean,
context = context
))
SyncEnginesStorage(context).setStatus(SyncEngine.History, newValue)
@Suppress("DeferredResultUnused") @Suppress("DeferredResultUnused")
context.components.backgroundServices.accountManager.syncNowAsync(SyncReason.EngineChange) context.components.backgroundServices.accountManager.syncNowAsync(SyncReason.EngineChange)
true true
@ -181,12 +176,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
val bookmarksNameKey = getPreferenceKey(R.string.pref_key_sync_bookmarks) val bookmarksNameKey = getPreferenceKey(R.string.pref_key_sync_bookmarks)
findPreference<CheckBoxPreference>(bookmarksNameKey)?.apply { findPreference<CheckBoxPreference>(bookmarksNameKey)?.apply {
setOnPreferenceChangeListener { _, newValue -> setOnPreferenceChangeListener { _, newValue ->
requireComponents.analytics.metrics.track(Event.PreferenceToggled( SyncEnginesStorage(context).setStatus(SyncEngine.Bookmarks, newValue as Boolean)
preferenceKey = bookmarksNameKey,
enabled = newValue as Boolean,
context = context
))
SyncEnginesStorage(context).setStatus(SyncEngine.Bookmarks, newValue)
@Suppress("DeferredResultUnused") @Suppress("DeferredResultUnused")
context.components.backgroundServices.accountManager.syncNowAsync(SyncReason.EngineChange) context.components.backgroundServices.accountManager.syncNowAsync(SyncReason.EngineChange)
true true
@ -327,6 +317,17 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
} }
} }
private fun setEnginesDisabledWhileSyncing(isSyncing: Boolean) {
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 { private val syncStatusObserver = object : SyncStatusObserver {
override fun onStarted() { override fun onStarted() {
lifecycleScope.launch { lifecycleScope.launch {
@ -334,6 +335,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
view?.announceForAccessibility(getString(R.string.sync_syncing_in_progress)) view?.announceForAccessibility(getString(R.string.sync_syncing_in_progress))
pref?.title = getString(R.string.sync_syncing_in_progress) pref?.title = getString(R.string.sync_syncing_in_progress)
pref?.isEnabled = false pref?.isEnabled = false
setEnginesDisabledWhileSyncing(true)
} }
} }
@ -350,6 +352,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
} }
// Make sure out sync engine checkboxes are up-to-date. // Make sure out sync engine checkboxes are up-to-date.
updateSyncEngineStates() updateSyncEngineStates()
setEnginesDisabledWhileSyncing(false)
} }
} }
@ -359,6 +362,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
val pref = findPreference<Preference>(getPreferenceKey(R.string.pref_key_sync_now)) val pref = findPreference<Preference>(getPreferenceKey(R.string.pref_key_sync_now))
pref?.let { pref?.let {
pref.title = getString(R.string.preferences_sync_now) pref.title = getString(R.string.preferences_sync_now)
// We want to only enable the sync button, and not the checkboxes here
pref.isEnabled = true pref.isEnabled = true
val failedTime = getLastSynced(requireContext()) val failedTime = getLastSynced(requireContext())