Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/AutofillCreditCardEditor.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/AutofillCreditCardEditor.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/AutofillCreditCardEditor.java |
| index ae2e59d3554dfca85117df4952e881a964d4c361..9fb215e860c11031039ebfd43289ca5015f61582 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/AutofillCreditCardEditor.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/AutofillCreditCardEditor.java |
| @@ -16,8 +16,10 @@ import android.widget.ArrayAdapter; |
| import android.widget.Button; |
| import android.widget.EditText; |
| import android.widget.Spinner; |
| +import android.widget.TextView; |
| import org.chromium.chrome.R; |
| +import org.chromium.chrome.browser.EmbedContentViewActivity; |
| import org.chromium.chrome.browser.autofill.PersonalDataManager; |
| import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; |
| import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; |
| @@ -32,10 +34,17 @@ import java.util.Locale; |
| * Provides the Java-ui for editing a Credit Card autofill entry. |
| */ |
| public class AutofillCreditCardEditor extends AutofillEditorBase { |
| + private TextView mServerCardLabel; |
| + private TextView mServerCardSublabel; |
| + private View mServerCardEditLinkContainer; |
| + private View mServerCardEditLink; |
| + private View mServerCardClearButton; |
| private FloatLabelLayout mNameLabel; |
| private EditText mNameText; |
| private FloatLabelLayout mNumberLabel; |
| private EditText mNumberText; |
| + private View mExpirationLabel; |
| + private View mExpirationContainer; |
| private Spinner mExpirationMonth; |
| private Spinner mExpirationYear; |
| private Spinner mBillingAddress; |
| @@ -43,16 +52,25 @@ public class AutofillCreditCardEditor extends AutofillEditorBase { |
| private int mInitialExpirationMonthPos; |
| private int mInitialExpirationYearPos; |
| private int mInitialBillingAddressPos; |
| + private boolean mIsLocalCard; |
| @Override |
| public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| Bundle savedInstanceState) { |
| View v = super.onCreateView(inflater, container, savedInstanceState); |
| + mServerCardLabel = (TextView) v.findViewById(R.id.server_card_label); |
| + mServerCardSublabel = (TextView) v.findViewById(R.id.server_card_sublabel); |
| + mServerCardEditLinkContainer = v.findViewById(R.id.server_card_edit_link_container); |
| + mServerCardEditLink = v.findViewById(R.id.server_card_edit_link); |
| + mServerCardClearButton = v.findViewById(R.id.server_card_clear_button); |
| + |
| mNameLabel = (FloatLabelLayout) v.findViewById(R.id.credit_card_name_label); |
| mNameText = (EditText) v.findViewById(R.id.credit_card_name_edit); |
| mNumberLabel = (FloatLabelLayout) v.findViewById(R.id.credit_card_number_label); |
| mNumberText = (EditText) v.findViewById(R.id.credit_card_number_edit); |
| + mExpirationLabel = v.findViewById(R.id.credit_card_expiration_label); |
| + mExpirationContainer = v.findViewById(R.id.credit_card_expiration_container); |
| // Set text watcher to format credit card number |
| mNumberText.addTextChangedListener(new CreditCardNumberFormattingTextWatcher()); |
| @@ -147,45 +165,59 @@ public class AutofillCreditCardEditor extends AutofillEditorBase { |
| private void addCardDataToEditFields() { |
| CreditCard card = PersonalDataManager.getInstance().getCreditCard(mGUID); |
| if (card == null) { |
| + hideServerCardElements(); |
| mNameLabel.focusWithoutAnimation(); |
| return; |
| } |
| - if (!TextUtils.isEmpty(card.getName())) { |
| - mNameLabel.setText(card.getName()); |
| - } |
| - if (!TextUtils.isEmpty(card.getNumber())) { |
| - mNumberLabel.setText(card.getNumber()); |
| - } |
| + mIsLocalCard = card.getIsLocal(); |
|
gone
2016/06/29 20:09:42
As mentioned in chat, I think it'd make more sense
please use gerrit instead
2016/06/30 01:19:27
Separated the classes.
|
| + if (mIsLocalCard) { |
| + hideServerCardElements(); |
| - // Make the name label focusable in touch mode so that mNameText doesn't get focused. |
| - mNameLabel.getLabel().setFocusableInTouchMode(true); |
| + if (!TextUtils.isEmpty(card.getName())) { |
| + mNameLabel.setText(card.getName()); |
| + } |
| + if (!TextUtils.isEmpty(card.getNumber())) { |
| + mNumberLabel.setText(card.getNumber()); |
| + } |
| - int monthAsInt = 1; |
| - if (!card.getMonth().isEmpty()) { |
| - monthAsInt = Integer.parseInt(card.getMonth()); |
| - } |
| - mExpirationMonth.setSelection(monthAsInt - 1); |
| - |
| - mInitialExpirationYearPos = 0; |
| - boolean foundYear = false; |
| - for (int i = 0; i < mExpirationYear.getAdapter().getCount(); i++) { |
| - if (card.getYear().equals(mExpirationYear.getAdapter().getItem(i))) { |
| - mInitialExpirationYearPos = i; |
| - foundYear = true; |
| - break; |
| + // Make the name label focusable in touch mode so that mNameText doesn't get focused. |
| + mNameLabel.getLabel().setFocusableInTouchMode(true); |
| + |
| + int monthAsInt = 1; |
| + if (!card.getMonth().isEmpty()) { |
| + monthAsInt = Integer.parseInt(card.getMonth()); |
| } |
| - } |
| - // Maybe your card expired years ago? Add the card's year |
| - // to the spinner adapter if not found. |
| - if (!foundYear && !card.getYear().isEmpty()) { |
| - @SuppressWarnings("unchecked") |
| - ArrayAdapter<CharSequence> adapter = |
| - (ArrayAdapter<CharSequence>) mExpirationYear.getAdapter(); |
| - adapter.insert(card.getYear(), 0); |
| + mInitialExpirationMonthPos = monthAsInt - 1; |
| + mExpirationMonth.setSelection(mInitialExpirationMonthPos); |
| + |
| mInitialExpirationYearPos = 0; |
| + boolean foundYear = false; |
| + for (int i = 0; i < mExpirationYear.getAdapter().getCount(); i++) { |
| + if (card.getYear().equals(mExpirationYear.getAdapter().getItem(i))) { |
| + mInitialExpirationYearPos = i; |
| + foundYear = true; |
| + break; |
| + } |
| + } |
| + // Maybe your card expired years ago? Add the card's year |
| + // to the spinner adapter if not found. |
| + if (!foundYear && !card.getYear().isEmpty()) { |
| + @SuppressWarnings("unchecked") |
| + ArrayAdapter<CharSequence> adapter = |
| + (ArrayAdapter<CharSequence>) mExpirationYear.getAdapter(); |
| + adapter.insert(card.getYear(), 0); |
| + mInitialExpirationYearPos = 0; |
| + } |
| + mExpirationYear.setSelection(mInitialExpirationYearPos); |
| + } else { |
| + hideLocalCardElements(); |
| + mServerCardLabel.setText(card.getObfuscatedNumber()); |
| + mServerCardSublabel.setText(card.getFormattedExpirationDate(getActivity())); |
| + if (!card.getIsCached()) { |
| + mServerCardClearButton.setVisibility(View.GONE); |
| + } |
| } |
| - mExpirationYear.setSelection(mInitialExpirationYearPos); |
| if (!TextUtils.isEmpty(card.getBillingAddressId())) { |
| for (int i = 0; i < mBillingAddress.getAdapter().getCount(); i++) { |
| @@ -199,21 +231,42 @@ public class AutofillCreditCardEditor extends AutofillEditorBase { |
| } |
| } |
| + void hideServerCardElements() { |
| + mServerCardLabel.setVisibility(View.GONE); |
|
gone
2016/06/29 20:09:42
Prefer removing views you'll never use to just cha
please use gerrit instead
2016/06/30 01:19:27
Switched to removing views.
|
| + mServerCardSublabel.setVisibility(View.GONE); |
| + mServerCardEditLinkContainer.setVisibility(View.GONE); |
| + mServerCardClearButton.setVisibility(View.GONE); |
| + } |
| + |
| + void hideLocalCardElements() { |
| + mNameLabel.setVisibility(View.GONE); |
| + mNameText.setVisibility(View.GONE); |
| + mNumberLabel.setVisibility(View.GONE); |
| + mNumberText.setVisibility(View.GONE); |
| + mExpirationLabel.setVisibility(View.GONE); |
| + mExpirationContainer.setVisibility(View.GONE); |
| + } |
| + |
| // Read edited data; save in the associated Chrome profile. |
| // Ignore empty fields. |
| @Override |
| protected void saveEntry() { |
| // Remove all spaces in editText. |
| String cardNumber = mNumberText.getText().toString().replaceAll("\\s+", ""); |
| - CreditCard card = new CreditCard(mGUID, AutofillPreferences.SETTINGS_ORIGIN, |
| - true /* isLocal */, false /* isCached */, mNameText.getText().toString().trim(), |
| - cardNumber, "" /* obfuscatedNumber */, |
| - String.valueOf(mExpirationMonth.getSelectedItemPosition() + 1), |
| - (String) mExpirationYear.getSelectedItem(), "" /* basicCardPaymentType */, |
| - 0 /* issuerIconDrawableId */, |
| - ((AutofillProfile) mBillingAddress.getSelectedItem()).getGUID() /* billing */); |
| - |
| - PersonalDataManager.getInstance().setCreditCard(card); |
| + if (mIsLocalCard) { |
| + CreditCard card = new CreditCard(mGUID, AutofillPreferences.SETTINGS_ORIGIN, |
| + true /* isLocal */, false /* isCached */, mNameText.getText().toString().trim(), |
| + cardNumber, "" /* obfuscatedNumber */, |
| + String.valueOf(mExpirationMonth.getSelectedItemPosition() + 1), |
| + (String) mExpirationYear.getSelectedItem(), "" /* basicCardPaymentType */, |
| + 0 /* issuerIconDrawableId */, |
| + ((AutofillProfile) mBillingAddress.getSelectedItem()).getGUID() /* billing */); |
| + PersonalDataManager.getInstance().setCreditCard(card); |
| + } else { |
| + PersonalDataManager.getInstance().updateServerCardBillingAddress(mGUID, |
| + ((AutofillProfile) mBillingAddress.getSelectedItem()).getGUID()); |
| + } |
| + |
| } |
| @Override |
| @@ -224,6 +277,11 @@ public class AutofillCreditCardEditor extends AutofillEditorBase { |
| } |
| @Override |
| + protected boolean getIsDeletable() { |
| + return mIsLocalCard; |
| + } |
| + |
| + @Override |
| protected void initializeButtons(View v) { |
| super.initializeButtons(v); |
| @@ -233,10 +291,24 @@ public class AutofillCreditCardEditor extends AutofillEditorBase { |
| mExpirationMonth.setOnItemSelectedListener(this); |
| mExpirationYear.setOnItemSelectedListener(this); |
| mBillingAddress.setOnItemSelectedListener(this); |
| + mServerCardEditLink.setOnClickListener(new View.OnClickListener() { |
| + @Override |
| + public void onClick(View v) { |
| + EmbedContentViewActivity.show(getActivity(), R.string.autofill_edit_credit_card, |
| + R.string.autofill_manage_wallet_cards_url); |
| + } |
| + }); |
| + mServerCardClearButton.setOnClickListener(new View.OnClickListener() { |
| + @Override |
| + public void onClick(View v) { |
| + PersonalDataManager.getInstance().clearUnmaskedCache(mGUID); |
| + mServerCardClearButton.setVisibility(View.GONE); |
| + } |
| + }); |
| } |
| private void updateSaveButtonEnabled() { |
| - boolean enabled = !TextUtils.isEmpty(mNameText.getText()) |
| + boolean enabled = !mIsLocalCard || !TextUtils.isEmpty(mNameText.getText()) |
| || !TextUtils.isEmpty(mNumberText.getText()); |
| Button button = (Button) getView().findViewById(R.id.button_primary); |
| button.setEnabled(enabled); |