Commit 8a6a4b16 authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Chromium LUCI CQ

[WebLayer] Adds PaymentUiService#showShippingAddressError()

This CL adds PaymentUiService#showShippingAddressError() to encapsulate
the UI logic so as to simplify the boundary between the UI and the
business logic.

Bug: 1155582
Change-Id: I144785eb833da259a6752f2f20d193f5f61c2e35
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2572909
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833847}
parent 6b687454
...@@ -15,7 +15,6 @@ import org.chromium.chrome.browser.app.ChromeActivity; ...@@ -15,7 +15,6 @@ import org.chromium.chrome.browser.app.ChromeActivity;
import org.chromium.chrome.browser.autofill.PersonalDataManager; import org.chromium.chrome.browser.autofill.PersonalDataManager;
import org.chromium.chrome.browser.payments.handler.PaymentHandlerCoordinator; import org.chromium.chrome.browser.payments.handler.PaymentHandlerCoordinator;
import org.chromium.chrome.browser.payments.ui.PaymentUiService; import org.chromium.chrome.browser.payments.ui.PaymentUiService;
import org.chromium.chrome.browser.payments.ui.SectionInformation;
import org.chromium.components.autofill.EditableOption; import org.chromium.components.autofill.EditableOption;
import org.chromium.components.payments.AbortReason; import org.chromium.components.payments.AbortReason;
import org.chromium.components.payments.BrowserPaymentRequest; import org.chromium.components.payments.BrowserPaymentRequest;
...@@ -398,15 +397,8 @@ public class ChromePaymentRequestService ...@@ -398,15 +397,8 @@ public class ChromePaymentRequestService
if (hasNotifiedInvokedPaymentApp) return; if (hasNotifiedInvokedPaymentApp) return;
if (mPaymentUiService.shouldShowShippingSection() String detailsError = mSpec.getPaymentDetails().error;
&& (mPaymentUiService.getUiShippingOptions().isEmpty() mPaymentUiService.showShippingAddressErrorIfApplicable(detailsError);
|| !TextUtils.isEmpty(details.error))
&& mPaymentUiService.getShippingAddressesSection().getSelectedItem() != null) {
mPaymentUiService.getShippingAddressesSection().getSelectedItem().setInvalid();
mPaymentUiService.getShippingAddressesSection().setSelectedItemIndex(
SectionInformation.INVALID_SELECTION);
mPaymentUiService.getShippingAddressesSection().setErrorMessage(details.error);
}
boolean providedInformationToPaymentRequestUI = boolean providedInformationToPaymentRequestUI =
mPaymentUiService.enableAndUpdatePaymentRequestUIWithPaymentInfo(); mPaymentUiService.enableAndUpdatePaymentRequestUIWithPaymentInfo();
...@@ -451,16 +443,7 @@ public class ChromePaymentRequestService ...@@ -451,16 +443,7 @@ public class ChromePaymentRequestService
// Implements BrowserPaymentRequest: // Implements BrowserPaymentRequest:
@Override @Override
public void onPaymentDetailsNotUpdated(@Nullable String selectedShippingOptionError) { public void onPaymentDetailsNotUpdated(@Nullable String selectedShippingOptionError) {
if (mPaymentUiService.shouldShowShippingSection() mPaymentUiService.showShippingAddressErrorIfApplicable(selectedShippingOptionError);
&& (mPaymentUiService.getUiShippingOptions().isEmpty()
|| !TextUtils.isEmpty(mSpec.selectedShippingOptionError()))
&& mPaymentUiService.getShippingAddressesSection().getSelectedItem() != null) {
mPaymentUiService.getShippingAddressesSection().getSelectedItem().setInvalid();
mPaymentUiService.getShippingAddressesSection().setSelectedItemIndex(
SectionInformation.INVALID_SELECTION);
mPaymentUiService.getShippingAddressesSection().setErrorMessage(
selectedShippingOptionError);
}
boolean providedInformationToPaymentRequestUI = boolean providedInformationToPaymentRequestUI =
mPaymentUiService.enableAndUpdatePaymentRequestUIWithPaymentInfo(); mPaymentUiService.enableAndUpdatePaymentRequestUIWithPaymentInfo();
......
...@@ -908,6 +908,20 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -908,6 +908,20 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
return isFirstUpdate; return isFirstUpdate;
} }
/**
* Shows the shipping address error if any.
* @param error The shipping address error, can be null.
*/
public void showShippingAddressErrorIfApplicable(@Nullable String error) {
if (shouldShowShippingSection()
&& (mUiShippingOptions.isEmpty() || !TextUtils.isEmpty(error))
&& mShippingAddressesSection.getSelectedItem() != null) {
mShippingAddressesSection.getSelectedItem().setInvalid();
mShippingAddressesSection.setSelectedItemIndex(SectionInformation.INVALID_SELECTION);
mShippingAddressesSection.setErrorMessage(error);
}
}
// Implements PaymentUiService.Delegate: // Implements PaymentUiService.Delegate:
@Override @Override
public boolean shouldShowShippingSection() { public boolean shouldShowShippingSection() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment