Commit 7df52de7 authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Commit Bot

Create PaymentUIsManager to take over PRImpl's UI logic

In order to reuse most of PaymentRequestImpl for WebLayer, to move the
business logic from PaymentRequestImpl to ComponentPaymentRequestImpl,
we need to put a clear cut between the UI logic and the business logic
within PaymentRequestImpl. So this CL is to create PaymentUIsManager to
take over the the UI logic of PRImpl.

Change:
* Move mUI into PaymentUIsManager and renaming as mPaymentRequestUI
* Move the PaymentUisShowStateReconciler into PaymentUIsManager

Bug: 1102522

Change-Id: I128a58c8a86c6325e408ad249571c45f127d44ab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2299187
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#788782}
parent a2d0b5a2
...@@ -1289,6 +1289,7 @@ chrome_java_sources = [ ...@@ -1289,6 +1289,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestHeader.java", "java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestHeader.java",
"java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestSection.java", "java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestSection.java",
"java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestUI.java", "java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestUI.java",
"java/src/org/chromium/chrome/browser/payments/ui/PaymentUIsManager.java",
"java/src/org/chromium/chrome/browser/payments/ui/SectionInformation.java", "java/src/org/chromium/chrome/browser/payments/ui/SectionInformation.java",
"java/src/org/chromium/chrome/browser/payments/ui/SectionUiUtils.java", "java/src/org/chromium/chrome/browser/payments/ui/SectionUiUtils.java",
"java/src/org/chromium/chrome/browser/payments/ui/ShoppingCart.java", "java/src/org/chromium/chrome/browser/payments/ui/ShoppingCart.java",
......
...@@ -40,11 +40,11 @@ import org.chromium.chrome.browser.ChromeVersionInfo; ...@@ -40,11 +40,11 @@ import org.chromium.chrome.browser.ChromeVersionInfo;
import org.chromium.chrome.browser.autofill.prefeditor.EditorDialog; import org.chromium.chrome.browser.autofill.prefeditor.EditorDialog;
import org.chromium.chrome.browser.autofill.prefeditor.EditorObserverForTest; import org.chromium.chrome.browser.autofill.prefeditor.EditorObserverForTest;
import org.chromium.chrome.browser.lifecycle.PauseResumeWithNativeObserver; import org.chromium.chrome.browser.lifecycle.PauseResumeWithNativeObserver;
import org.chromium.chrome.browser.payments.PaymentRequestImpl.PaymentUisShowStateReconciler;
import org.chromium.chrome.browser.payments.ShippingStrings; import org.chromium.chrome.browser.payments.ShippingStrings;
import org.chromium.chrome.browser.payments.ui.PaymentRequestSection.LineItemBreakdownSection; import org.chromium.chrome.browser.payments.ui.PaymentRequestSection.LineItemBreakdownSection;
import org.chromium.chrome.browser.payments.ui.PaymentRequestSection.OptionSection; import org.chromium.chrome.browser.payments.ui.PaymentRequestSection.OptionSection;
import org.chromium.chrome.browser.payments.ui.PaymentRequestSection.SectionSeparator; import org.chromium.chrome.browser.payments.ui.PaymentRequestSection.SectionSeparator;
import org.chromium.chrome.browser.payments.ui.PaymentUIsManager.PaymentUisShowStateReconciler;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.signin.IdentityServicesProvider; import org.chromium.chrome.browser.signin.IdentityServicesProvider;
import org.chromium.components.autofill.EditableOption; import org.chromium.components.autofill.EditableOption;
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.payments.ui;
import org.chromium.chrome.browser.payments.PaymentRequestImpl;
/**
* This class manages all of the UIs related to payment. The UI logic of {@link PaymentRequestImpl}
* should be moved into this class.
*/
public class PaymentUIsManager {
private PaymentRequestUI mPaymentRequestUI;
private PaymentUisShowStateReconciler mPaymentUisShowStateReconciler;
/**
* This class is to coordinate the show state of a bottom sheet UI (either expandable payment
* handler or minimal UI) and the Payment Request UI so that these visibility rules are
* enforced:
* 1. At most one UI is shown at any moment in case the Payment Request UI obstructs the bottom
* sheet.
* 2. Bottom sheet is prioritized to show over Payment Request UI
*/
public class PaymentUisShowStateReconciler {
// Whether the bottom sheet is showing.
private boolean mShowingBottomSheet;
// Whether to show the Payment Request UI when the bottom sheet is not being shown.
private boolean mShouldShowDialog;
/**
* Show the Payment Request UI dialog when the bottom sheet is hidden, i.e., if the bottom
* sheet hidden, show the dialog immediately; otherwise, show the dialog after the bottom
* sheet hides.
*/
/* package */ void showPaymentRequestDialogWhenNoBottomSheet() {
mShouldShowDialog = true;
updatePaymentRequestDialogShowState();
}
/** Hide the Payment Request UI dialog. */
/* package */ void hidePaymentRequestDialog() {
mShouldShowDialog = false;
updatePaymentRequestDialogShowState();
}
/** A callback invoked when the Payment Request UI is closed. */
public void onPaymentRequestUiClosed() {
assert mPaymentRequestUI == null;
mShouldShowDialog = false;
}
/** A callback invoked when the bottom sheet is shown, to enforce the visibility rules. */
public void onBottomSheetShown() {
mShowingBottomSheet = true;
updatePaymentRequestDialogShowState();
}
/** A callback invoked when the bottom sheet is hidden, to enforce the visibility rules. */
public void onBottomSheetClosed() {
mShowingBottomSheet = false;
updatePaymentRequestDialogShowState();
}
private void updatePaymentRequestDialogShowState() {
if (mPaymentRequestUI == null) return;
mPaymentRequestUI.setVisible(!mShowingBottomSheet && mShouldShowDialog);
}
}
/** Create PaymentUIsManager. */
public PaymentUIsManager() {
mPaymentUisShowStateReconciler = new PaymentUisShowStateReconciler();
}
/** @return The PaymentRequestUI. */
public PaymentRequestUI getPaymentRequestUI() {
return mPaymentRequestUI;
}
/**
* Set the PaymentRequestUI.
* @param paymentRequestUI The PaymentRequestUI.
*/
public void setPaymentRequestUI(PaymentRequestUI paymentRequestUI) {
mPaymentRequestUI = paymentRequestUI;
}
/** @return The PaymentUisShowStateReconciler. */
public PaymentUisShowStateReconciler getPaymentUisShowStateReconciler() {
return mPaymentUisShowStateReconciler;
}
}
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