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

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

Issue 2549073004: Update order summary total when instruments change. (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
index c1cefc3ccc8aaa3622982b1538ab2e9a4c7143b2..67c7e4f215a9690857478849654772026775ca39 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
@@ -63,6 +63,8 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
+import javax.annotation.Nullable;
+
/**
* Android implementation of the PaymentRequest service defined in
* components/payments/payment_request.mojom.
@@ -644,18 +646,31 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
if (mPaymentMethodsSection == null) return;
for (int i = 0; i < mPaymentMethodsSection.getSize(); i++) {
- PaymentOption option = mPaymentMethodsSection.getItem(i);
- assert option instanceof PaymentInstrument;
- PaymentInstrument instrument = (PaymentInstrument) option;
- Set<String> methodNames = instrument.getInstrumentMethodNames();
- methodNames.retainAll(mModifiedTotals.keySet());
- PaymentItem modifiedTotal = methodNames.isEmpty()
- ? null
- : mModifiedTotals.get(methodNames.iterator().next());
- instrument.setModifiedTotal(modifiedTotal == null
- ? null
- : mFormatter.format(modifiedTotal.amount.value));
+ PaymentInstrument instrument = (PaymentInstrument) mPaymentMethodsSection.getItem(i);
+ PaymentItem modifiedTotal = getModifiedTotal(instrument);
+ instrument.setModifiedTotal(
+ modifiedTotal == null ? null : mFormatter.format(modifiedTotal.amount.value));
}
+
+ updateOrderSummaryTotal((PaymentInstrument) mPaymentMethodsSection.getSelectedItem());
+ }
+
+ private void updateOrderSummaryTotal(@Nullable PaymentInstrument instrument) {
+ if (!ChromeFeatureList.isEnabled(ChromeFeatureList.WEB_PAYMENTS_MODIFIERS)) return;
+
+ PaymentItem total = getModifiedTotal(instrument);
+ if (total == null) total = mRawTotal;
+
+ mUiShoppingCart.setTotal(new LineItem(total.label, mFormatter.getFormattedCurrencyCode(),
+ mFormatter.format(total.amount.value), false /* isPending */));
+ mUI.updateOrderSummarySection(mUiShoppingCart);
+ }
+
+ @Nullable private PaymentItem getModifiedTotal(@Nullable PaymentInstrument instrument) {
+ if (instrument == null) return null;
+ Set<String> methodNames = instrument.getInstrumentMethodNames();
+ methodNames.retainAll(mModifiedTotals.keySet());
+ return methodNames.isEmpty() ? null : mModifiedTotals.get(methodNames.iterator().next());
}
/**
@@ -829,6 +844,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
}
}
+ updateOrderSummaryTotal((PaymentInstrument) option);
mPaymentMethodsSection.setSelectedItem(option);
}
@@ -953,6 +969,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
mPaymentMethodsSection.addAndSelectItem(completeCard);
}
+ updateInstrumentModifiedTotals();
mUI.updateSection(PaymentRequestUI.TYPE_PAYMENT_METHODS, mPaymentMethodsSection);
}
});
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698