Commit 7c665abd authored by estade's avatar estade Committed by Commit bot

Refresh the autofill wallet switch summary as needed.

(in the top level Autofill Preferences page)

BUG=461006

Review URL: https://codereview.chromium.org/952613003

Cr-Commit-Position: refs/heads/master@{#318828}
parent 77367c10
...@@ -37,6 +37,8 @@ public class AutofillPreferences extends PreferenceFragment ...@@ -37,6 +37,8 @@ public class AutofillPreferences extends PreferenceFragment
private static final String PREF_AUTOFILL_CREDIT_CARDS = "autofill_credit_cards"; private static final String PREF_AUTOFILL_CREDIT_CARDS = "autofill_credit_cards";
private static final String PREF_AUTOFILL_WALLET = "autofill_wallet"; private static final String PREF_AUTOFILL_WALLET = "autofill_wallet";
ChromeBasePreference mWalletPref;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -57,23 +59,13 @@ public class AutofillPreferences extends PreferenceFragment ...@@ -57,23 +59,13 @@ public class AutofillPreferences extends PreferenceFragment
} }
}); });
ChromeBasePreference walletPref = mWalletPref = (ChromeBasePreference) findPreference(PREF_AUTOFILL_WALLET);
(ChromeBasePreference) findPreference(PREF_AUTOFILL_WALLET);
if (!PersonalDataManager.isWalletImportFeatureAvailable()) {
getPreferenceScreen().removePreference(walletPref);
autofillSwitch.setDrawDivider(true);
} else {
walletPref.setSummary(getResources().getString(
PersonalDataManager.isWalletImportEnabled() ? R.string.text_on
: R.string.text_off));
}
setPreferenceCategoryIcons(); setPreferenceCategoryIcons();
} }
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
rebuildLists(); refreshState();
return true; return true;
} }
...@@ -92,9 +84,10 @@ public class AutofillPreferences extends PreferenceFragment ...@@ -92,9 +84,10 @@ public class AutofillPreferences extends PreferenceFragment
} }
/** /**
* Rebuild all the profile and credit card lists. * Refresh state (profile and credit card lists, preference summaries, etc.).
*/ */
private void rebuildLists() { private void refreshState() {
updateSummaries();
rebuildProfileList(); rebuildProfileList();
rebuildCreditCardList(); rebuildCreditCardList();
} }
...@@ -140,6 +133,24 @@ public class AutofillPreferences extends PreferenceFragment ...@@ -140,6 +133,24 @@ public class AutofillPreferences extends PreferenceFragment
} }
} }
private void updateSummaries() {
ChromeSwitchPreference autofillSwitch =
(ChromeSwitchPreference) findPreference(PREF_AUTOFILL_SWITCH);
if (!PersonalDataManager.isWalletImportFeatureAvailable()) {
getPreferenceScreen().removePreference(mWalletPref);
autofillSwitch.setDrawDivider(true);
} else {
if (getPreferenceScreen().findPreference(PREF_AUTOFILL_WALLET) == null) {
getPreferenceScreen().addPreference(mWalletPref);
}
mWalletPref.setSummary(getResources().getString(
PersonalDataManager.isWalletImportEnabled() ? R.string.text_on
: R.string.text_off));
autofillSwitch.setDrawDivider(false);
}
}
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
...@@ -147,12 +158,12 @@ public class AutofillPreferences extends PreferenceFragment ...@@ -147,12 +158,12 @@ public class AutofillPreferences extends PreferenceFragment
// detect if profiles are added or deleted (GUID list // detect if profiles are added or deleted (GUID list
// changes), the profile summary (name+addr) might be // changes), the profile summary (name+addr) might be
// different. To be safe, we update all. // different. To be safe, we update all.
rebuildLists(); refreshState();
} }
@Override @Override
public void onPersonalDataChanged() { public void onPersonalDataChanged() {
rebuildLists(); refreshState();
} }
@Override @Override
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment