Commit 771aa583 authored by Matt Jones's avatar Matt Jones Committed by Commit Bot

Move snackbar manager out of BottomSheetController

This patch moves the snackbar manager out of the BottomSheetController
and removes the controller's dependency on Activity. The controller
did little more than hold a reference to the snackbar manager, this
is more along the lines of "feature interaction". As a result the code
has been moved to "glue code" in the activity (soon to be
RootUiCoordinator).

Bug: 986310, 1002277
Change-Id: Ibdbd2ad5a65e9721aecce20a54d7eb632814455e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1822027Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699526}
parent 7b804aef
......@@ -150,7 +150,7 @@ class AutofillAssistantUiTestUtil {
((BottomContainer) activity.findViewById(R.id.bottom_container))
.setBottomSheet(bottomSheet);
return new BottomSheetController(activity, activity.getLifecycleDispatcher(),
return new BottomSheetController(activity.getLifecycleDispatcher(),
activity.getActivityTabProvider(), activity.getScrim(), bottomSheet,
activity.getCompositorViewHolder().getLayoutManager().getOverlayPanelManager());
}
......
......@@ -280,6 +280,7 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
private ContextualSearchManager mContextualSearchManager;
protected ReaderModeManager mReaderModeManager;
private SnackbarManager mSnackbarManager;
private SnackbarManager mBottomSheetSnackbarManager;
@Nullable
private ToolbarManager mToolbarManager;
private BottomSheetController mBottomSheetController;
......@@ -1344,8 +1345,7 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
boolean useBottomSheetContainer = mBottomSheetController != null
&& mBottomSheetController.getBottomSheet().isSheetOpen()
&& !mBottomSheetController.getBottomSheet().isHiding();
return useBottomSheetContainer ? mBottomSheetController.getSnackbarManager()
: mSnackbarManager;
return useBottomSheetContainer ? mBottomSheetSnackbarManager : mSnackbarManager;
}
@Override
......@@ -1461,6 +1461,9 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
mBottomSheet.init(coordinator, getActivityTabProvider(), getFullscreenManager(),
getWindow(), getWindowAndroid().getKeyboardDelegate());
mBottomSheetSnackbarManager = new SnackbarManager(
this, mBottomSheet.findViewById(R.id.bottom_sheet_snackbar_container));
mBottomSheet.addObserver(new EmptyBottomSheetObserver() {
@Override
public void onSheetOpened(int reason) {
......@@ -1471,11 +1474,16 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
public void onSheetClosed(int reason) {
removeViewObscuringAllTabs(mBottomSheet);
}
@Override
public void onSheetOffsetChanged(float heightFraction, float offsetPx) {
mBottomSheetSnackbarManager.dismissAllSnackbars();
}
});
((BottomContainer) findViewById(R.id.bottom_container)).setBottomSheet(mBottomSheet);
mBottomSheetController = new BottomSheetController(this, getLifecycleDispatcher(),
mBottomSheetController = new BottomSheetController(getLifecycleDispatcher(),
mActivityTabProvider, mScrimView, mBottomSheet,
getCompositorViewHolder().getLayoutManager().getOverlayPanelManager());
}
......
......@@ -4,16 +4,12 @@
package org.chromium.chrome.browser.widget.bottomsheet;
import android.app.Activity;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ActivityTabProvider;
import org.chromium.chrome.browser.ActivityTabProvider.HintlessActivityTabObserver;
import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel;
import org.chromium.chrome.browser.compositor.bottombar.OverlayPanelManager;
import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
import org.chromium.chrome.browser.lifecycle.Destroyable;
import org.chromium.chrome.browser.snackbar.SnackbarManager;
import org.chromium.chrome.browser.tab.EmptyTabObserver;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabObserver;
......@@ -45,9 +41,6 @@ public class BottomSheetController implements Destroyable {
/** A handle to the {@link BottomSheet} that this class controls. */
private final BottomSheet mBottomSheet;
/** A handle to the {@link SnackbarManager} that manages snackbars inside the bottom sheet. */
private final SnackbarManager mSnackbarManager;
/** A {@link VrModeObserver} that observers events of entering and exiting VR mode. */
private final VrModeObserver mVrModeObserver;
......@@ -71,22 +64,18 @@ public class BottomSheetController implements Destroyable {
/**
* Build a new controller of the bottom sheet.
* @param activity An activity for context.
* @param lifecycleDispatcher The {@link ActivityLifecycleDispatcher} for the {@code activity}.
* @param activityTabProvider The provider of the activity's current tab.
* @param scrim The scrim that shows when the bottom sheet is opened.
* @param bottomSheet The bottom sheet that this class will be controlling.
* @param overlayManager The manager for overlay panels to attach listeners to.
*/
public BottomSheetController(final Activity activity,
final ActivityLifecycleDispatcher lifecycleDispatcher,
public BottomSheetController(final ActivityLifecycleDispatcher lifecycleDispatcher,
final ActivityTabProvider activityTabProvider, final ScrimView scrim,
BottomSheet bottomSheet, OverlayPanelManager overlayManager) {
mBottomSheet = bottomSheet;
mTabProvider = activityTabProvider;
mOverlayPanelManager = overlayManager;
mSnackbarManager = new SnackbarManager(
activity, mBottomSheet.findViewById(R.id.bottom_sheet_snackbar_container));
// Initialize the queue with a comparator that checks content priority.
mContentQueue = new PriorityQueue<>(INITIAL_QUEUE_CAPACITY,
......@@ -202,11 +191,6 @@ public class BottomSheetController implements Destroyable {
mIsProcessingHideRequest = false;
showNextContent(true);
}
@Override
public void onSheetOffsetChanged(float heightFraction, float offsetPx) {
mSnackbarManager.dismissAllSnackbars();
}
});
}
......@@ -253,13 +237,6 @@ public class BottomSheetController implements Destroyable {
return mBottomSheet;
}
/**
* @return The {@link SnackbarManager} that manages snackbars inside the bottom sheet.
*/
public SnackbarManager getSnackbarManager() {
return mSnackbarManager;
}
/**
* Request that some content be shown in the bottom sheet.
* @param content The content to be shown in the bottom sheet.
......
......@@ -74,9 +74,8 @@ public class BottomSheetControllerTest {
ScrimView scrim = new ScrimView(mActivityTestRule.getActivity(), null, coordinator);
mSheetController = new BottomSheetController(activity,
activity.getLifecycleDispatcher(), activity.getActivityTabProvider(), scrim,
mBottomSheet,
mSheetController = new BottomSheetController(activity.getLifecycleDispatcher(),
activity.getActivityTabProvider(), scrim, mBottomSheet,
activity.getCompositorViewHolder().getLayoutManager().getOverlayPanelManager());
mLowPriorityContent = new TestBottomSheetContent(
......
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