| Index: chrome/android/java/src/org/chromium/chrome/browser/payments/AutofillContact.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/AutofillContact.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/AutofillContact.java
|
| index 667d2585e1162d0a0dc9f0b6c70fd61904141227..8a913994ce9b717b89c29abf2df7a0fdf74a8ff3 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/payments/AutofillContact.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/AutofillContact.java
|
| @@ -19,6 +19,10 @@ import javax.annotation.Nullable;
|
| public class AutofillContact extends PaymentOption {
|
| private final AutofillProfile mProfile;
|
| private final Context mContext;
|
| + private int mCompletionStatus;
|
| + private boolean mRequestName;
|
| + private boolean mRequestPhone;
|
| + private boolean mRequestEmail;
|
| @Nullable private String mPayerName;
|
| @Nullable private String mPayerPhone;
|
| @Nullable private String mPayerEmail;
|
| @@ -33,13 +37,20 @@ public class AutofillContact extends PaymentOption {
|
| * @param email The email address. If name and phone are empty, this will be the
|
| * primary label.
|
| * @param completionStatus The completion status of this contact.
|
| + * @param requestName Whether the merchant requests a payer name.
|
| + * @param requestPhone Whether the merchant requests a payer phone number.
|
| + * @param requestEmail Whether the merchant requests a payer email address.
|
| */
|
| public AutofillContact(Context context, AutofillProfile profile, @Nullable String name,
|
| @Nullable String phone, @Nullable String email,
|
| - @ContactEditor.CompletionStatus int completionStatus) {
|
| + @ContactEditor.CompletionStatus int completionStatus, boolean requestName,
|
| + boolean requestPhone, boolean requestEmail) {
|
| super(profile.getGUID(), null, null, null, null);
|
| mContext = context;
|
| mProfile = profile;
|
| + mRequestName = requestName;
|
| + mRequestPhone = requestPhone;
|
| + mRequestEmail = requestEmail;
|
| mIsEditable = true;
|
| setContactInfo(profile.getGUID(), name, phone, email);
|
| updateCompletionStatus(completionStatus);
|
| @@ -50,16 +61,17 @@ public class AutofillContact extends PaymentOption {
|
| return mPayerName;
|
| }
|
|
|
| - /** @return Email address. Null if the merchant did not request it or data is incomplete. */
|
| - @Nullable public String getPayerEmail() {
|
| - return mPayerEmail;
|
| - }
|
| -
|
| /** @return Phone number. Null if the merchant did not request it or data is incomplete. */
|
| @Nullable public String getPayerPhone() {
|
| return mPayerPhone;
|
| }
|
|
|
| + /** @return Email address. Null if the merchant did not request it or data is incomplete. */
|
| + @Nullable
|
| + public String getPayerEmail() {
|
| + return mPayerEmail;
|
| + }
|
| +
|
| /** @return The autofill profile where this contact data lives. */
|
| public AutofillProfile getProfile() {
|
| return mProfile;
|
| @@ -87,6 +99,60 @@ public class AutofillContact extends PaymentOption {
|
| updateCompletionStatus(ContactEditor.COMPLETE);
|
| }
|
|
|
| + /**
|
| + * Returns whether this contact is equal or a superset of the specified contact considering the
|
| + * information requested by the merchant.
|
| + *
|
| + * @param contact The contact to compare to.
|
| + * @return Whether this contact is equal to or a superset of the other.
|
| + */
|
| + public boolean isEqualOrSupersetOf(AutofillContact contact) {
|
| + assert contact != null;
|
| +
|
| + // This contact is not equal to or a superset of the other if for a requested field:
|
| + // 1- This contact's field is null and the other's is not.
|
| + // 2- The field values are not equal.
|
| + if (mRequestName) {
|
| + if (mPayerName == null && contact.mPayerName != null) return false;
|
| + if (mPayerName != null && contact.mPayerName != null
|
| + && !mPayerName.equalsIgnoreCase(contact.mPayerName)) {
|
| + return false;
|
| + }
|
| + }
|
| +
|
| + if (mRequestPhone) {
|
| + if (mPayerPhone == null && contact.mPayerPhone != null) return false;
|
| + if (mPayerPhone != null && contact.mPayerPhone != null
|
| + && !TextUtils.equals(mPayerPhone, contact.mPayerPhone)) {
|
| + return false;
|
| + }
|
| + }
|
| +
|
| + if (mRequestEmail) {
|
| + if (mPayerEmail == null && contact.mPayerEmail != null) return false;
|
| + if (mPayerEmail != null && contact.mPayerEmail != null
|
| + && !mPayerEmail.equalsIgnoreCase(contact.mPayerEmail)) {
|
| + return false;
|
| + }
|
| + }
|
| +
|
| + return true;
|
| + }
|
| +
|
| + /**
|
| + * @return Returns the relevance score of this contact, based on the validity of the information
|
| + * requested by the merchant.
|
| + */
|
| + public int getRelevanceScore() {
|
| + int score = 0;
|
| +
|
| + if (mRequestName && (mCompletionStatus & ContactEditor.INVALID_NAME) == 0) ++score;
|
| + if (mRequestPhone && (mCompletionStatus & ContactEditor.INVALID_PHONE_NUMBER) == 0) ++score;
|
| + if (mRequestEmail && (mCompletionStatus & ContactEditor.INVALID_EMAIL) == 0) ++score;
|
| +
|
| + return score;
|
| + }
|
| +
|
| private void setContactInfo(String guid, @Nullable String name,
|
| @Nullable String phone, @Nullable String email) {
|
| mPayerName = TextUtils.isEmpty(name) ? null : name;
|
| @@ -104,6 +170,7 @@ public class AutofillContact extends PaymentOption {
|
| }
|
|
|
| private void updateCompletionStatus(int completionStatus) {
|
| + mCompletionStatus = completionStatus;
|
| mIsComplete = completionStatus == ContactEditor.COMPLETE;
|
|
|
| switch (completionStatus) {
|
| @@ -123,12 +190,11 @@ public class AutofillContact extends PaymentOption {
|
| mEditMessage = mContext.getString(R.string.payments_phone_number_required);
|
| mEditTitle = mContext.getString(R.string.payments_add_phone_number);
|
| break;
|
| - case ContactEditor.INVALID_MULTIPLE_FIELDS:
|
| + default:
|
| + // Multiple invalid fields.
|
| mEditMessage = mContext.getString(R.string.payments_more_information_required);
|
| mEditTitle = mContext.getString(R.string.payments_add_more_information);
|
| break;
|
| - default:
|
| - assert false : "Invalid completion status code";
|
| }
|
| }
|
| }
|
|
|