Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/payments/ContactEditor.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/ContactEditor.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/ContactEditor.java |
| index bade26fc6d6b632a2d9da00cf70c9e8ae21ca15c..1e689b1ac761dc1c0a04a0597f88201ebd189661 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/payments/ContactEditor.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/ContactEditor.java |
| @@ -24,23 +24,30 @@ import javax.annotation.Nullable; |
| * Contact information editor. |
| */ |
| public class ContactEditor extends EditorBase<AutofillContact> { |
| + private final boolean mRequestPayerName; |
| private final boolean mRequestPayerPhone; |
| private final boolean mRequestPayerEmail; |
| + private final Set<CharSequence> mPayerNames; |
| private final Set<CharSequence> mPhoneNumbers; |
| private final Set<CharSequence> mEmailAddresses; |
| + @Nullable private EditorFieldValidator mNameValidator; |
|
please use gerrit instead
2016/10/13 20:20:33
No need for a fancy format validator for names, be
zino
2016/10/14 19:01:56
Done.
|
| @Nullable private EditorFieldValidator mPhoneValidator; |
| @Nullable private EditorFieldValidator mEmailValidator; |
| /** |
| * Builds a contact information editor. |
| * |
| + * @param requestPayerName Whether to request the user's name. |
| * @param requestPayerPhone Whether to request the user's phone number. |
| * @param requestPayerEmail Whether to request the user's email address. |
| */ |
| - public ContactEditor(boolean requestPayerPhone, boolean requestPayerEmail) { |
| - assert requestPayerPhone || requestPayerEmail; |
| + public ContactEditor(boolean requestPayerName, |
| + boolean requestPayerPhone, boolean requestPayerEmail) { |
| + assert requestPayerName || requestPayerPhone || requestPayerEmail; |
| + mRequestPayerName = requestPayerName; |
| mRequestPayerPhone = requestPayerPhone; |
| mRequestPayerEmail = requestPayerEmail; |
| + mPayerNames = new HashSet<>(); |
| mPhoneNumbers = new HashSet<>(); |
| mEmailAddresses = new HashSet<>(); |
| } |
| @@ -49,16 +56,28 @@ public class ContactEditor extends EditorBase<AutofillContact> { |
| * Returns whether the following contact information can be sent to the merchant as-is without |
| * editing first. |
| * |
| + * @param name The payer name to check. |
| * @param phone The phone number to check. |
| * @param email The email address to check. |
| * @return Whether the contact information is complete. |
| */ |
| - public boolean isContactInformationComplete(@Nullable String phone, @Nullable String email) { |
| - return (!mRequestPayerPhone || getPhoneValidator().isValid(phone)) |
| + public boolean isContactInformationComplete( |
| + @Nullable String name, @Nullable String phone, @Nullable String email) { |
| + return (!mRequestPayerName || getNameValidator().isValid(name)) |
|
please use gerrit instead
2016/10/13 20:20:33
Use the built-in !TextUtils.isEmpty(payerName) ins
zino
2016/10/14 19:01:56
Done.
|
| + && (!mRequestPayerPhone || getPhoneValidator().isValid(phone)) |
| && (!mRequestPayerEmail || getEmailValidator().isValid(email)); |
| } |
| /** |
| + * Adds the given payer name to the autocomplete set, if it's valid. |
| + * |
| + * @param payerName The payer name to possibly add. |
| + */ |
| + public void addPayerNameIfValid(@Nullable CharSequence payerName) { |
| + if (getNameValidator().isValid(payerName)) mPayerNames.add(payerName); |
|
please use gerrit instead
2016/10/13 20:20:33
Use the built-in !TextUtils.isEmpty(payerName) ins
zino
2016/10/14 19:01:56
Done.
|
| + } |
| + |
| + /** |
| * Adds the given phone number to the autocomplete set, if it's valid. |
| * |
| * @param phoneNumber The phone number to possibly add. |
| @@ -81,7 +100,16 @@ public class ContactEditor extends EditorBase<AutofillContact> { |
| super.edit(toEdit, callback); |
| final AutofillContact contact = toEdit == null |
| - ? new AutofillContact(new AutofillProfile(), null, null, false) : toEdit; |
| + ? new AutofillContact(new AutofillProfile(), null, null, null, false) : toEdit; |
| + |
| + final EditorFieldModel nameField = mRequestPayerName |
| + ? EditorFieldModel.createTextInput(EditorFieldModel.INPUT_TYPE_HINT_PERSON_NAME, |
| + mContext.getString(R.string.autofill_profile_editor_name), |
| + mPayerNames, getNameValidator(), |
| + mContext.getString(R.string.payments_field_required_validation_message), |
| + mContext.getString(R.string.payments_name_invalid_validation_message), |
|
please use gerrit instead
2016/10/13 20:20:33
The only validation for payer names is that it's n
zino
2016/10/14 19:01:56
Done.
|
| + contact.getPayerName()) |
| + : null; |
| final EditorFieldModel phoneField = mRequestPayerPhone |
| ? EditorFieldModel.createTextInput(EditorFieldModel.INPUT_TYPE_HINT_PHONE, |
| @@ -104,6 +132,7 @@ public class ContactEditor extends EditorBase<AutofillContact> { |
| EditorModel editor = new EditorModel( |
| mContext.getString(toEdit == null ? R.string.payments_add_contact_details_label |
| : R.string.payments_edit_contact_details_label)); |
| + if (nameField != null) editor.addField(nameField); |
| if (phoneField != null) editor.addField(phoneField); |
| if (emailField != null) editor.addField(emailField); |
| @@ -117,9 +146,15 @@ public class ContactEditor extends EditorBase<AutofillContact> { |
| editor.setDoneCallback(new Runnable() { |
| @Override |
| public void run() { |
| + String name = null; |
| String phone = null; |
| String email = null; |
| + if (nameField != null) { |
| + name = nameField.getValue().toString(); |
| + contact.getProfile().setFullName(name); |
| + } |
| + |
| if (phoneField != null) { |
| phone = phoneField.getValue().toString(); |
| contact.getProfile().setPhoneNumber(phone); |
| @@ -131,7 +166,7 @@ public class ContactEditor extends EditorBase<AutofillContact> { |
| } |
| String guid = PersonalDataManager.getInstance().setProfile(contact.getProfile()); |
| - contact.completeContact(guid, phone, email); |
| + contact.completeContact(guid, name, phone, email); |
| callback.onResult(contact); |
| } |
| }); |
| @@ -139,6 +174,18 @@ public class ContactEditor extends EditorBase<AutofillContact> { |
| mEditorView.show(editor); |
| } |
| + private EditorFieldValidator getNameValidator() { |
| + if (mNameValidator == null) { |
| + mNameValidator = new EditorFieldValidator() { |
| + @Override |
| + public boolean isValid(@Nullable CharSequence value) { |
| + return value != null; |
| + } |
| + }; |
| + } |
| + return mNameValidator; |
| + } |
|
please use gerrit instead
2016/10/13 20:20:33
There's no need for an EditorFieldValidator for na
zino
2016/10/14 19:01:56
Done.
|
| + |
| private EditorFieldValidator getPhoneValidator() { |
| if (mPhoneValidator == null) { |
| mPhoneValidator = new EditorFieldValidator() { |