Commit ab612558 authored by Ian Wells's avatar Ian Wells Committed by Commit Bot

Change FeedActionsHandler.showSnackbar to use an enum for duration rather than milliseconds

Responsibility for defining snackbar durations will belong to FeedStreamSurface.

Bug: 1044139
Change-Id: Ifd007e0014fb46e5c81eb6e7ad6d78ed4a23eb13
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2231540
Commit-Queue: Ian Wells <iwells@chromium.org>
Reviewed-by: default avatarDan H <harringtond@chromium.org>
Reviewed-by: default avatarJustin DeWitt <dewittj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#775288}
parent dcc60951
...@@ -49,6 +49,10 @@ import java.util.List; ...@@ -49,6 +49,10 @@ import java.util.List;
@JNINamespace("feed") @JNINamespace("feed")
public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHandler { public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHandler {
private static final String TAG = "FeedStreamSurface"; private static final String TAG = "FeedStreamSurface";
private static final int SNACKBAR_DURATION_MS_SHORT = 4000;
private static final int SNACKBAR_DURATION_MS_LONG = 10000;
private final long mNativeFeedStreamSurface; private final long mNativeFeedStreamSurface;
private final FeedListContentManager mContentManager; private final FeedListContentManager mContentManager;
private final TabModelSelector mTabModelSelector; private final TabModelSelector mTabModelSelector;
...@@ -335,8 +339,14 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand ...@@ -335,8 +339,14 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand
} }
@Override @Override
public void showSnackbar(String text, String actionLabel, int durationMs, public void showSnackbar(String text, String actionLabel,
FeedActionsHandler.SnackbarDuration duration,
FeedActionsHandler.SnackbarController controller) { FeedActionsHandler.SnackbarController controller) {
int durationMs = SNACKBAR_DURATION_MS_SHORT;
if (duration == FeedActionsHandler.SnackbarDuration.LONG) {
durationMs = SNACKBAR_DURATION_MS_LONG;
}
mSnackbarManager.showSnackbar( mSnackbarManager.showSnackbar(
Snackbar.make(text, Snackbar.make(text,
new SnackbarManager.SnackbarController() { new SnackbarManager.SnackbarController() {
......
...@@ -332,7 +332,8 @@ public class FeedStreamSurfaceTest { ...@@ -332,7 +332,8 @@ public class FeedStreamSurfaceTest {
@Test @Test
@SmallTest @SmallTest
public void testShowSnackbar() { public void testShowSnackbar() {
mFeedStreamSurface.showSnackbar("message", "Undo", 50, mSnackbarController); mFeedStreamSurface.showSnackbar(
"message", "Undo", FeedActionsHandler.SnackbarDuration.SHORT, mSnackbarController);
verify(mSnackbarManager).showSnackbar(any()); verify(mSnackbarManager).showSnackbar(any());
} }
......
...@@ -55,13 +55,27 @@ public interface FeedActionsHandler { ...@@ -55,13 +55,27 @@ public interface FeedActionsHandler {
default void onDismissNoAction() {} default void onDismissNoAction() {}
} }
/**
* Snackbar dismissal timeout.
*/
public enum SnackbarDuration {
/**
* SHORT should be used with simple one-line snackbars.
*/
SHORT,
/**
* LONG should be used with multi-line snackbars that take longer to read.
*/
LONG
}
/** /**
* Show a snackbar. * Show a snackbar.
* @param text Text to display. * @param text Text to display.
* @param actionLabel Text for the button (e.g. "Undo"). * @param actionLabel Text for the button (e.g. "Undo").
* @param durationMs Timeout in milliseconds after which the snackbar is removed. * @param duration Whether to remove the snackbar after a short or long delay.
* @param controller Handlers for snackbar actions. * @param controller Handlers for snackbar actions.
*/ */
default void showSnackbar( default void showSnackbar(String text, String actionLabel, SnackbarDuration duration,
String text, String actionLabel, int durationMs, SnackbarController controller) {} SnackbarController controller) {}
} }
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