OLD | NEW |
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.text.TextUtils; | 7 import android.text.TextUtils; |
8 | 8 |
9 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; | 9 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; |
10 import org.chromium.chrome.browser.payments.ui.PaymentOption; | 10 import org.chromium.chrome.browser.payments.ui.PaymentOption; |
11 | 11 |
12 import javax.annotation.Nullable; | 12 import javax.annotation.Nullable; |
13 | 13 |
14 /** | 14 /** |
15 * The locally stored contact details. | 15 * The locally stored contact details. |
16 */ | 16 */ |
17 public class AutofillContact extends PaymentOption { | 17 public class AutofillContact extends PaymentOption { |
18 private final AutofillProfile mProfile; | 18 private final AutofillProfile mProfile; |
| 19 @Nullable private String mPayerName; |
19 @Nullable private String mPayerPhone; | 20 @Nullable private String mPayerPhone; |
20 @Nullable private String mPayerEmail; | 21 @Nullable private String mPayerEmail; |
21 | 22 |
22 /** | 23 /** |
23 * Builds contact details. | 24 * Builds contact details. |
24 * | 25 * |
25 * @param profile The autofill profile where this contact data lives. | 26 * @param profile The autofill profile where this contact data lives. |
26 * @param phone The phone number. If not empty, this will be the primar
y label. | 27 * @param name The payer name. If not empty, this will be the primary
label. |
27 * @param email The email address. If phone is empty, this will be the
primary label. | 28 * @param phone The phone number. If name is empty, this will be the pr
imary label. |
| 29 * @param email The email address. If name and phone are empty, this wi
ll be the primary |
| 30 * label. |
28 * @param isComplete Whether the data in this contact can be sent to the mer
chant as-is. If | 31 * @param isComplete Whether the data in this contact can be sent to the mer
chant as-is. If |
29 * false, user needs to add more information here. | 32 * false, user needs to add more information here. |
30 */ | 33 */ |
31 public AutofillContact(AutofillProfile profile, @Nullable String phone, @Nul
lable String email, | 34 public AutofillContact(AutofillProfile profile, @Nullable String name, |
32 boolean isComplete) { | 35 @Nullable String phone, @Nullable String email, boolean isComplete)
{ |
33 super(profile.getGUID(), null, null, PaymentOption.NO_ICON); | 36 super(profile.getGUID(), null, null, PaymentOption.NO_ICON); |
34 mProfile = profile; | 37 mProfile = profile; |
35 mIsComplete = isComplete; | 38 mIsComplete = isComplete; |
36 setGuidPhoneEmail(profile.getGUID(), phone, email); | 39 setContactInfo(profile.getGUID(), name, phone, email); |
| 40 } |
| 41 |
| 42 /** @return Payer name. Null if the merchant did not request it or data is i
ncomplete. */ |
| 43 @Nullable public String getPayerName() { |
| 44 return mPayerName; |
37 } | 45 } |
38 | 46 |
39 /** @return Email address. Null if the merchant did not request it or data i
s incomplete. */ | 47 /** @return Email address. Null if the merchant did not request it or data i
s incomplete. */ |
40 @Nullable public String getPayerEmail() { | 48 @Nullable public String getPayerEmail() { |
41 return mPayerEmail; | 49 return mPayerEmail; |
42 } | 50 } |
43 | 51 |
44 /** @return Phone number. Null if the merchant did not request it or data is
incomplete. */ | 52 /** @return Phone number. Null if the merchant did not request it or data is
incomplete. */ |
45 @Nullable public String getPayerPhone() { | 53 @Nullable public String getPayerPhone() { |
46 return mPayerPhone; | 54 return mPayerPhone; |
47 } | 55 } |
48 | 56 |
49 /** @return The autofill profile where this contact data lives. */ | 57 /** @return The autofill profile where this contact data lives. */ |
50 public AutofillProfile getProfile() { | 58 public AutofillProfile getProfile() { |
51 return mProfile; | 59 return mProfile; |
52 } | 60 } |
53 | 61 |
54 /** | 62 /** |
55 * Updates the profile guid, email address, and phone number and marks this
information | 63 * Updates the profile guid, payer name, email address, and phone number and
marks this |
56 * "complete." Called after the user has edited this contact information. Up
dates the | 64 * information "complete." Called after the user has edited this contact inf
ormation. |
57 * identifier, label, and sublabel. | 65 * Update the identifier, label, sublabel, and tertiarylabel. |
58 * | 66 * |
59 * @param guid The new identifier to use. Should not be null or empty. | 67 * @param guid The new identifier to use. Should not be null or empty. |
60 * @param phone The new phone number to use. If not empty, this will be the
primary label. | 68 * @param name The new payer name to use. If not empty, this will be the pr
imary label. |
61 * @param email The new email address to use. If phone is empty, this will b
e the primary label. | 69 * @param phone The new phone number to use. If name is empty, this will be
the primary label. |
| 70 * @param email The new email address to use. If email and phone are empty,
this will be the |
| 71 * primary label. |
62 */ | 72 */ |
63 public void completeContact(String guid, @Nullable String phone, @Nullable S
tring email) { | 73 public void completeContact(String guid, @Nullable String name, |
| 74 @Nullable String phone, @Nullable String email) { |
64 mIsComplete = true; | 75 mIsComplete = true; |
65 setGuidPhoneEmail(guid, phone, email); | 76 setContactInfo(guid, name, phone, email); |
66 } | 77 } |
67 | 78 |
68 private void setGuidPhoneEmail(String guid, @Nullable String phone, @Nullabl
e String email) { | 79 private void setContactInfo(String guid, @Nullable String name, |
| 80 @Nullable String phone, @Nullable String email) { |
| 81 mPayerName = TextUtils.isEmpty(name) ? null : name; |
69 mPayerPhone = TextUtils.isEmpty(phone) ? null : phone; | 82 mPayerPhone = TextUtils.isEmpty(phone) ? null : phone; |
70 mPayerEmail = TextUtils.isEmpty(email) ? null : email; | 83 mPayerEmail = TextUtils.isEmpty(email) ? null : email; |
71 updateIdentifierAndLabels(guid, mPayerPhone == null ? mPayerEmail : mPay
erPhone, | 84 |
72 mPayerPhone == null ? null : mPayerEmail); | 85 if (mPayerName == null) { |
| 86 updateIdentifierAndLabels(guid, mPayerPhone == null ? mPayerEmail :
mPayerPhone, |
| 87 mPayerPhone == null ? null : mPayerEmail); |
| 88 } else { |
| 89 updateIdentifierAndLabels(guid, mPayerName, |
| 90 mPayerPhone == null ? mPayerEmail : mPayerPhone, |
| 91 mPayerPhone == null ? null : mPayerEmail); |
| 92 } |
73 } | 93 } |
74 } | 94 } |
OLD | NEW |