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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/payments/AutofillContact.java

Issue 2583593002: [Payments] Dedupe subsets in contact detail suggestions. (Closed)
Patch Set: Nit Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/payments/ContactEditor.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.content.Context; 7 import android.content.Context;
8 import android.text.TextUtils; 8 import android.text.TextUtils;
9 9
10 import org.chromium.chrome.R; 10 import org.chromium.chrome.R;
11 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; 11 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile;
12 import org.chromium.chrome.browser.payments.ui.PaymentOption; 12 import org.chromium.chrome.browser.payments.ui.PaymentOption;
13 13
14 import javax.annotation.Nullable; 14 import javax.annotation.Nullable;
15 15
16 /** 16 /**
17 * The locally stored contact details. 17 * The locally stored contact details.
18 */ 18 */
19 public class AutofillContact extends PaymentOption { 19 public class AutofillContact extends PaymentOption {
20 private final AutofillProfile mProfile; 20 private final AutofillProfile mProfile;
21 private final Context mContext; 21 private final Context mContext;
22 private int mCompletionStatus;
23 private boolean mRequestName;
24 private boolean mRequestPhone;
25 private boolean mRequestEmail;
22 @Nullable private String mPayerName; 26 @Nullable private String mPayerName;
23 @Nullable private String mPayerPhone; 27 @Nullable private String mPayerPhone;
24 @Nullable private String mPayerEmail; 28 @Nullable private String mPayerEmail;
25 29
26 /** 30 /**
27 * Builds contact details. 31 * Builds contact details.
28 * 32 *
29 * @param context The application context. 33 * @param context The application context.
30 * @param profile The autofill profile where this contact data live s. 34 * @param profile The autofill profile where this contact data live s.
31 * @param name The payer name. If not empty, this will be the pr imary label. 35 * @param name The payer name. If not empty, this will be the pr imary label.
32 * @param phone The phone number. If name is empty, this will be the primary label. 36 * @param phone The phone number. If name is empty, this will be the primary label.
33 * @param email The email address. If name and phone are empty, t his will be the 37 * @param email The email address. If name and phone are empty, t his will be the
34 * primary label. 38 * primary label.
35 * @param completionStatus The completion status of this contact. 39 * @param completionStatus The completion status of this contact.
40 * @param requestName Whether the merchant requests a payer name.
41 * @param requestPhone Whether the merchant requests a payer phone numbe r.
42 * @param requestEmail Whether the merchant requests a payer email addre ss.
36 */ 43 */
37 public AutofillContact(Context context, AutofillProfile profile, @Nullable S tring name, 44 public AutofillContact(Context context, AutofillProfile profile, @Nullable S tring name,
38 @Nullable String phone, @Nullable String email, 45 @Nullable String phone, @Nullable String email,
39 @ContactEditor.CompletionStatus int completionStatus) { 46 @ContactEditor.CompletionStatus int completionStatus, boolean reques tName,
47 boolean requestPhone, boolean requestEmail) {
40 super(profile.getGUID(), null, null, null, null); 48 super(profile.getGUID(), null, null, null, null);
41 mContext = context; 49 mContext = context;
42 mProfile = profile; 50 mProfile = profile;
51 mRequestName = requestName;
52 mRequestPhone = requestPhone;
53 mRequestEmail = requestEmail;
43 mIsEditable = true; 54 mIsEditable = true;
44 setContactInfo(profile.getGUID(), name, phone, email); 55 setContactInfo(profile.getGUID(), name, phone, email);
45 updateCompletionStatus(completionStatus); 56 updateCompletionStatus(completionStatus);
46 } 57 }
47 58
48 /** @return Payer name. Null if the merchant did not request it or data is i ncomplete. */ 59 /** @return Payer name. Null if the merchant did not request it or data is i ncomplete. */
49 @Nullable public String getPayerName() { 60 @Nullable public String getPayerName() {
50 return mPayerName; 61 return mPayerName;
51 } 62 }
52 63
53 /** @return Email address. Null if the merchant did not request it or data i s incomplete. */
54 @Nullable public String getPayerEmail() {
55 return mPayerEmail;
56 }
57
58 /** @return Phone number. Null if the merchant did not request it or data is incomplete. */ 64 /** @return Phone number. Null if the merchant did not request it or data is incomplete. */
59 @Nullable public String getPayerPhone() { 65 @Nullable public String getPayerPhone() {
60 return mPayerPhone; 66 return mPayerPhone;
61 } 67 }
62 68
69 /** @return Email address. Null if the merchant did not request it or data i s incomplete. */
70 @Nullable
71 public String getPayerEmail() {
72 return mPayerEmail;
73 }
74
63 /** @return The autofill profile where this contact data lives. */ 75 /** @return The autofill profile where this contact data lives. */
64 public AutofillProfile getProfile() { 76 public AutofillProfile getProfile() {
65 return mProfile; 77 return mProfile;
66 } 78 }
67 79
68 /** @return Whether the contact is complete and ready to be sent to the merc hant as-is. */ 80 /** @return Whether the contact is complete and ready to be sent to the merc hant as-is. */
69 public boolean isComplete() { 81 public boolean isComplete() {
70 return mIsComplete; 82 return mIsComplete;
71 } 83 }
72 84
73 /** 85 /**
74 * Updates the profile guid, payer name, email address, and phone number and marks this 86 * Updates the profile guid, payer name, email address, and phone number and marks this
75 * information "complete." Called after the user has edited this contact inf ormation. 87 * information "complete." Called after the user has edited this contact inf ormation.
76 * Update the identifier, label, sublabel, and tertiarylabel. 88 * Update the identifier, label, sublabel, and tertiarylabel.
77 * 89 *
78 * @param guid The new identifier to use. Should not be null or empty. 90 * @param guid The new identifier to use. Should not be null or empty.
79 * @param name The new payer name to use. If not empty, this will be the pr imary label. 91 * @param name The new payer name to use. If not empty, this will be the pr imary label.
80 * @param phone The new phone number to use. If name is empty, this will be the primary label. 92 * @param phone The new phone number to use. If name is empty, this will be the primary label.
81 * @param email The new email address to use. If email and phone are empty, this will be the 93 * @param email The new email address to use. If email and phone are empty, this will be the
82 * primary label. 94 * primary label.
83 */ 95 */
84 public void completeContact(String guid, @Nullable String name, 96 public void completeContact(String guid, @Nullable String name,
85 @Nullable String phone, @Nullable String email) { 97 @Nullable String phone, @Nullable String email) {
86 setContactInfo(guid, name, phone, email); 98 setContactInfo(guid, name, phone, email);
87 updateCompletionStatus(ContactEditor.COMPLETE); 99 updateCompletionStatus(ContactEditor.COMPLETE);
88 } 100 }
89 101
102 /**
103 * Returns whether this contact is equal or a superset of the specified cont act considering the
104 * information requested by the merchant.
105 *
106 * @param contact The contact to compare to.
107 * @return Whether this contact is equal to or a superset of the other.
108 */
109 public boolean isEqualOrSupersetOf(AutofillContact contact) {
110 assert contact != null;
111
112 // This contact is not equal to or a superset of the other if for a requ ested field:
113 // 1- This contact's field is null and the other's is not.
114 // 2- The field values are not equal.
115 if (mRequestName) {
116 if (mPayerName == null && contact.mPayerName != null) return false;
117 if (mPayerName != null && contact.mPayerName != null
118 && !mPayerName.equalsIgnoreCase(contact.mPayerName)) {
119 return false;
120 }
121 }
122
123 if (mRequestPhone) {
124 if (mPayerPhone == null && contact.mPayerPhone != null) return false ;
125 if (mPayerPhone != null && contact.mPayerPhone != null
126 && !TextUtils.equals(mPayerPhone, contact.mPayerPhone)) {
127 return false;
128 }
129 }
130
131 if (mRequestEmail) {
132 if (mPayerEmail == null && contact.mPayerEmail != null) return false ;
133 if (mPayerEmail != null && contact.mPayerEmail != null
134 && !mPayerEmail.equalsIgnoreCase(contact.mPayerEmail)) {
135 return false;
136 }
137 }
138
139 return true;
140 }
141
142 /**
143 * @return Returns the relevance score of this contact, based on the validit y of the information
144 * requested by the merchant.
145 */
146 public int getRelevanceScore() {
147 int score = 0;
148
149 if (mRequestName && (mCompletionStatus & ContactEditor.INVALID_NAME) == 0) ++score;
150 if (mRequestPhone && (mCompletionStatus & ContactEditor.INVALID_PHONE_NU MBER) == 0) ++score;
151 if (mRequestEmail && (mCompletionStatus & ContactEditor.INVALID_EMAIL) = = 0) ++score;
152
153 return score;
154 }
155
90 private void setContactInfo(String guid, @Nullable String name, 156 private void setContactInfo(String guid, @Nullable String name,
91 @Nullable String phone, @Nullable String email) { 157 @Nullable String phone, @Nullable String email) {
92 mPayerName = TextUtils.isEmpty(name) ? null : name; 158 mPayerName = TextUtils.isEmpty(name) ? null : name;
93 mPayerPhone = TextUtils.isEmpty(phone) ? null : phone; 159 mPayerPhone = TextUtils.isEmpty(phone) ? null : phone;
94 mPayerEmail = TextUtils.isEmpty(email) ? null : email; 160 mPayerEmail = TextUtils.isEmpty(email) ? null : email;
95 161
96 if (mPayerName == null) { 162 if (mPayerName == null) {
97 updateIdentifierAndLabels(guid, mPayerPhone == null ? mPayerEmail : mPayerPhone, 163 updateIdentifierAndLabels(guid, mPayerPhone == null ? mPayerEmail : mPayerPhone,
98 mPayerPhone == null ? null : mPayerEmail); 164 mPayerPhone == null ? null : mPayerEmail);
99 } else { 165 } else {
100 updateIdentifierAndLabels(guid, mPayerName, 166 updateIdentifierAndLabels(guid, mPayerName,
101 mPayerPhone == null ? mPayerEmail : mPayerPhone, 167 mPayerPhone == null ? mPayerEmail : mPayerPhone,
102 mPayerPhone == null ? null : mPayerEmail); 168 mPayerPhone == null ? null : mPayerEmail);
103 } 169 }
104 } 170 }
105 171
106 private void updateCompletionStatus(int completionStatus) { 172 private void updateCompletionStatus(int completionStatus) {
173 mCompletionStatus = completionStatus;
107 mIsComplete = completionStatus == ContactEditor.COMPLETE; 174 mIsComplete = completionStatus == ContactEditor.COMPLETE;
108 175
109 switch (completionStatus) { 176 switch (completionStatus) {
110 case ContactEditor.COMPLETE: 177 case ContactEditor.COMPLETE:
111 mEditMessage = null; 178 mEditMessage = null;
112 mEditTitle = mContext.getString(R.string.payments_edit_contact_d etails_label); 179 mEditTitle = mContext.getString(R.string.payments_edit_contact_d etails_label);
113 break; 180 break;
114 case ContactEditor.INVALID_NAME: 181 case ContactEditor.INVALID_NAME:
115 mEditMessage = mContext.getString(R.string.payments_name_require d); 182 mEditMessage = mContext.getString(R.string.payments_name_require d);
116 mEditTitle = mContext.getString(R.string.payments_add_name); 183 mEditTitle = mContext.getString(R.string.payments_add_name);
117 break; 184 break;
118 case ContactEditor.INVALID_EMAIL: 185 case ContactEditor.INVALID_EMAIL:
119 mEditMessage = mContext.getString(R.string.payments_email_requir ed); 186 mEditMessage = mContext.getString(R.string.payments_email_requir ed);
120 mEditTitle = mContext.getString(R.string.payments_add_email); 187 mEditTitle = mContext.getString(R.string.payments_add_email);
121 break; 188 break;
122 case ContactEditor.INVALID_PHONE_NUMBER: 189 case ContactEditor.INVALID_PHONE_NUMBER:
123 mEditMessage = mContext.getString(R.string.payments_phone_number _required); 190 mEditMessage = mContext.getString(R.string.payments_phone_number _required);
124 mEditTitle = mContext.getString(R.string.payments_add_phone_numb er); 191 mEditTitle = mContext.getString(R.string.payments_add_phone_numb er);
125 break; 192 break;
126 case ContactEditor.INVALID_MULTIPLE_FIELDS: 193 default:
194 // Multiple invalid fields.
127 mEditMessage = mContext.getString(R.string.payments_more_informa tion_required); 195 mEditMessage = mContext.getString(R.string.payments_more_informa tion_required);
128 mEditTitle = mContext.getString(R.string.payments_add_more_infor mation); 196 mEditTitle = mContext.getString(R.string.payments_add_more_infor mation);
129 break; 197 break;
130 default:
131 assert false : "Invalid completion status code";
132 } 198 }
133 } 199 }
134 } 200 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/payments/ContactEditor.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698