| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.chrome.browser.payments; | |
| 6 | |
| 7 import android.text.TextUtils; | |
| 8 | |
| 9 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; | |
| 10 import org.chromium.chrome.browser.payments.ui.PaymentOption; | |
| 11 | |
| 12 import javax.annotation.Nullable; | |
| 13 | |
| 14 /** | |
| 15 * The locally stored contact details. | |
| 16 */ | |
| 17 public class AutofillContact extends PaymentOption { | |
| 18 private final AutofillProfile mProfile; | |
| 19 @Nullable private String mPayerPhone; | |
| 20 @Nullable private String mPayerEmail; | |
| 21 | |
| 22 /** | |
| 23 * Builds contact details. | |
| 24 * | |
| 25 * @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 email The email address. If phone is empty, this will be the
primary label. | |
| 28 * @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. | |
| 30 */ | |
| 31 public AutofillContact(AutofillProfile profile, @Nullable String phone, @Nul
lable String email, | |
| 32 boolean isComplete) { | |
| 33 super(profile.getGUID(), null, null, PaymentOption.NO_ICON); | |
| 34 mProfile = profile; | |
| 35 mIsComplete = isComplete; | |
| 36 setGuidPhoneEmail(profile.getGUID(), phone, email); | |
| 37 } | |
| 38 | |
| 39 /** @return Email address. Null if the merchant did not request it or data i
s incomplete. */ | |
| 40 @Nullable public String getPayerEmail() { | |
| 41 return mPayerEmail; | |
| 42 } | |
| 43 | |
| 44 /** @return Phone number. Null if the merchant did not request it or data is
incomplete. */ | |
| 45 @Nullable public String getPayerPhone() { | |
| 46 return mPayerPhone; | |
| 47 } | |
| 48 | |
| 49 /** @return The autofill profile where this contact data lives. */ | |
| 50 public AutofillProfile getProfile() { | |
| 51 return mProfile; | |
| 52 } | |
| 53 | |
| 54 /** | |
| 55 * Updates the profile guid, email address, and phone number and marks this
information | |
| 56 * "complete." Called after the user has edited this contact information. Up
dates the | |
| 57 * identifier, label, and sublabel. | |
| 58 * | |
| 59 * @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. | |
| 61 * @param email The new email address to use. If phone is empty, this will b
e the primary label. | |
| 62 */ | |
| 63 public void completeContact(String guid, @Nullable String phone, @Nullable S
tring email) { | |
| 64 mIsComplete = true; | |
| 65 setGuidPhoneEmail(guid, phone, email); | |
| 66 } | |
| 67 | |
| 68 private void setGuidPhoneEmail(String guid, @Nullable String phone, @Nullabl
e String email) { | |
| 69 mPayerPhone = TextUtils.isEmpty(phone) ? null : phone; | |
| 70 mPayerEmail = TextUtils.isEmpty(email) ? null : email; | |
| 71 updateIdentifierAndLabels(guid, mPayerPhone == null ? mPayerEmail : mPay
erPhone, | |
| 72 mPayerPhone == null ? null : mPayerEmail); | |
| 73 } | |
| 74 } | |
| OLD | NEW |