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; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 return mIsComplete; | 51 return mIsComplete; |
52 } | 52 } |
53 | 53 |
54 /** @return The autofill profile where this address data lives. */ | 54 /** @return The autofill profile where this address data lives. */ |
55 public AutofillProfile getProfile() { | 55 public AutofillProfile getProfile() { |
56 return mProfile; | 56 return mProfile; |
57 } | 57 } |
58 | 58 |
59 /** | 59 /** |
60 * Updates the address and marks it "complete." Called after the user has ed
ited this address. | 60 * Updates the address and marks it "complete." Called after the user has ed
ited this address. |
61 * Updates the label and sublabel. | 61 * Updates the identifier, label, and sublabel. |
62 * | 62 * |
63 * @param profile The new profile to use. The GUID should not change. | 63 * @param profile The new profile to use. |
64 */ | 64 */ |
65 public void completeAddress(AutofillProfile profile) { | 65 public void completeAddress(AutofillProfile profile) { |
66 assert profile.getGUID().equals(mProfile.getGUID()); | |
67 mProfile = profile; | 66 mProfile = profile; |
68 mIsComplete = true; | 67 mIsComplete = true; |
69 updateLabels(mProfile.getFullName(), mProfile.getLabel()); | 68 updateIdentifierAndLabels(mProfile.getGUID(), mProfile.getFullName(), mP
rofile.getLabel()); |
70 } | 69 } |
71 | 70 |
72 /** @return The country code to use, e.g., when constructing an editor for t
his address. */ | 71 /** @return The country code to use, e.g., when constructing an editor for t
his address. */ |
73 public static String getCountryCode(@Nullable AutofillProfile profile) { | 72 public static String getCountryCode(@Nullable AutofillProfile profile) { |
74 if (sRegionCodePattern == null) sRegionCodePattern = Pattern.compile(REG
ION_CODE_PATTERN); | 73 if (sRegionCodePattern == null) sRegionCodePattern = Pattern.compile(REG
ION_CODE_PATTERN); |
75 | 74 |
76 return profile == null || TextUtils.isEmpty(profile.getCountryCode()) | 75 return profile == null || TextUtils.isEmpty(profile.getCountryCode()) |
77 || !sRegionCodePattern.matcher(profile.getCountryCode())
.matches() | 76 || !sRegionCodePattern.matcher(profile.getCountryCode())
.matches() |
78 ? Locale.getDefault().getCountry() : profile.getCountryCode(); | 77 ? Locale.getDefault().getCountry() : profile.getCountryCode(); |
79 } | 78 } |
(...skipping 29 matching lines...) Expand all Loading... |
109 result.scriptCode = ensureNotNull(matcher.group(SCRIPT_CODE_GROUP)); | 108 result.scriptCode = ensureNotNull(matcher.group(SCRIPT_CODE_GROUP)); |
110 } | 109 } |
111 | 110 |
112 return result; | 111 return result; |
113 } | 112 } |
114 | 113 |
115 private static String ensureNotNull(@Nullable String value) { | 114 private static String ensureNotNull(@Nullable String value) { |
116 return value == null ? "" : value; | 115 return value == null ? "" : value; |
117 } | 116 } |
118 } | 117 } |
OLD | NEW |