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

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

Issue 2413833002: PaymentRequest: Rename ContactInfo to PayerInfo.
Patch Set: test 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 unified diff | Download patch
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.telephony.PhoneNumberUtils; 7 import android.telephony.PhoneNumberUtils;
8 import android.util.Patterns; 8 import android.util.Patterns;
9 9
10 import org.chromium.base.Callback; 10 import org.chromium.base.Callback;
11 import org.chromium.chrome.R; 11 import org.chromium.chrome.R;
12 import org.chromium.chrome.browser.autofill.PersonalDataManager; 12 import org.chromium.chrome.browser.autofill.PersonalDataManager;
13 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; 13 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile;
14 import org.chromium.chrome.browser.payments.ui.EditorFieldModel; 14 import org.chromium.chrome.browser.payments.ui.EditorFieldModel;
15 import org.chromium.chrome.browser.payments.ui.EditorFieldModel.EditorFieldValid ator; 15 import org.chromium.chrome.browser.payments.ui.EditorFieldModel.EditorFieldValid ator;
16 import org.chromium.chrome.browser.payments.ui.EditorModel; 16 import org.chromium.chrome.browser.payments.ui.EditorModel;
17 17
18 import java.util.HashSet; 18 import java.util.HashSet;
19 import java.util.Set; 19 import java.util.Set;
20 20
21 import javax.annotation.Nullable; 21 import javax.annotation.Nullable;
22 22
23 /** 23 /**
24 * Contact information editor. 24 * Payer information editor.
25 */ 25 */
26 public class ContactEditor extends EditorBase<AutofillContact> { 26 public class PayerInfoEditor extends EditorBase<AutofillPayerInfo> {
27 private final boolean mRequestPayerPhone; 27 private final boolean mRequestPayerPhone;
28 private final boolean mRequestPayerEmail; 28 private final boolean mRequestPayerEmail;
29 private final Set<CharSequence> mPhoneNumbers; 29 private final Set<CharSequence> mPhoneNumbers;
30 private final Set<CharSequence> mEmailAddresses; 30 private final Set<CharSequence> mEmailAddresses;
31 @Nullable private EditorFieldValidator mPhoneValidator; 31 @Nullable private EditorFieldValidator mPhoneValidator;
32 @Nullable private EditorFieldValidator mEmailValidator; 32 @Nullable private EditorFieldValidator mEmailValidator;
33 33
34 /** 34 /**
35 * Builds a contact information editor. 35 * Builds a payer information editor.
36 * 36 *
37 * @param requestPayerPhone Whether to request the user's phone number. 37 * @param requestPayerPhone Whether to request the user's phone number.
38 * @param requestPayerEmail Whether to request the user's email address. 38 * @param requestPayerEmail Whether to request the user's email address.
39 */ 39 */
40 public ContactEditor(boolean requestPayerPhone, boolean requestPayerEmail) { 40 public PayerInfoEditor(boolean requestPayerPhone, boolean requestPayerEmail) {
41 assert requestPayerPhone || requestPayerEmail; 41 assert requestPayerPhone || requestPayerEmail;
42 mRequestPayerPhone = requestPayerPhone; 42 mRequestPayerPhone = requestPayerPhone;
43 mRequestPayerEmail = requestPayerEmail; 43 mRequestPayerEmail = requestPayerEmail;
44 mPhoneNumbers = new HashSet<>(); 44 mPhoneNumbers = new HashSet<>();
45 mEmailAddresses = new HashSet<>(); 45 mEmailAddresses = new HashSet<>();
46 } 46 }
47 47
48 /** 48 /**
49 * Returns whether the following contact information can be sent to the merc hant as-is without 49 * Returns whether the following payer information can be sent to the mercha nt as-is without
50 * editing first. 50 * editing first.
51 * 51 *
52 * @param phone The phone number to check. 52 * @param phone The phone number to check.
53 * @param email The email address to check. 53 * @param email The email address to check.
54 * @return Whether the contact information is complete. 54 * @return Whether the payer information is complete.
55 */ 55 */
56 public boolean isContactInformationComplete(@Nullable String phone, @Nullabl e String email) { 56 public boolean isPayerInformationComplete(@Nullable String phone, @Nullable String email) {
57 return (!mRequestPayerPhone || getPhoneValidator().isValid(phone)) 57 return (!mRequestPayerPhone || getPhoneValidator().isValid(phone))
58 && (!mRequestPayerEmail || getEmailValidator().isValid(email)); 58 && (!mRequestPayerEmail || getEmailValidator().isValid(email));
59 } 59 }
60 60
61 /** 61 /**
62 * Adds the given phone number to the autocomplete set, if it's valid. 62 * Adds the given phone number to the autocomplete set, if it's valid.
63 * 63 *
64 * @param phoneNumber The phone number to possibly add. 64 * @param phoneNumber The phone number to possibly add.
65 */ 65 */
66 public void addPhoneNumberIfValid(@Nullable CharSequence phoneNumber) { 66 public void addPhoneNumberIfValid(@Nullable CharSequence phoneNumber) {
67 if (getPhoneValidator().isValid(phoneNumber)) mPhoneNumbers.add(phoneNum ber); 67 if (getPhoneValidator().isValid(phoneNumber)) mPhoneNumbers.add(phoneNum ber);
68 } 68 }
69 69
70 /** 70 /**
71 * Adds the given email address to the autocomplete set, if it's valid. 71 * Adds the given email address to the autocomplete set, if it's valid.
72 * 72 *
73 * @param emailAddress The email address to possibly add. 73 * @param emailAddress The email address to possibly add.
74 */ 74 */
75 public void addEmailAddressIfValid(@Nullable CharSequence emailAddress) { 75 public void addEmailAddressIfValid(@Nullable CharSequence emailAddress) {
76 if (getEmailValidator().isValid(emailAddress)) mEmailAddresses.add(email Address); 76 if (getEmailValidator().isValid(emailAddress)) mEmailAddresses.add(email Address);
77 } 77 }
78 78
79 @Override 79 @Override
80 public void edit(@Nullable AutofillContact toEdit, final Callback<AutofillCo ntact> callback) { 80 public void edit(
81 @Nullable AutofillPayerInfo toEdit, final Callback<AutofillPayerInfo > callback) {
81 super.edit(toEdit, callback); 82 super.edit(toEdit, callback);
82 83
83 final AutofillContact contact = toEdit == null 84 final AutofillPayerInfo payerInfo = toEdit == null
84 ? new AutofillContact(new AutofillProfile(), null, null, false) : toEdit; 85 ? new AutofillPayerInfo(new AutofillProfile(), null, null, false ) : toEdit;
85 86
86 final EditorFieldModel phoneField = mRequestPayerPhone 87 final EditorFieldModel phoneField = mRequestPayerPhone
87 ? EditorFieldModel.createTextInput(EditorFieldModel.INPUT_TYPE_H INT_PHONE, 88 ? EditorFieldModel.createTextInput(EditorFieldModel.INPUT_TYPE_H INT_PHONE,
88 mContext.getString(R.string.autofill_profile_editor_ph one_number), 89 mContext.getString(R.string.autofill_profile_editor_ph one_number),
89 mPhoneNumbers, getPhoneValidator(), 90 mPhoneNumbers, getPhoneValidator(),
90 mContext.getString(R.string.payments_field_required_va lidation_message), 91 mContext.getString(R.string.payments_field_required_va lidation_message),
91 mContext.getString(R.string.payments_phone_invalid_val idation_message), 92 mContext.getString(R.string.payments_phone_invalid_val idation_message),
92 contact.getPayerPhone()) 93 payerInfo.getPayerPhone())
93 : null; 94 : null;
94 95
95 final EditorFieldModel emailField = mRequestPayerEmail 96 final EditorFieldModel emailField = mRequestPayerEmail
96 ? EditorFieldModel.createTextInput(EditorFieldModel.INPUT_TYPE_H INT_EMAIL, 97 ? EditorFieldModel.createTextInput(EditorFieldModel.INPUT_TYPE_H INT_EMAIL,
97 mContext.getString(R.string.autofill_profile_editor_em ail_address), 98 mContext.getString(R.string.autofill_profile_editor_em ail_address),
98 mEmailAddresses, getEmailValidator(), 99 mEmailAddresses, getEmailValidator(),
99 mContext.getString(R.string.payments_field_required_va lidation_message), 100 mContext.getString(R.string.payments_field_required_va lidation_message),
100 mContext.getString(R.string.payments_email_invalid_val idation_message), 101 mContext.getString(R.string.payments_email_invalid_val idation_message),
101 contact.getPayerEmail()) 102 payerInfo.getPayerEmail())
102 : null; 103 : null;
103 104
104 EditorModel editor = new EditorModel( 105 EditorModel editor = new EditorModel(mContext.getString(toEdit == null
105 mContext.getString(toEdit == null ? R.string.payments_add_contac t_details_label 106 ? R.string.payments_add_payer_info_details_label
106 : R.string.payments_edit_conta ct_details_label)); 107 : R.string.payments_edit_payer_info_details_label));
107 if (phoneField != null) editor.addField(phoneField); 108 if (phoneField != null) editor.addField(phoneField);
108 if (emailField != null) editor.addField(emailField); 109 if (emailField != null) editor.addField(emailField);
109 110
110 editor.setCancelCallback(new Runnable() { 111 editor.setCancelCallback(new Runnable() {
111 @Override 112 @Override
112 public void run() { 113 public void run() {
113 callback.onResult(null); 114 callback.onResult(null);
114 } 115 }
115 }); 116 });
116 117
117 editor.setDoneCallback(new Runnable() { 118 editor.setDoneCallback(new Runnable() {
118 @Override 119 @Override
119 public void run() { 120 public void run() {
120 String phone = null; 121 String phone = null;
121 String email = null; 122 String email = null;
122 123
123 if (phoneField != null) { 124 if (phoneField != null) {
124 phone = phoneField.getValue().toString(); 125 phone = phoneField.getValue().toString();
125 contact.getProfile().setPhoneNumber(phone); 126 payerInfo.getProfile().setPhoneNumber(phone);
126 } 127 }
127 128
128 if (emailField != null) { 129 if (emailField != null) {
129 email = emailField.getValue().toString(); 130 email = emailField.getValue().toString();
130 contact.getProfile().setEmailAddress(email); 131 payerInfo.getProfile().setEmailAddress(email);
131 } 132 }
132 133
133 String guid = PersonalDataManager.getInstance().setProfile(conta ct.getProfile()); 134 String guid = PersonalDataManager.getInstance().setProfile(payer Info.getProfile());
134 contact.completeContact(guid, phone, email); 135 payerInfo.completePayerInfo(guid, phone, email);
135 callback.onResult(contact); 136 callback.onResult(payerInfo);
136 } 137 }
137 }); 138 });
138 139
139 mEditorView.show(editor); 140 mEditorView.show(editor);
140 } 141 }
141 142
142 private EditorFieldValidator getPhoneValidator() { 143 private EditorFieldValidator getPhoneValidator() {
143 if (mPhoneValidator == null) { 144 if (mPhoneValidator == null) {
144 mPhoneValidator = new EditorFieldValidator() { 145 mPhoneValidator = new EditorFieldValidator() {
145 @Override 146 @Override
(...skipping 12 matching lines...) Expand all
158 mEmailValidator = new EditorFieldValidator() { 159 mEmailValidator = new EditorFieldValidator() {
159 @Override 160 @Override
160 public boolean isValid(@Nullable CharSequence value) { 161 public boolean isValid(@Nullable CharSequence value) {
161 return value != null && Patterns.EMAIL_ADDRESS.matcher(value ).matches(); 162 return value != null && Patterns.EMAIL_ADDRESS.matcher(value ).matches();
162 } 163 }
163 }; 164 };
164 } 165 }
165 return mEmailValidator; 166 return mEmailValidator;
166 } 167 }
167 } 168 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698