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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/payments/CardEditor.java

Issue 2507523002: [Payments] Order billing addresses by frecency. (Closed)
Patch Set: Addressed comment Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/payments/CardEditor.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/CardEditor.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/CardEditor.java
index b929faa5e8a119f44773ef3358ba04671a7cd3ec..5c377534ca55b24ea99d30f6bc093cc9c3f39f17 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/payments/CardEditor.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/CardEditor.java
@@ -77,11 +77,11 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument>
private final WebContents mWebContents;
/**
- * The map from GUIDs to profiles that can be used for billing address. This cache avoids
- * re-reading profiles from disk, which may have changed due to sync, for example.
- * updateBillingAddress() updates this cache.
+ * The list of profiles that can be used for billing address. This cache avoids re-reading
+ * profiles from disk, which may have changed due to sync, for example. updateBillingAddress()
+ * updates this cache.
*/
- private final Map<String, AutofillProfile> mProfilesForBillingAddress;
+ private final List<AutofillProfile> mProfilesForBillingAddress;
/** Used for verifying billing address completeness and also editing billing addresses. */
private final AddressEditor mAddressEditor;
@@ -146,7 +146,7 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument>
List<AutofillProfile> profiles =
PersonalDataManager.getInstance().getBillingAddressesToSuggest();
- mProfilesForBillingAddress = new HashMap<>();
+ mProfilesForBillingAddress = new ArrayList<>();
for (int i = 0; i < profiles.size(); i++) {
AutofillProfile profile = profiles.get(i);
// 1) Include only local profiles, because GUIDs of server profiles change on every
@@ -156,7 +156,7 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument>
if (profile.getIsLocal()
&& AutofillAddress.checkAddressCompletionStatus(profile)
== AutofillAddress.COMPLETE) {
- mProfilesForBillingAddress.put(profile.getGUID(), profile);
+ mProfilesForBillingAddress.add(profile);
}
}
@@ -305,8 +305,13 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument>
@Override
public void run() {
commitChanges(card, isNewCard);
- instrument.completeInstrument(
- card, mProfilesForBillingAddress.get(card.getBillingAddressId()));
+ for (int i = 0; i < mProfilesForBillingAddress.size(); ++i) {
+ if (TextUtils.equals(mProfilesForBillingAddress.get(i).getGUID(),
+ card.getBillingAddressId())) {
+ instrument.completeInstrument(card, mProfilesForBillingAddress.get(i));
+ break;
+ }
+ }
callback.onResult(instrument);
}
});
@@ -323,7 +328,14 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument>
*/
public void updateBillingAddressIfComplete(AutofillAddress billingAddress) {
if (!billingAddress.isComplete()) return;
- mProfilesForBillingAddress.put(billingAddress.getIdentifier(), billingAddress.getProfile());
+
+ for (int i = 0; i < mProfilesForBillingAddress.size(); ++i) {
+ if (TextUtils.equals(mProfilesForBillingAddress.get(i).getGUID(),
+ billingAddress.getIdentifier())) {
+ mProfilesForBillingAddress.set(i, billingAddress.getProfile());
+ return;
+ }
+ }
}
/**
@@ -504,10 +516,9 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument>
private void addBillingAddressDropdown(EditorModel editor, final CreditCard card) {
final List<DropdownKeyValue> billingAddresses = new ArrayList<>();
- for (Map.Entry<String, AutofillProfile> address : mProfilesForBillingAddress.entrySet()) {
- // Key is profile GUID. Value is profile label.
- billingAddresses.add(
- new DropdownKeyValue(address.getKey(), address.getValue().getLabel()));
+ for (int i = 0; i < mProfilesForBillingAddress.size(); ++i) {
+ billingAddresses.add(new DropdownKeyValue(mProfilesForBillingAddress.get(i).getGUID(),
+ mProfilesForBillingAddress.get(i).getLabel()));
}
billingAddresses.add(new DropdownKeyValue(BILLING_ADDRESS_ADD_NEW,
@@ -541,11 +552,11 @@ public class CardEditor extends EditorBase<AutofillPaymentInstrument>
mBillingAddressField.setValue(null);
} else {
// User has added a new complete address. Add it to the top of the
- // dropdown, under the "Select" prompt.
- mProfilesForBillingAddress.put(
- billingAddress.getIdentifier(), billingAddress.getProfile());
- billingAddresses.add(1, new DropdownKeyValue(
- billingAddress.getIdentifier(), billingAddress.getSublabel()));
+ // dropdown.
+ mProfilesForBillingAddress.add(billingAddress.getProfile());
+ billingAddresses.add(
+ 0, new DropdownKeyValue(billingAddress.getIdentifier(),
+ billingAddress.getSublabel()));
mBillingAddressField.setDropdownKeyValues(billingAddresses);
mBillingAddressField.setValue(billingAddress.getIdentifier());
}

Powered by Google App Engine
This is Rietveld 408576698