Commit c9e56a3c authored by Matt Jones's avatar Matt Jones Committed by Commit Bot

View creation is now BottomSheetController's responsibility

This patch moves the responsibility of creating the bottom sheet's
view to the controller. Glue shouldn't have to know implementation
details about the sheet. Instead, a root view, inflater, and callback
are passed in.

Bug: 1002277
Change-Id: I796f26e4a33b061ebcca9862f9bf19dea6d3aafc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2238560
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#777527}
parent 142bb9e4
...@@ -622,25 +622,21 @@ public class RootUiCoordinator ...@@ -622,25 +622,21 @@ public class RootUiCoordinator
* until content is requested in the sheet. * until content is requested in the sheet.
*/ */
private void initializeBottomSheetController() { private void initializeBottomSheetController() {
Supplier<View> sheetViewSupplier = () -> { // TODO(1093999): Componentize SnackbarManager so BottomSheetController can own this.
ViewGroup coordinator = mActivity.findViewById(R.id.coordinator); Callback<View> sheetInitializedCallback = (view) -> {
mActivity.getLayoutInflater().inflate(R.layout.bottom_sheet, coordinator);
View sheet = coordinator.findViewById(R.id.bottom_sheet);
mBottomSheetSnackbarManager = new SnackbarManager(mActivity, mBottomSheetSnackbarManager = new SnackbarManager(mActivity,
sheet.findViewById(R.id.bottom_sheet_snackbar_container), view.findViewById(R.id.bottom_sheet_snackbar_container),
mActivity.getWindowAndroid()); mActivity.getWindowAndroid());
return sheet;
}; };
Supplier<OverlayPanelManager> panelManagerSupplier = () Supplier<OverlayPanelManager> panelManagerSupplier = ()
-> mActivity.getCompositorViewHolder().getLayoutManager().getOverlayPanelManager(); -> mActivity.getCompositorViewHolder().getLayoutManager().getOverlayPanelManager();
// TODO(1094000): Initialize after inflation so we don't need to pass in view suppliers.
mBottomSheetController = BottomSheetControllerFactory.createBottomSheetController( mBottomSheetController = BottomSheetControllerFactory.createBottomSheetController(
() -> mScrimCoordinator, sheetViewSupplier, mActivity.getWindow(), () -> mScrimCoordinator, sheetInitializedCallback, mActivity.getWindow(),
mActivity.getWindowAndroid().getKeyboardDelegate()); mActivity.getWindowAndroid().getKeyboardDelegate(),
() -> mActivity.findViewById(R.id.coordinator));
mBottomSheetManager = new BottomSheetManager(mBottomSheetController, mActivityTabProvider, mBottomSheetManager = new BottomSheetManager(mBottomSheetController, mActivityTabProvider,
mActivity.getFullscreenManager(), mActivity::getModalDialogManager, mActivity.getFullscreenManager(), mActivity::getModalDialogManager,
......
...@@ -5,8 +5,10 @@ ...@@ -5,8 +5,10 @@
package org.chromium.chrome.browser.widget.bottomsheet; package org.chromium.chrome.browser.widget.bottomsheet;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.view.Window; import android.view.Window;
import org.chromium.base.Callback;
import org.chromium.base.supplier.Supplier; import org.chromium.base.supplier.Supplier;
import org.chromium.components.browser_ui.widget.scrim.ScrimCoordinator; import org.chromium.components.browser_ui.widget.scrim.ScrimCoordinator;
import org.chromium.ui.KeyboardVisibilityDelegate; import org.chromium.ui.KeyboardVisibilityDelegate;
...@@ -15,15 +17,17 @@ import org.chromium.ui.KeyboardVisibilityDelegate; ...@@ -15,15 +17,17 @@ import org.chromium.ui.KeyboardVisibilityDelegate;
public class BottomSheetControllerFactory { public class BottomSheetControllerFactory {
/** /**
* @param scrim A supplier of scrim to be shown behind the sheet. * @param scrim A supplier of scrim to be shown behind the sheet.
* @param bottomSheetViewSupplier A means of creating the sheet's view. * @param initializedCallback A callback for the sheet having been created.
* @param window The activity's window. * @param window The activity's window.
* @param keyboardDelegate A means of hiding the keyboard. * @param keyboardDelegate A means of hiding the keyboard.
* @param root The view that should contain the sheet.
* @param inflater A mechanism for building views from XML.
* @return A new instance of the {@link BottomSheetController}. * @return A new instance of the {@link BottomSheetController}.
*/ */
public static BottomSheetControllerInternal createBottomSheetController( public static BottomSheetControllerInternal createBottomSheetController(
final Supplier<ScrimCoordinator> scrim, Supplier<View> bottomSheetViewSupplier, final Supplier<ScrimCoordinator> scrim, Callback<View> initializedCallback,
Window window, KeyboardVisibilityDelegate keyboardDelegate) { Window window, KeyboardVisibilityDelegate keyboardDelegate, Supplier<ViewGroup> root) {
return new BottomSheetControllerImpl( return new BottomSheetControllerImpl(
scrim, bottomSheetViewSupplier, window, keyboardDelegate); scrim, initializedCallback, window, keyboardDelegate, root);
} }
} }
...@@ -4,11 +4,14 @@ ...@@ -4,11 +4,14 @@
package org.chromium.chrome.browser.widget.bottomsheet; package org.chromium.chrome.browser.widget.bottomsheet;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.view.Window; import android.view.Window;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import org.chromium.base.Callback;
import org.chromium.base.supplier.Supplier; import org.chromium.base.supplier.Supplier;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetContent; import org.chromium.components.browser_ui.bottomsheet.BottomSheetContent;
import org.chromium.components.browser_ui.widget.scrim.ScrimCoordinator; import org.chromium.components.browser_ui.widget.scrim.ScrimCoordinator;
...@@ -75,29 +78,38 @@ class BottomSheetControllerImpl implements BottomSheetControllerInternal { ...@@ -75,29 +78,38 @@ class BottomSheetControllerImpl implements BottomSheetControllerInternal {
/** /**
* Build a new controller of the bottom sheet. * Build a new controller of the bottom sheet.
* @param scrim A supplier of the scrim that shows when the bottom sheet is opened. * @param scrim A supplier of the scrim that shows when the bottom sheet is opened.
* @param bottomSheetViewSupplier A mechanism for creating a {@link BottomSheet}. * @param initializedCallback A callback for the sheet being created (as the sheet is not
* initialized until first use.
* @param window A means of accessing the screen size.
* @param keyboardDelegate A means of hiding the keyboard.
* @param root The view that should contain the sheet.
*/ */
public BottomSheetControllerImpl(final Supplier<ScrimCoordinator> scrim, public BottomSheetControllerImpl(final Supplier<ScrimCoordinator> scrim,
Supplier<View> bottomSheetViewSupplier, Window window, Callback<View> initializedCallback, Window window,
KeyboardVisibilityDelegate keyboardDelegate) { KeyboardVisibilityDelegate keyboardDelegate, Supplier<ViewGroup> root) {
mScrimCoordinatorSupplier = scrim; mScrimCoordinatorSupplier = scrim;
mPendingSheetObservers = new ArrayList<>(); mPendingSheetObservers = new ArrayList<>();
mSuppressionTokens = new TokenHolder(() -> onSuppressionTokensChanged()); mSuppressionTokens = new TokenHolder(() -> onSuppressionTokensChanged());
mSheetInitializer = () -> { mSheetInitializer = () -> {
initializeSheet(bottomSheetViewSupplier, window, keyboardDelegate); initializeSheet(initializedCallback, window, keyboardDelegate, root);
}; };
} }
/** /**
* Do the actual initialization of the bottom sheet. * Do the actual initialization of the bottom sheet.
* @param bottomSheetViewSupplier A means of creating the bottom sheet. * @param initializedCallback A callback for the creation of the sheet.
* @param window A means of accessing the screen size. * @param window A means of accessing the screen size.
* @param keyboardDelegate A means of hiding the keyboard. * @param keyboardDelegate A means of hiding the keyboard.
* @param root The view that should contain the sheet.
*/ */
private void initializeSheet(Supplier<View> bottomSheetViewSupplier, Window window, private void initializeSheet(Callback<View> initializedCallback, Window window,
KeyboardVisibilityDelegate keyboardDelegate) { KeyboardVisibilityDelegate keyboardDelegate, Supplier<ViewGroup> root) {
mBottomSheet = (BottomSheet) bottomSheetViewSupplier.get(); LayoutInflater.from(root.get().getContext()).inflate(
org.chromium.chrome.R.layout.bottom_sheet, root.get());
mBottomSheet = (BottomSheet) root.get().findViewById(org.chromium.chrome.R.id.bottom_sheet);
initializedCallback.onResult(mBottomSheet);
mBottomSheet.init(window, keyboardDelegate); mBottomSheet.init(window, keyboardDelegate);
mToolbarShadowHeight = mBottomSheet.getResources().getDimensionPixelOffset( mToolbarShadowHeight = mBottomSheet.getResources().getDimensionPixelOffset(
BottomSheet.getTopShadowResourceId()); BottomSheet.getTopShadowResourceId());
......
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