| Index: chrome/android/java/src/org/chromium/chrome/browser/payments/PayerInfoEditor.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/PayerInfoEditor.java
|
| similarity index 62%
|
| rename from chrome/android/java/src/org/chromium/chrome/browser/payments/ContactEditor.java
|
| rename to chrome/android/java/src/org/chromium/chrome/browser/payments/PayerInfoEditor.java
|
| index bade26fc6d6b632a2d9da00cf70c9e8ae21ca15c..e67a97d9fffac72e560358b7d7d0a7428163a0f3 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/payments/ContactEditor.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/PayerInfoEditor.java
|
| @@ -21,44 +21,63 @@ import java.util.Set;
|
| import javax.annotation.Nullable;
|
|
|
| /**
|
| - * Contact information editor.
|
| + * Payer information editor.
|
| */
|
| -public class ContactEditor extends EditorBase<AutofillContact> {
|
| +public class PayerInfoEditor extends EditorBase<AutofillPayerInfo> {
|
| + 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;
|
| @Nullable private EditorFieldValidator mPhoneValidator;
|
| @Nullable private EditorFieldValidator mEmailValidator;
|
|
|
| /**
|
| - * Builds a contact information editor.
|
| + * Builds a payer 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 PayerInfoEditor(
|
| + 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<>();
|
| }
|
|
|
| /**
|
| - * Returns whether the following contact information can be sent to the merchant as-is without
|
| + * Returns whether the following payer 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.
|
| + * @return Whether the payer information is complete.
|
| */
|
| - public boolean isContactInformationComplete(@Nullable String phone, @Nullable String email) {
|
| - return (!mRequestPayerPhone || getPhoneValidator().isValid(phone))
|
| + public boolean isPayerInformationComplete(
|
| + @Nullable String name, @Nullable String phone, @Nullable String email) {
|
| + return (!mRequestPayerName || getNameValidator().isValid(name))
|
| + && (!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);
|
| + }
|
| +
|
| + /**
|
| * Adds the given phone number to the autocomplete set, if it's valid.
|
| *
|
| * @param phoneNumber The phone number to possibly add.
|
| @@ -77,11 +96,21 @@ public class ContactEditor extends EditorBase<AutofillContact> {
|
| }
|
|
|
| @Override
|
| - public void edit(@Nullable AutofillContact toEdit, final Callback<AutofillContact> callback) {
|
| + public void edit(
|
| + @Nullable AutofillPayerInfo toEdit, final Callback<AutofillPayerInfo> callback) {
|
| super.edit(toEdit, callback);
|
|
|
| - final AutofillContact contact = toEdit == null
|
| - ? new AutofillContact(new AutofillProfile(), null, null, false) : toEdit;
|
| + final AutofillPayerInfo payerInfo = toEdit == null
|
| + ? new AutofillPayerInfo(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),
|
| + payerInfo.getPayerName())
|
| + : null;
|
|
|
| final EditorFieldModel phoneField = mRequestPayerPhone
|
| ? EditorFieldModel.createTextInput(EditorFieldModel.INPUT_TYPE_HINT_PHONE,
|
| @@ -89,7 +118,7 @@ public class ContactEditor extends EditorBase<AutofillContact> {
|
| mPhoneNumbers, getPhoneValidator(),
|
| mContext.getString(R.string.payments_field_required_validation_message),
|
| mContext.getString(R.string.payments_phone_invalid_validation_message),
|
| - contact.getPayerPhone())
|
| + payerInfo.getPayerPhone())
|
| : null;
|
|
|
| final EditorFieldModel emailField = mRequestPayerEmail
|
| @@ -98,12 +127,13 @@ public class ContactEditor extends EditorBase<AutofillContact> {
|
| mEmailAddresses, getEmailValidator(),
|
| mContext.getString(R.string.payments_field_required_validation_message),
|
| mContext.getString(R.string.payments_email_invalid_validation_message),
|
| - contact.getPayerEmail())
|
| + payerInfo.getPayerEmail())
|
| : null;
|
|
|
| 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,28 +147,46 @@ 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();
|
| + payerInfo.getProfile().setFullName(name);
|
| + }
|
| +
|
| if (phoneField != null) {
|
| phone = phoneField.getValue().toString();
|
| - contact.getProfile().setPhoneNumber(phone);
|
| + payerInfo.getProfile().setPhoneNumber(phone);
|
| }
|
|
|
| if (emailField != null) {
|
| email = emailField.getValue().toString();
|
| - contact.getProfile().setEmailAddress(email);
|
| + payerInfo.getProfile().setEmailAddress(email);
|
| }
|
|
|
| - String guid = PersonalDataManager.getInstance().setProfile(contact.getProfile());
|
| - contact.completeContact(guid, phone, email);
|
| - callback.onResult(contact);
|
| + String guid = PersonalDataManager.getInstance().setProfile(payerInfo.getProfile());
|
| + payerInfo.completePayerInfo(guid, name, phone, email);
|
| + callback.onResult(payerInfo);
|
| }
|
| });
|
|
|
| mEditorView.show(editor);
|
| }
|
|
|
| + private EditorFieldValidator getNameValidator() {
|
| + if (mNameValidator == null) {
|
| + mNameValidator = new EditorFieldValidator() {
|
| + @Override
|
| + public boolean isValid(@Nullable CharSequence value) {
|
| + return value != null;
|
| + }
|
| + };
|
| + }
|
| + return mNameValidator;
|
| + }
|
| +
|
| private EditorFieldValidator getPhoneValidator() {
|
| if (mPhoneValidator == null) {
|
| mPhoneValidator = new EditorFieldValidator() {
|
|
|