Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestUI.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestUI.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestUI.java |
| index 07be71b7c286f919ddffa3d240958f6bc3d70d57..afe82aabb50ebaf85c298cbaebd002ea179ccaf6 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestUI.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestUI.java |
| @@ -95,12 +95,23 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View |
| @DataType int optionType, Callback<SectionInformation> callback); |
| /** |
| - * Called when the user changes one of their payment options. |
| + * Called when the user changes one of their payment options. This method returns true if |
| + * this section should be disabled and show a spinner while it's being checked. If this |
| + * method returns true, then the checkedCallback will be invoked with the results of the |
| + * check and updated information. |
| * |
| - * @param optionType Data being updated. |
| - * @param option Value of the data being updated. |
| + * For example, if the website needs a shipping address to calculate shipping options, then |
| + * calling onSectionOptionChanged(TYPE_SHIPPING_ADDRESS, option, checkedCallback) will |
| + * return true. When the website updates the shipping options, the checkedCallback will be |
| + * invoked. |
| + * |
| + * @param optionType Data being updated. |
| + * @param option Value of the data being updated. |
| + * @param checkedCallback The callback after an asynchronous check has completed. |
| + * @return True if the option needs to be asynchronously checked. |
| */ |
| - void onSectionOptionChanged(@DataType int optionType, PaymentOption option); |
| + boolean onSectionOptionChanged(@DataType int optionType, PaymentOption option, |
| + Callback<PaymentInformation> checkedCallback); |
| /** |
| * Called when the user clicks on the "Add" button for a section. |
| @@ -192,6 +203,7 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View |
| private ViewGroup mSelectedSection; |
| private boolean mIsShowingEditDialog; |
| private boolean mIsClientClosing; |
| + private boolean mIsClientCheckingSelection; |
| private ShoppingCart mShoppingCart; |
| private SectionInformation mPaymentMethodSectionInformation; |
| @@ -267,7 +279,7 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View |
| mClient.getDefaultPaymentInformation(new Callback<PaymentInformation>() { |
| @Override |
| public void onResult(PaymentInformation result) { |
| - updateOrderSummarySection(new ShoppingCart(result.getTotal(), null)); |
| + updateOrderSummarySection(result.getShoppingCart()); |
| if (mRequestShipping) { |
| updateSection(TYPE_SHIPPING_ADDRESSES, result.getShippingAddresses()); |
| @@ -459,20 +471,65 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View |
| } |
| @Override |
| - public void onPaymentOptionChanged(OptionSection section, PaymentOption option) { |
| + public void onPaymentOptionChanged(final OptionSection section, PaymentOption option) { |
| + // The callback that will be fired if mIsClientCheckingSelection is true. |
| + Callback<PaymentInformation> callback = new Callback<PaymentInformation>() { |
| + @Override |
| + public void onResult(PaymentInformation result) { |
| + assert section == mShippingAddressSection |
| + : "Only shipping addresses can be checked"; |
| + mIsClientCheckingSelection = false; |
| + |
| + updateOrderSummarySection(result.getShoppingCart()); |
| + |
| + if (mRequestShipping) { |
| + updateSection(TYPE_SHIPPING_ADDRESSES, result.getShippingAddresses()); |
| + updateSection(TYPE_SHIPPING_OPTIONS, result.getShippingOptions()); |
| + } |
| + |
| + updateSection(TYPE_PAYMENT_METHODS, result.getPaymentMethods()); |
| + |
| + if (mShippingAddressSectionInformation.getSelectedItem() == null) { |
| + section.setDisplayMode(PaymentRequestSection.DISPLAY_MODE_FOCUSED); |
| + } else { |
| + expand(null); |
| + } |
| + |
| + updatePayButtonEnabled(); |
| + } |
| + }; |
| + |
| if (section == mShippingAddressSection) { |
| + if (mShippingAddressSectionInformation.getSelectedItem() == option) { |
| + expand(null); |
| + return; |
| + } |
| mShippingAddressSectionInformation.setSelectedItem(option); |
| - mClient.onSectionOptionChanged(TYPE_SHIPPING_ADDRESSES, option); |
| + mIsClientCheckingSelection = mClient.onSectionOptionChanged(TYPE_SHIPPING_ADDRESSES, |
| + option, callback); |
|
gone
2016/06/13 20:34:03
Feels like you should only pass a real callback in
please use gerrit instead
2016/06/13 21:59:08
Done.
|
| } else if (section == mShippingOptionSection) { |
| + if (mShippingOptionsSectionInformation.getSelectedItem() == option) { |
| + expand(null); |
| + return; |
| + } |
| mShippingOptionsSectionInformation.setSelectedItem(option); |
| - mClient.onSectionOptionChanged(TYPE_SHIPPING_OPTIONS, option); |
| + mIsClientCheckingSelection = mClient.onSectionOptionChanged(TYPE_SHIPPING_OPTIONS, |
| + option, callback); |
| } else if (section == mPaymentMethodSection) { |
| + if (mPaymentMethodSectionInformation.getSelectedItem() == option) { |
| + expand(null); |
| + return; |
| + } |
| mPaymentMethodSectionInformation.setSelectedItem(option); |
| - mClient.onSectionOptionChanged(TYPE_PAYMENT_METHODS, option); |
| + mIsClientCheckingSelection = mClient.onSectionOptionChanged(TYPE_PAYMENT_METHODS, |
| + option, callback); |
| } |
| - // Collapse all sections after an option is selected. |
| - expand(null); |
| + if (mIsClientCheckingSelection) { |
| + section.setDisplayMode(PaymentRequestSection.DISPLAY_MODE_CHECKING); |
| + } else { |
| + expand(null); |
| + } |
| updatePayButtonEnabled(); |
| } |
| @@ -564,10 +621,12 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View |
| && mShippingOptionsSectionInformation != null |
| && mShippingOptionsSectionInformation.getSelectedItem() != null |
| && mPaymentMethodSectionInformation != null |
| - && mPaymentMethodSectionInformation.getSelectedItem() != null); |
| + && mPaymentMethodSectionInformation.getSelectedItem() != null |
| + && !mIsClientCheckingSelection); |
| } else { |
| mPayButton.setEnabled(mPaymentMethodSectionInformation != null |
| - && mPaymentMethodSectionInformation.getSelectedItem() != null); |
| + && mPaymentMethodSectionInformation.getSelectedItem() != null |
| + && !mIsClientCheckingSelection); |
| } |
| notifyReadyToPay(); |
| @@ -581,7 +640,8 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View |
| /** @return Whether or not the dialog is accepting user input. */ |
| @Override |
| public boolean isAcceptingUserInput() { |
| - return isAcceptingCloseButton() && mPaymentMethodSectionInformation != null; |
| + return isAcceptingCloseButton() && mPaymentMethodSectionInformation != null |
| + && !mIsClientCheckingSelection; |
| } |
| private void expand(ViewGroup section) { |
| @@ -708,16 +768,27 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View |
| if (section == mShippingAddressSection) { |
| int selectedItemIndex = mShippingAddressSectionInformation.getSelectedItemIndex(); |
| boolean isNecessary = mClient.merchantNeedsShippingAddress() |
| - && selectedItemIndex == SectionInformation.NO_SELECTION; |
| - return isNecessary ? mContext.getString( |
| - R.string.payments_select_shipping_address_for_shipping_methods) : null; |
| + && (selectedItemIndex == SectionInformation.NO_SELECTION |
| + || selectedItemIndex == SectionInformation.INVALID_SELECTION); |
| + return isNecessary |
| + ? mContext.getString(selectedItemIndex == SectionInformation.NO_SELECTION |
| + ? R.string.payments_select_shipping_address_for_shipping_methods |
| + : R.string.payments_unsupported_shipping_address) |
| + : null; |
| } |
| return null; |
| } |
| + @Override |
| + public boolean isAdditionalTextWarning(OptionSection section) { |
|
gone
2016/06/13 20:34:03
Maybe isAdditionalTextDisplayingWarning?
please use gerrit instead
2016/06/13 21:59:08
Done.
|
| + return section == mShippingAddressSection |
| + && mShippingAddressSectionInformation.getSelectedItemIndex() |
| + == SectionInformation.INVALID_SELECTION; |
|
gone
2016/06/13 20:34:03
I think this requires a double indentation on the
please use gerrit instead
2016/06/13 21:59:08
Done.
|
| + } |
| + |
| /** |
| * Animates the whole dialog fading in and darkening everything else on screen. |
| - * This particular animation is not tracked because it is not meant to be cancelable. |
| + * This particular animation is not tracked because it is not meant to be cancellable. |
| */ |
| private class FadeInAnimator |
| extends AnimatorListenerAdapter implements OnLayoutChangeListener { |