Commit 821174db authored by Becky Zhou's avatar Becky Zhou Committed by Commit Bot

[EoC] Handle snackbar for bottom sheet

Bug: 822951
Change-Id: If213f5703c966868778cd00511f222eba6ff5191
Reviewed-on: https://chromium-review.googlesource.com/990575
Commit-Queue: Becky Zhou <huayinz@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548222}
parent b625d909
...@@ -55,4 +55,10 @@ ...@@ -55,4 +55,10 @@
android:scaleType="fitXY" android:scaleType="fitXY"
android:contentDescription="@null" /> android:contentDescription="@null" />
<FrameLayout
android:id="@+id/bottom_sheet_snackbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start|bottom" />
</org.chromium.chrome.browser.widget.bottomsheet.BottomSheet> </org.chromium.chrome.browser.widget.bottomsheet.BottomSheet>
...@@ -90,12 +90,6 @@ ...@@ -90,12 +90,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
<FrameLayout
android:id="@+id/bottom_sheet_snackbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start|bottom" />
<ViewStub <ViewStub
android:id="@+id/empty_container_stub" android:id="@+id/empty_container_stub"
android:inflatedId="@+id/empty_container" android:inflatedId="@+id/empty_container"
......
...@@ -1192,7 +1192,10 @@ public abstract class ChromeActivity extends AsyncInitializationActivity ...@@ -1192,7 +1192,10 @@ public abstract class ChromeActivity extends AsyncInitializationActivity
*/ */
@Override @Override
public SnackbarManager getSnackbarManager() { public SnackbarManager getSnackbarManager() {
return mSnackbarManager; return mBottomSheetController != null
&& mBottomSheetController.getBottomSheet().isSheetOpen()
? mBottomSheetController.getSnackbarManager()
: mSnackbarManager;
} }
/** /**
...@@ -1269,7 +1272,7 @@ public abstract class ChromeActivity extends AsyncInitializationActivity ...@@ -1269,7 +1272,7 @@ public abstract class ChromeActivity extends AsyncInitializationActivity
((BottomContainer) findViewById(R.id.bottom_container)).setBottomSheet(mBottomSheet); ((BottomContainer) findViewById(R.id.bottom_container)).setBottomSheet(mBottomSheet);
mFadingBackgroundView = (FadingBackgroundView) findViewById(R.id.fading_focus_target); mFadingBackgroundView = (FadingBackgroundView) findViewById(R.id.fading_focus_target);
mBottomSheetController = new BottomSheetController(getTabModelSelector(), mBottomSheetController = new BottomSheetController(this, getTabModelSelector(),
getCompositorViewHolder().getLayoutManager(), mFadingBackgroundView, getCompositorViewHolder().getLayoutManager(), mFadingBackgroundView,
mBottomSheet); mBottomSheet);
......
...@@ -110,7 +110,7 @@ public class ContextualSuggestionsCoordinator { ...@@ -110,7 +110,7 @@ public class ContextualSuggestionsCoordinator {
new SuggestionsUiDelegateImpl(suggestionsSource, new DummyEventReporter(), new SuggestionsUiDelegateImpl(suggestionsSource, new DummyEventReporter(),
navigationDelegate, mProfile, mBottomSheetController.getBottomSheet(), navigationDelegate, mProfile, mBottomSheetController.getBottomSheet(),
mActivity.getChromeApplication().getReferencePool(), mActivity.getChromeApplication().getReferencePool(),
mActivity.getSnackbarManager()); mBottomSheetController.getSnackbarManager());
mContentCoordinator.showSuggestions(mActivity, mProfile, uiDelegate, mModel, mContentCoordinator.showSuggestions(mActivity, mProfile, uiDelegate, mModel,
mActivity.getWindowAndroid(), mActivity::closeContextMenu); mActivity.getWindowAndroid(), mActivity::closeContextMenu);
......
...@@ -4,12 +4,17 @@ ...@@ -4,12 +4,17 @@
package org.chromium.chrome.browser.widget.bottomsheet; package org.chromium.chrome.browser.widget.bottomsheet;
import android.app.Activity;
import android.view.ViewGroup; import android.view.ViewGroup;
import org.chromium.base.ActivityState;
import org.chromium.base.ApplicationStatus;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.compositor.layouts.Layout; import org.chromium.chrome.browser.compositor.layouts.Layout;
import org.chromium.chrome.browser.compositor.layouts.LayoutManager; import org.chromium.chrome.browser.compositor.layouts.LayoutManager;
import org.chromium.chrome.browser.compositor.layouts.SceneChangeObserver; import org.chromium.chrome.browser.compositor.layouts.SceneChangeObserver;
import org.chromium.chrome.browser.compositor.layouts.StaticLayout; import org.chromium.chrome.browser.compositor.layouts.StaticLayout;
import org.chromium.chrome.browser.snackbar.SnackbarManager;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabModelSelector; import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver; import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver;
...@@ -27,7 +32,7 @@ import java.util.PriorityQueue; ...@@ -27,7 +32,7 @@ import java.util.PriorityQueue;
* and call {@link #requestShowContent(BottomSheetContent, boolean)} which will return true if the * and call {@link #requestShowContent(BottomSheetContent, boolean)} which will return true if the
* content was actually shown (see full doc on method). * content was actually shown (see full doc on method).
*/ */
public class BottomSheetController { public class BottomSheetController implements ApplicationStatus.ActivityStateListener {
/** The initial capacity for the priority queue handling pending content show requests. */ /** The initial capacity for the priority queue handling pending content show requests. */
private static final int INITIAL_QUEUE_CAPACITY = 1; private static final int INITIAL_QUEUE_CAPACITY = 1;
...@@ -37,6 +42,9 @@ public class BottomSheetController { ...@@ -37,6 +42,9 @@ public class BottomSheetController {
/** A handle to the {@link BottomSheet} that this class controls. */ /** A handle to the {@link BottomSheet} that this class controls. */
private final BottomSheet mBottomSheet; private final BottomSheet mBottomSheet;
/** A handle to the {@link SnackbarManager} that manages snackbars inside the bottom sheet. */
private final SnackbarManager mSnackbarManager;
/** A queue for content that is waiting to be shown in the {@link BottomSheet}. */ /** A queue for content that is waiting to be shown in the {@link BottomSheet}. */
private PriorityQueue<BottomSheetContent> mContentQueue; private PriorityQueue<BottomSheetContent> mContentQueue;
...@@ -53,11 +61,15 @@ public class BottomSheetController { ...@@ -53,11 +61,15 @@ public class BottomSheetController {
* @param fadingBackgroundView The scrim that shows when the bottom sheet is opened. * @param fadingBackgroundView The scrim that shows when the bottom sheet is opened.
* @param bottomSheet The bottom sheet that this class will be controlling. * @param bottomSheet The bottom sheet that this class will be controlling.
*/ */
public BottomSheetController(final TabModelSelector tabModelSelector, public BottomSheetController(final Activity activity, final TabModelSelector tabModelSelector,
final LayoutManager layoutManager, final FadingBackgroundView fadingBackgroundView, final LayoutManager layoutManager, final FadingBackgroundView fadingBackgroundView,
BottomSheet bottomSheet) { BottomSheet bottomSheet) {
mBottomSheet = bottomSheet; mBottomSheet = bottomSheet;
mLayoutManager = layoutManager; mLayoutManager = layoutManager;
mSnackbarManager = new SnackbarManager(
activity, mBottomSheet.findViewById(R.id.bottom_sheet_snackbar_container));
mSnackbarManager.onStart();
ApplicationStatus.registerStateListenerForActivity(this, activity);
// Handle interactions with the scrim. // Handle interactions with the scrim.
fadingBackgroundView.addObserver(new FadingViewObserver() { fadingBackgroundView.addObserver(new FadingViewObserver() {
...@@ -132,6 +144,11 @@ public class BottomSheetController { ...@@ -132,6 +144,11 @@ public class BottomSheetController {
UiUtils.removeViewFromParent(fadingBackgroundView); UiUtils.removeViewFromParent(fadingBackgroundView);
parent.addView(fadingBackgroundView, mOriginalScrimIndexInParent); parent.addView(fadingBackgroundView, mOriginalScrimIndexInParent);
} }
@Override
public void onSheetOffsetChanged(float heightFraction) {
mSnackbarManager.dismissAllSnackbars();
}
}); });
// Initialize the queue with a comparator that checks content priority. // Initialize the queue with a comparator that checks content priority.
...@@ -146,6 +163,13 @@ public class BottomSheetController { ...@@ -146,6 +163,13 @@ public class BottomSheetController {
return mBottomSheet; 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. * Request that some content be shown in the bottom sheet.
* @param content The content to be shown in the bottom sheet. * @param content The content to be shown in the bottom sheet.
...@@ -235,6 +259,17 @@ public class BottomSheetController { ...@@ -235,6 +259,17 @@ public class BottomSheetController {
} }
} }
@Override
public void onActivityStateChange(Activity activity, int newState) {
if (newState == ActivityState.STARTED) {
mSnackbarManager.onStart();
} else if (newState == ActivityState.STOPPED) {
mSnackbarManager.onStop();
} else if (newState == ActivityState.DESTROYED) {
ApplicationStatus.unregisterActivityStateListener(this);
}
}
/** /**
* Show the next {@link BottomSheetContent} if it is available and peek the sheet. If no content * Show the next {@link BottomSheetContent} if it is available and peek the sheet. If no content
* is available the sheet's content is set to null. * is available the sheet's content is set to null.
......
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