Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3300)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/payments/AddressEditor.java

Issue 2924513002: use user chosen country code to format and validate phone number for addresses. (Closed)
Patch Set: fix presubmit complaints Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/payments/AddressEditor.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/AddressEditor.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/AddressEditor.java
index 804186b826fa310271e1c379236ff673cd97a597..053a16a44670960623737b0800e128305b6a0b5e 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/payments/AddressEditor.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/AddressEditor.java
@@ -58,10 +58,13 @@ public class AddressEditor
/**
* Adds the given phone number to the autocomplete set, if it's valid.
*
- * @param phoneNumber The phone number to possibly add.
+ * @param phoneNumber The phone number to possibly add, if it is not null or empty.
+ * We don't validate for number format since these are suggestions only.
gogerald1 2017/06/19 21:30:38 The reason we do not validate it here is not becau
wuandy1 2017/06/20 15:33:26 Done.
*/
public void addPhoneNumberIfValid(@Nullable CharSequence phoneNumber) {
- if (getPhoneValidator().isValid(phoneNumber)) mPhoneNumbers.add(phoneNumber);
+ if (phoneNumber != null && !phoneNumber.toString().isEmpty()) {
gogerald1 2017/06/19 21:30:38 use TextUtils.isEmpty() which do both, https://cs.
wuandy1 2017/06/20 15:33:27 Done.
+ mPhoneNumbers.add(phoneNumber.toString());
+ }
}
/**
@@ -123,6 +126,7 @@ public class AddressEditor
mEditor.removeAllFields();
showProgressDialog();
mRecentlySelectedCountry = eventData.first;
+ mEditorDialog.updateCountryOfPhoneFormatter(mRecentlySelectedCountry);
mCountryChangeCallback = eventData.second;
loadAdminAreasForCountry(mRecentlySelectedCountry);
}
@@ -131,6 +135,7 @@ public class AddressEditor
// Country dropdown is cached, so the selected item needs to be updated for the new profile
// that's being edited. This will not fire the dropdown callback.
mCountryField.setValue(AutofillAddress.getCountryCode(mProfile));
+ mEditorDialog.updateCountryOfPhoneFormatter(mCountryField.getValue().toString());
// There's a finite number of fields for address editing. Changing the country will re-order
// and relabel the fields. The meaning of each field remains the same.
@@ -161,7 +166,7 @@ public class AddressEditor
if (mPhoneField == null) {
mPhoneField = EditorFieldModel.createTextInput(EditorFieldModel.INPUT_TYPE_HINT_PHONE,
mContext.getString(R.string.autofill_profile_editor_phone_number),
- mPhoneNumbers, getPhoneValidator(), null,
+ mPhoneNumbers, getPhoneValidator(mCountryField), null,
mContext.getString(R.string.payments_field_required_validation_message),
mContext.getString(R.string.payments_phone_invalid_validation_message), null);
}
@@ -390,12 +395,19 @@ public class AddressEditor
mEditor.addField(mPhoneField);
}
- private EditorFieldValidator getPhoneValidator() {
+ private EditorFieldValidator getPhoneValidator(
+ @Nullable final EditorFieldModel countryCodeField) {
gogerald1 2017/06/19 21:30:38 Why are you using EditorFieldModel instead of coun
wuandy1 2017/06/20 15:33:26 because validator can then run validation after us
if (mPhoneValidator == null) {
mPhoneValidator = new EditorFieldValidator() {
@Override
public boolean isValid(@Nullable CharSequence value) {
- return value != null && PhoneNumberUtil.isValidNumber(value.toString());
+ String countryToValidateAgainst =
+ (countryCodeField == null || countryCodeField.getValue() == null)
+ ? null
+ : countryCodeField.getValue().toString();
+ return value != null
+ && PhoneNumberUtil.isValidNumber(
+ value.toString(), countryToValidateAgainst);
}
@Override

Powered by Google App Engine
This is Rietveld 408576698