OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.payments; | 5 package org.chromium.chrome.browser.payments; |
6 | 6 |
7 import android.app.ProgressDialog; | 7 import android.app.ProgressDialog; |
8 import android.os.Handler; | 8 import android.os.Handler; |
9 import android.util.Pair; | 9 import android.util.Pair; |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 private boolean mAdminAreasLoaded; | 51 private boolean mAdminAreasLoaded; |
52 private String mRecentlySelectedCountry; | 52 private String mRecentlySelectedCountry; |
53 private Runnable mCountryChangeCallback; | 53 private Runnable mCountryChangeCallback; |
54 private AutofillProfile mProfile; | 54 private AutofillProfile mProfile; |
55 private EditorModel mEditor; | 55 private EditorModel mEditor; |
56 private ProgressDialog mProgressDialog; | 56 private ProgressDialog mProgressDialog; |
57 | 57 |
58 /** | 58 /** |
59 * Adds the given phone number to the autocomplete set, if it's valid. | 59 * Adds the given phone number to the autocomplete set, if it's valid. |
60 * | 60 * |
61 * @param phoneNumber The phone number to possibly add. | 61 * @param phoneNumber The phone number to possibly add. |
gogerald1
2017/06/15 17:41:35
comments: @param countryCode .....
wuandy1
2017/06/19 15:11:14
deleted
| |
62 */ | 62 */ |
63 public void addPhoneNumberIfValid(@Nullable CharSequence phoneNumber) { | 63 public void addPhoneNumberIfValid( |
64 if (getPhoneValidator().isValid(phoneNumber)) mPhoneNumbers.add(phoneNum ber); | 64 @Nullable CharSequence phoneNumber, @Nullable String countryCode) { |
gogerald1
2017/06/15 17:41:35
this countryCode doesn't take effect, since it may
wuandy1
2017/06/19 15:11:14
removed validation.
| |
65 if (getPhoneValidator(countryCode).isValid(phoneNumber)) mPhoneNumbers.a dd(phoneNumber); | |
65 } | 66 } |
66 | 67 |
67 /** | 68 /** |
68 * Builds and shows an editor model with the following fields. | 69 * Builds and shows an editor model with the following fields. |
69 * | 70 * |
70 * [ country dropdown ] <----- country dropdown is always present. | 71 * [ country dropdown ] <----- country dropdown is always present. |
71 * [ an address field ] \ | 72 * [ an address field ] \ |
72 * [ an address field ] \ | 73 * [ an address field ] \ |
73 * ... <-- field order, presence, required, and labels depend on country. | 74 * ... <-- field order, presence, required, and labels depend on country. |
74 * [ an address field ] / | 75 * [ an address field ] / |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 * If the selected country on the country dropdown list is changed, | 117 * If the selected country on the country dropdown list is changed, |
117 * the first element of eventData is the recently selected dropdown key, | 118 * the first element of eventData is the recently selected dropdown key, |
118 * the second element is the callback to invoke for when the dropdow n | 119 * the second element is the callback to invoke for when the dropdow n |
119 * change has been processed. | 120 * change has been processed. |
120 */ | 121 */ |
121 @Override | 122 @Override |
122 public void onResult(Pair<String, Runnable> eventData) { | 123 public void onResult(Pair<String, Runnable> eventData) { |
123 mEditor.removeAllFields(); | 124 mEditor.removeAllFields(); |
124 showProgressDialog(); | 125 showProgressDialog(); |
125 mRecentlySelectedCountry = eventData.first; | 126 mRecentlySelectedCountry = eventData.first; |
127 mEditorDialog.updateCountryOfPhoneFormatter(mRecentlySelectedCou ntry); | |
gogerald1
2017/06/15 17:41:35
This not enough as I mentioned in the last review.
wuandy1
2017/06/19 15:11:14
add code to initialize it, not sure this is what y
| |
126 mCountryChangeCallback = eventData.second; | 128 mCountryChangeCallback = eventData.second; |
127 loadAdminAreasForCountry(mRecentlySelectedCountry); | 129 loadAdminAreasForCountry(mRecentlySelectedCountry); |
128 } | 130 } |
129 }); | 131 }); |
130 | 132 |
131 // Country dropdown is cached, so the selected item needs to be updated for the new profile | 133 // Country dropdown is cached, so the selected item needs to be updated for the new profile |
132 // that's being edited. This will not fire the dropdown callback. | 134 // that's being edited. This will not fire the dropdown callback. |
133 mCountryField.setValue(AutofillAddress.getCountryCode(mProfile)); | 135 mCountryField.setValue(AutofillAddress.getCountryCode(mProfile)); |
134 | 136 |
135 // There's a finite number of fields for address editing. Changing the c ountry will re-order | 137 // There's a finite number of fields for address editing. Changing the c ountry will re-order |
(...skipping 18 matching lines...) Expand all Loading... | |
154 // Android has special formatting rules for names. | 156 // Android has special formatting rules for names. |
155 mAddressFields.put(AddressField.RECIPIENT, EditorFieldModel.createTe xtInput( | 157 mAddressFields.put(AddressField.RECIPIENT, EditorFieldModel.createTe xtInput( |
156 EditorFieldModel.INPUT_TYPE_HINT_PERSON_NAME)); | 158 EditorFieldModel.INPUT_TYPE_HINT_PERSON_NAME)); |
157 } | 159 } |
158 | 160 |
159 | 161 |
160 // Phone number is present and required for all countries. | 162 // Phone number is present and required for all countries. |
161 if (mPhoneField == null) { | 163 if (mPhoneField == null) { |
162 mPhoneField = EditorFieldModel.createTextInput(EditorFieldModel.INPU T_TYPE_HINT_PHONE, | 164 mPhoneField = EditorFieldModel.createTextInput(EditorFieldModel.INPU T_TYPE_HINT_PHONE, |
163 mContext.getString(R.string.autofill_profile_editor_phone_nu mber), | 165 mContext.getString(R.string.autofill_profile_editor_phone_nu mber), |
164 mPhoneNumbers, getPhoneValidator(), null, | 166 mPhoneNumbers, getPhoneValidator(null), null, |
gogerald1
2017/06/15 17:41:35
mCountryField.getValue()? since we have set defaul
wuandy1
2017/06/19 15:11:14
Done.
| |
165 mContext.getString(R.string.payments_field_required_validati on_message), | 167 mContext.getString(R.string.payments_field_required_validati on_message), |
166 mContext.getString(R.string.payments_phone_invalid_validatio n_message), null); | 168 mContext.getString(R.string.payments_phone_invalid_validatio n_message), null); |
167 } | 169 } |
168 | 170 |
169 // Phone number field is cached, so its value needs to be updated for ev ery new profile | 171 // Phone number field is cached, so its value needs to be updated for ev ery new profile |
170 // that's being edited. | 172 // that's being edited. |
171 mPhoneField.setValue(mProfile.getPhoneNumber()); | 173 mPhoneField.setValue(mProfile.getPhoneNumber()); |
172 | 174 |
173 // If the user clicks [Cancel], send |toEdit| address back to the caller , which was the | 175 // If the user clicks [Cancel], send |toEdit| address back to the caller , which was the |
174 // original state (could be null, a complete address, a partial address) . | 176 // original state (could be null, a complete address, a partial address) . |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 R.string.payments_field_required_validation_message)); | 385 R.string.payments_field_required_validation_message)); |
384 } else { | 386 } else { |
385 field.setRequiredErrorMessage(null); | 387 field.setRequiredErrorMessage(null); |
386 } | 388 } |
387 mEditor.addField(field); | 389 mEditor.addField(field); |
388 } | 390 } |
389 // Phone number must be the last field. | 391 // Phone number must be the last field. |
390 mEditor.addField(mPhoneField); | 392 mEditor.addField(mPhoneField); |
391 } | 393 } |
392 | 394 |
393 private EditorFieldValidator getPhoneValidator() { | 395 private EditorFieldValidator getPhoneValidator(@Nullable final String countr yCode) { |
394 if (mPhoneValidator == null) { | 396 if (mPhoneValidator == null) { |
gogerald1
2017/06/15 17:41:35
This makes the countryCode of mPhoneValidator is f
wuandy1
2017/06/19 15:11:14
Done.
| |
395 mPhoneValidator = new EditorFieldValidator() { | 397 mPhoneValidator = new EditorFieldValidator() { |
396 @Override | 398 @Override |
397 public boolean isValid(@Nullable CharSequence value) { | 399 public boolean isValid(@Nullable CharSequence value) { |
398 return value != null && PhoneNumberUtil.isValidNumber(value. toString()); | 400 String countryToValidateAgainst = countryCode != null |
401 ? countryCode | |
402 : (mCountryField == null ? null : mCountryField.getV alue().toString()); | |
403 return value != null | |
404 && PhoneNumberUtil.isValidNumber( | |
405 value.toString(), countryToValidateAgains t); | |
399 } | 406 } |
400 | 407 |
401 @Override | 408 @Override |
402 public boolean isLengthMaximum(@Nullable CharSequence value) { | 409 public boolean isLengthMaximum(@Nullable CharSequence value) { |
403 return false; | 410 return false; |
404 } | 411 } |
405 }; | 412 }; |
406 } | 413 } |
407 return mPhoneValidator; | 414 return mPhoneValidator; |
408 } | 415 } |
409 } | 416 } |
OLD | NEW |