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

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

Issue 2093363002: Autofill address editor in PaymentRequest UI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@contact-editor
Patch Set: Created 4 years, 5 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.content.Context;
8 import android.telephony.PhoneNumberUtils; 7 import android.telephony.PhoneNumberUtils;
9 import android.util.Patterns; 8 import android.util.Patterns;
10 9
11 import org.chromium.base.Callback; 10 import org.chromium.base.Callback;
12 import org.chromium.chrome.R; 11 import org.chromium.chrome.R;
13 import org.chromium.chrome.browser.autofill.PersonalDataManager; 12 import org.chromium.chrome.browser.autofill.PersonalDataManager;
14 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; 13 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile;
15 import org.chromium.chrome.browser.payments.ui.EditorFieldModel; 14 import org.chromium.chrome.browser.payments.ui.EditorFieldModel;
16 import org.chromium.chrome.browser.payments.ui.EditorFieldModel.EditorFieldValid ator; 15 import org.chromium.chrome.browser.payments.ui.EditorFieldModel.EditorFieldValid ator;
17 import org.chromium.chrome.browser.payments.ui.EditorModel; 16 import org.chromium.chrome.browser.payments.ui.EditorModel;
18 import org.chromium.chrome.browser.payments.ui.EditorView;
19 17
20 import java.util.ArrayList; 18 import java.util.ArrayList;
21 import java.util.List; 19 import java.util.List;
22 20
23 import javax.annotation.Nullable; 21 import javax.annotation.Nullable;
24 22
25 /** 23 /**
26 * Contact information editor. 24 * Contact information editor.
27 */ 25 */
28 public class ContactEditor { 26 public class ContactEditor extends EditorBase<AutofillContact> {
29 private final boolean mRequestPayerPhone; 27 private final boolean mRequestPayerPhone;
30 private final boolean mRequestPayerEmail; 28 private final boolean mRequestPayerEmail;
31 private final List<CharSequence> mAllPhoneNumbers; 29 private final List<CharSequence> mAllPhoneNumbers;
32 private final List<CharSequence> mAllEmailAddresses; 30 private final List<CharSequence> mAllEmailAddresses;
33 @Nullable private EditorView mEditorView;
34 @Nullable private Context mContext;
35 @Nullable private EditorFieldValidator mPhoneValidator; 31 @Nullable private EditorFieldValidator mPhoneValidator;
36 @Nullable private EditorFieldValidator mEmailValidator; 32 @Nullable private EditorFieldValidator mEmailValidator;
37 33
38 /** 34 /**
39 * Builds a contact information editor. 35 * Builds a contact information editor.
40 * 36 *
41 * @param requestPayerPhone Whether to request the user's phone number. 37 * @param requestPayerPhone Whether to request the user's phone number.
42 * @param requestPayerEmail Whether to request the user's email address. 38 * @param requestPayerEmail Whether to request the user's email address.
43 */ 39 */
44 public ContactEditor(boolean requestPayerPhone, boolean requestPayerEmail) { 40 public ContactEditor(boolean requestPayerPhone, boolean requestPayerEmail) {
(...skipping 11 matching lines...) Expand all
56 * @param phone The phone number to check. 52 * @param phone The phone number to check.
57 * @param email The email address to check. 53 * @param email The email address to check.
58 * @return Whether the contact information is complete. 54 * @return Whether the contact information is complete.
59 */ 55 */
60 public boolean isContactInformationComplete(@Nullable String phone, @Nullabl e String email) { 56 public boolean isContactInformationComplete(@Nullable String phone, @Nullabl e String email) {
61 return (!mRequestPayerPhone || getPhoneValidator().isValid(phone)) 57 return (!mRequestPayerPhone || getPhoneValidator().isValid(phone))
62 && (!mRequestPayerEmail || getEmailValidator().isValid(email)); 58 && (!mRequestPayerEmail || getEmailValidator().isValid(email));
63 } 59 }
64 60
65 /** 61 /**
66 * Sets the user interface to be used for editing contact information.
67 *
68 * @param editorView The user interface to be used.
69 */
70 public void setEditorView(EditorView editorView) {
71 assert editorView != null;
72 mEditorView = editorView;
73 mContext = mEditorView.getContext();
74 }
75
76 /**
77 * Adds the given phone number to the autocomplete list, if it's valid. 62 * Adds the given phone number to the autocomplete list, if it's valid.
78 * 63 *
79 * @param phoneNumber The phone number to possibly add. 64 * @param phoneNumber The phone number to possibly add.
80 */ 65 */
81 public void addPhoneNumberIfValid(@Nullable CharSequence phoneNumber) { 66 public void addPhoneNumberIfValid(@Nullable CharSequence phoneNumber) {
82 if (getPhoneValidator().isValid(phoneNumber)) mAllPhoneNumbers.add(phone Number); 67 if (getPhoneValidator().isValid(phoneNumber)) mAllPhoneNumbers.add(phone Number);
83 } 68 }
84 69
85 /** 70 /**
86 * Adds the given email address to the autocomplete list, if it's valid. 71 * Adds the given email address to the autocomplete list, if it's valid.
87 * 72 *
88 * @param emailAddress The email address to possibly add. 73 * @param emailAddress The email address to possibly add.
89 */ 74 */
90 public void addEmailAddressIfValid(@Nullable CharSequence emailAddress) { 75 public void addEmailAddressIfValid(@Nullable CharSequence emailAddress) {
91 if (getEmailValidator().isValid(emailAddress)) mAllEmailAddresses.add(em ailAddress); 76 if (getEmailValidator().isValid(emailAddress)) mAllEmailAddresses.add(em ailAddress);
92 } 77 }
93 78
94 /** 79 @Override
95 * Shows the user interface for editing the given contact. The contact is al so updated on disk, 80 public void edit(@Nullable AutofillContact toEdit, final Callback<AutofillCo ntact> callback) {
96 * so there's no need to do that in the calling code. 81 super.edit(toEdit, callback);
97 *
98 * @param toEdit The contact to edit. Can be null if the user is adding a new contact instead
99 * of editing an existing one.
100 * @param callback The callback to invoke with the complete and valid contac t information. Can
101 * be invoked with null if the user clicked Cancel.
102 */
103 public void editContact(
104 @Nullable AutofillContact toEdit, final Callback<AutofillContact> ca llback) {
105 assert mEditorView != null;
106 assert mContext != null;
107 82
108 final AutofillContact contact = toEdit == null 83 final AutofillContact contact = toEdit == null
109 ? new AutofillContact(new AutofillProfile(), null, null, false) : toEdit; 84 ? new AutofillContact(new AutofillProfile(), null, null, false) : toEdit;
110 85
111 final EditorFieldModel phoneField = mRequestPayerPhone 86 final EditorFieldModel phoneField = mRequestPayerPhone
112 ? new EditorFieldModel(EditorFieldModel.INPUT_TYPE_HINT_PHONE, 87 ? new EditorFieldModel(EditorFieldModel.INPUT_TYPE_HINT_PHONE,
113 mContext.getString(R.string.autofill_profile_editor_ph one_number), 88 mContext.getString(R.string.autofill_profile_editor_ph one_number),
114 mAllPhoneNumbers, getPhoneValidator(), 89 mAllPhoneNumbers, getPhoneValidator(),
115 mContext.getString(R.string.payments_phone_required_va lidation_message), 90 mContext.getString(R.string.payments_phone_required_va lidation_message),
116 mContext.getString(R.string.payments_phone_invalid_val idation_message), 91 mContext.getString(R.string.payments_phone_invalid_val idation_message),
117 contact.getPayerPhone()) 92 contact.getPayerPhone())
118 : null; 93 : null;
119 94
120 final EditorFieldModel emailField = mRequestPayerEmail 95 final EditorFieldModel emailField = mRequestPayerEmail
121 ? new EditorFieldModel(EditorFieldModel.INPUT_TYPE_HINT_EMAIL, 96 ? new EditorFieldModel(EditorFieldModel.INPUT_TYPE_HINT_EMAIL,
122 mContext.getString(R.string.autofill_profile_editor_em ail_address), 97 mContext.getString(R.string.autofill_profile_editor_em ail_address),
123 mAllEmailAddresses, getEmailValidator(), 98 mAllEmailAddresses, getEmailValidator(),
124 mContext.getString(R.string.payments_email_required_va lidation_message), 99 mContext.getString(R.string.payments_email_required_va lidation_message),
125 mContext.getString(R.string.payments_email_invalid_val idation_message), 100 mContext.getString(R.string.payments_email_invalid_val idation_message),
126 contact.getPayerEmail()) 101 contact.getPayerEmail())
127 : null; 102 : null;
128 103
129 EditorModel editor = 104 EditorModel editor = new EditorModel(
130 new EditorModel(mContext.getString(R.string.payments_add_contact _details_label)); 105 mContext.getString(toEdit == null ? R.string.payments_add_contac t_details_label
106 : R.string.payments_edit_conta ct_details_label));
131 if (phoneField != null) editor.addField(phoneField); 107 if (phoneField != null) editor.addField(phoneField);
132 if (emailField != null) editor.addField(emailField); 108 if (emailField != null) editor.addField(emailField);
133 109
134 editor.setCancelCallback(new Runnable() { 110 editor.setCancelCallback(new Runnable() {
135 @Override 111 @Override
136 public void run() { 112 public void run() {
137 callback.onResult(null); 113 callback.onResult(null);
138 } 114 }
139 }); 115 });
140 116
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 mEmailValidator = new EditorFieldValidator() { 158 mEmailValidator = new EditorFieldValidator() {
183 @Override 159 @Override
184 public boolean isValid(@Nullable CharSequence value) { 160 public boolean isValid(@Nullable CharSequence value) {
185 return value != null && Patterns.EMAIL_ADDRESS.matcher(value ).matches(); 161 return value != null && Patterns.EMAIL_ADDRESS.matcher(value ).matches();
186 } 162 }
187 }; 163 };
188 } 164 }
189 return mEmailValidator; 165 return mEmailValidator;
190 } 166 }
191 } 167 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698