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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/payments/ContactEditor.java

Issue 2368073002: PaymentRequest: Add payer name field to payer info editor. (android) (Closed)
Patch Set: PaymentRequest: Add payer name field to payer info editor. (android) Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
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..0fac706861d2a1d9b9edd460691477427df7dc20 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
@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.payments;
import android.telephony.PhoneNumberUtils;
+import android.text.TextUtils;
import android.util.Patterns;
import org.chromium.base.Callback;
@@ -24,8 +25,10 @@ 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 mPhoneValidator;
@@ -34,13 +37,17 @@ public class ContactEditor extends EditorBase<AutofillContact> {
/**
* 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 || !TextUtils.isEmpty(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 (!TextUtils.isEmpty(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.
@@ -81,7 +100,15 @@ 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.payments_name_field_in_contact_details),
+ mPayerNames, null,
+ mContext.getString(R.string.payments_field_required_validation_message),
+ null, contact.getPayerName())
+ : null;
final EditorFieldModel phoneField = mRequestPayerPhone
? EditorFieldModel.createTextInput(EditorFieldModel.INPUT_TYPE_HINT_PHONE,
@@ -104,6 +131,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 +145,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 +165,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);
}
});

Powered by Google App Engine
This is Rietveld 408576698