Commit ccf21c2c authored by Henrique Nakashima's avatar Henrique Nakashima Committed by Commit Bot

Move SharedPref from CardEditor to ChromePreferenceKeys.

Register SharedPreferences keys in ChromePreferenceKeys and use
SharedPreferencesManager consistently instead of SharedPreferences
directly.

Bug: 1022108
Change-Id: I03887624498879df9ee8a01f68abf877e340f57c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2076519
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#749214}
parent 5e5683b6
...@@ -11,8 +11,8 @@ import android.util.Pair; ...@@ -11,8 +11,8 @@ import android.util.Pair;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.browser.autofill.settings.AutofillProfileBridge.DropdownKeyValue; import org.chromium.chrome.browser.autofill.settings.AutofillProfileBridge.DropdownKeyValue;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -193,7 +193,8 @@ public class EditorFieldModel { ...@@ -193,7 +193,8 @@ public class EditorFieldModel {
* Constructs a checkbox to show in the editor. It's checked by default. * Constructs a checkbox to show in the editor. It's checked by default.
* *
* @param checkboxLabel The label for the checkbox. * @param checkboxLabel The label for the checkbox.
* @param checkboxPreference The shared preference for the checkbox status. * @param checkboxPreference The shared preference key for the checkbox status. It must be in
* ChromePreferenceKeys.
*/ */
public static EditorFieldModel createCheckbox( public static EditorFieldModel createCheckbox(
CharSequence checkboxLabel, CharSequence checkboxPreference) { CharSequence checkboxLabel, CharSequence checkboxPreference) {
...@@ -388,16 +389,13 @@ public class EditorFieldModel { ...@@ -388,16 +389,13 @@ public class EditorFieldModel {
/** @return Whether the checkbox is checked. */ /** @return Whether the checkbox is checked. */
public boolean isChecked() { public boolean isChecked() {
assert mInputTypeHint == INPUT_TYPE_HINT_CHECKBOX; assert mInputTypeHint == INPUT_TYPE_HINT_CHECKBOX;
return ContextUtils.getAppSharedPreferences().getBoolean(mValue.toString(), true); return SharedPreferencesManager.getInstance().readBoolean(mValue.toString(), true);
} }
/** Sets the checkbox state. */ /** Sets the checkbox state. */
public void setIsChecked(boolean isChecked) { public void setIsChecked(boolean isChecked) {
assert mInputTypeHint == INPUT_TYPE_HINT_CHECKBOX; assert mInputTypeHint == INPUT_TYPE_HINT_CHECKBOX;
ContextUtils.getAppSharedPreferences() SharedPreferencesManager.getInstance().writeBoolean(mValue.toString(), isChecked);
.edit()
.putBoolean(mValue.toString(), isChecked)
.apply();
} }
/** @return The list of icons resource identifiers to display. */ /** @return The list of icons resource identifiers to display. */
......
...@@ -30,6 +30,7 @@ import org.chromium.chrome.browser.autofill.prefeditor.EditorFieldModel.EditorVa ...@@ -30,6 +30,7 @@ import org.chromium.chrome.browser.autofill.prefeditor.EditorFieldModel.EditorVa
import org.chromium.chrome.browser.autofill.prefeditor.EditorModel; import org.chromium.chrome.browser.autofill.prefeditor.EditorModel;
import org.chromium.chrome.browser.autofill.settings.AutofillProfileBridge.DropdownKeyValue; import org.chromium.chrome.browser.autofill.settings.AutofillProfileBridge.DropdownKeyValue;
import org.chromium.chrome.browser.payments.PaymentRequestImpl.PaymentRequestServiceObserverForTest; import org.chromium.chrome.browser.payments.PaymentRequestImpl.PaymentRequestServiceObserverForTest;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.components.payments.MethodStrings; import org.chromium.components.payments.MethodStrings;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.payments.mojom.PaymentMethodData; import org.chromium.payments.mojom.PaymentMethodData;
...@@ -92,9 +93,6 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument> ...@@ -92,9 +93,6 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument>
/** The dropdown key that triggers the address editor to add a new billing address. */ /** The dropdown key that triggers the address editor to add a new billing address. */
private static final String BILLING_ADDRESS_ADD_NEW = "add"; private static final String BILLING_ADDRESS_ADD_NEW = "add";
/** The shared preference for the 'save card to device' checkbox status. */
private static final String CHECK_SAVE_CARD_TO_DEVICE = "check_save_card_to_device";
/** The web contents where the web payments API is invoked. */ /** The web contents where the web payments API is invoked. */
private final WebContents mWebContents; private final WebContents mWebContents;
...@@ -765,7 +763,7 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument> ...@@ -765,7 +763,7 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument>
if (mSaveCardCheckbox == null) { if (mSaveCardCheckbox == null) {
mSaveCardCheckbox = EditorFieldModel.createCheckbox( mSaveCardCheckbox = EditorFieldModel.createCheckbox(
mContext.getString(R.string.payments_save_card_to_device_checkbox), mContext.getString(R.string.payments_save_card_to_device_checkbox),
CHECK_SAVE_CARD_TO_DEVICE); ChromePreferenceKeys.PAYMENTS_CHECK_SAVE_CARD_TO_DEVICE);
} }
editor.addField(mSaveCardCheckbox); editor.addField(mSaveCardCheckbox);
} }
......
...@@ -451,6 +451,9 @@ public final class ChromePreferenceKeys { ...@@ -451,6 +451,9 @@ public final class ChromePreferenceKeys {
*/ */
public static final String OFFLINE_INDICATOR_V2_ENABLED = "offline_indicator_v2_enabled"; public static final String OFFLINE_INDICATOR_V2_ENABLED = "offline_indicator_v2_enabled";
/** The shared preference for the 'save card to device' checkbox status. */
public static final String PAYMENTS_CHECK_SAVE_CARD_TO_DEVICE = "check_save_card_to_device";
/** Prefix of the preferences to persist use count of the payment instruments. */ /** Prefix of the preferences to persist use count of the payment instruments. */
public static final KeyPrefix PAYMENTS_PAYMENT_INSTRUMENT_USE_COUNT = public static final KeyPrefix PAYMENTS_PAYMENT_INSTRUMENT_USE_COUNT =
new KeyPrefix("payment_instrument_use_count_*"); new KeyPrefix("payment_instrument_use_count_*");
......
...@@ -125,6 +125,7 @@ public class GrandfatheredChromePreferenceKeys { ...@@ -125,6 +125,7 @@ public class GrandfatheredChromePreferenceKeys {
ChromePreferenceKeys.OFFLINE_AUTO_FETCH_SHOWING_IN_PROGRESS, ChromePreferenceKeys.OFFLINE_AUTO_FETCH_SHOWING_IN_PROGRESS,
ChromePreferenceKeys.OFFLINE_AUTO_FETCH_USER_CANCEL_ACTION_IN_PROGRESS, ChromePreferenceKeys.OFFLINE_AUTO_FETCH_USER_CANCEL_ACTION_IN_PROGRESS,
ChromePreferenceKeys.OFFLINE_INDICATOR_V2_ENABLED, ChromePreferenceKeys.OFFLINE_INDICATOR_V2_ENABLED,
ChromePreferenceKeys.PAYMENTS_CHECK_SAVE_CARD_TO_DEVICE,
ChromePreferenceKeys.PAYMENTS_PAYMENT_COMPLETE_ONCE, ChromePreferenceKeys.PAYMENTS_PAYMENT_COMPLETE_ONCE,
ChromePreferenceKeys.PREFETCH_HAS_NEW_PAGES, ChromePreferenceKeys.PREFETCH_HAS_NEW_PAGES,
ChromePreferenceKeys.PREFETCH_IGNORED_NOTIFICATION_COUNTER, ChromePreferenceKeys.PREFETCH_IGNORED_NOTIFICATION_COUNTER,
......
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