Minor cleanup of the account settings

upstream-sync
Grisha Kruglov 3 years ago committed by Grisha Kruglov
parent e0b410efdf
commit e891139db9

@ -183,24 +183,22 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
).forEach { ).forEach {
requirePreference<CheckBoxPreference>(it.prefId()).apply { requirePreference<CheckBoxPreference>(it.prefId()).apply {
setOnPreferenceChangeListener { _, newValue -> setOnPreferenceChangeListener { _, newValue ->
updateSyncEngineState(context, it, newValue as Boolean) updateSyncEngineState(it, newValue as Boolean)
true true
} }
} }
} }
// 'Passwords' and 'Credit card' listeners are special, since we also display a pin protection warning. // 'Passwords' and 'Credit card' listeners are special, since we also display a pin protection warning.
requirePreference<CheckBoxPreference>(SyncEngine.Passwords.prefId()).apply { listOf(
setOnPreferenceChangeListener { _, newValue -> SyncEngine.Passwords,
updateSyncEngineStateWithPinWarning(SyncEngine.Passwords, newValue as Boolean) SyncEngine.CreditCards
true ).forEach {
} requirePreference<CheckBoxPreference>(it.prefId()).apply {
} setOnPreferenceChangeListener { _, newValue ->
updateSyncEngineStateWithPinWarning(it, newValue as Boolean)
requirePreference<CheckBoxPreference>(SyncEngine.CreditCards.prefId()).apply { true
setOnPreferenceChangeListener { _, newValue -> }
updateSyncEngineStateWithPinWarning(SyncEngine.CreditCards, newValue as Boolean)
true
} }
} }
@ -223,10 +221,10 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
* *
* Currently used for logins and credit cards. * Currently used for logins and credit cards.
* *
* @param engine the sync engine whose preference has changed. * @param syncEngine the sync engine whose preference has changed.
* @param newValue the value denoting whether or not to sync the specified preference. * @param newValue the value denoting whether or not to sync the specified preference.
*/ */
private fun CheckBoxPreference.updateSyncEngineStateWithPinWarning( private fun updateSyncEngineStateWithPinWarning(
syncEngine: SyncEngine, syncEngine: SyncEngine,
newValue: Boolean newValue: Boolean
) { ) {
@ -236,7 +234,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
!newValue || !newValue ||
!requireContext().settings().shouldShowSecurityPinWarningSync !requireContext().settings().shouldShowSecurityPinWarningSync
) { ) {
updateSyncEngineState(context, syncEngine, newValue) updateSyncEngineState(syncEngine, newValue)
} else { } else {
showPinDialogWarning(syncEngine, newValue) showPinDialogWarning(syncEngine, newValue)
} }
@ -250,10 +248,10 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
* @param newValue the new value of the sync preference, where true indicates sync for that * @param newValue the new value of the sync preference, where true indicates sync for that
* preference and false indicates not synced. * preference and false indicates not synced.
*/ */
private fun updateSyncEngineState(context: Context, engine: SyncEngine, newValue: Boolean) { private fun updateSyncEngineState(engine: SyncEngine, newValue: Boolean) {
SyncEnginesStorage(context).setStatus(engine, newValue) SyncEnginesStorage(requireContext()).setStatus(engine, newValue)
viewLifecycleOwner.lifecycleScope.launch { viewLifecycleOwner.lifecycleScope.launch {
context.components.backgroundServices.accountManager.syncNow(SyncReason.EngineChange) requireContext().components.backgroundServices.accountManager.syncNow(SyncReason.EngineChange)
} }
} }
@ -276,7 +274,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
) )
setNegativeButton(getString(R.string.logins_warning_dialog_later)) { _: DialogInterface, _ -> setNegativeButton(getString(R.string.logins_warning_dialog_later)) { _: DialogInterface, _ ->
updateSyncEngineState(context, syncEngine, newValue) updateSyncEngineState(syncEngine, newValue)
} }
setPositiveButton(getString(R.string.logins_warning_dialog_set_up_now)) { it: DialogInterface, _ -> setPositiveButton(getString(R.string.logins_warning_dialog_set_up_now)) { it: DialogInterface, _ ->

@ -30,8 +30,7 @@
android:title="@string/preferences_sync_bookmarks" /> android:title="@string/preferences_sync_bookmarks" />
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="false" android:defaultValue="true"
android:visible="false"
android:key="@string/pref_key_sync_credit_cards" android:key="@string/pref_key_sync_credit_cards"
android:layout="@layout/checkbox_left_preference" android:layout="@layout/checkbox_left_preference"
android:title="@string/preferences_sync_credit_cards" /> android:title="@string/preferences_sync_credit_cards" />
@ -49,13 +48,14 @@
android:title="@string/preferences_sync_logins" /> android:title="@string/preferences_sync_logins" />
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="false" android:defaultValue="true"
android:key="@string/pref_key_sync_tabs" android:key="@string/pref_key_sync_tabs"
android:layout="@layout/checkbox_left_preference" android:layout="@layout/checkbox_left_preference"
android:title="@string/preferences_sync_tabs_2"/> android:title="@string/preferences_sync_tabs_2"/>
<!-- The default visibility is 'false' because we don't display this on most channels. -->
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="false" android:defaultValue="true"
android:visible="false" android:visible="false"
android:key="@string/pref_key_sync_address" android:key="@string/pref_key_sync_address"
android:layout="@layout/checkbox_left_preference" android:layout="@layout/checkbox_left_preference"

Loading…
Cancel
Save