Commit 4ba11e8f authored by Sinan Sahin's avatar Sinan Sahin Committed by Commit Bot

[Messages] Add dismiss callback to the banner

Bug: 1137941
Change-Id: I1d9f7291f8ca5388667687d4bc2e5839837d3c50
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2530199
Commit-Queue: Sinan Sahin <sinansahin@google.com>
Reviewed-by: default avatarPavel Yatsuk <pavely@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827529}
parent a58687ee
...@@ -24,11 +24,15 @@ class MessageBannerCoordinator { ...@@ -24,11 +24,15 @@ class MessageBannerCoordinator {
* @param maxTranslationSupplier A {@link Supplier} that supplies the maximum translation Y * @param maxTranslationSupplier A {@link Supplier} that supplies the maximum translation Y
* value the message banner can have as a result of the animations or the gestures. * value the message banner can have as a result of the animations or the gestures.
* @param resources The {@link Resources}. * @param resources The {@link Resources}.
* @param messageDismissed The {@link Runnable} that will run if and when the user dismisses the
* message.
*/ */
MessageBannerCoordinator(MessageBannerView view, PropertyModel model, MessageBannerCoordinator(MessageBannerView view, PropertyModel model,
Supplier<Integer> maxTranslationSupplier, Resources resources) { Supplier<Integer> maxTranslationSupplier, Resources resources,
Runnable messageDismissed) {
PropertyModelChangeProcessor.create(model, view, MessageBannerViewBinder::bind); PropertyModelChangeProcessor.create(model, view, MessageBannerViewBinder::bind);
mMediator = new MessageBannerMediator(model, maxTranslationSupplier, resources); mMediator = new MessageBannerMediator(
model, maxTranslationSupplier, resources, messageDismissed);
view.setSwipeHandler(mMediator); view.setSwipeHandler(mMediator);
} }
......
...@@ -40,18 +40,20 @@ class MessageBannerMediator implements SwipeHandler { ...@@ -40,18 +40,20 @@ class MessageBannerMediator implements SwipeHandler {
private Supplier<Integer> mMaxTranslationSupplier; private Supplier<Integer> mMaxTranslationSupplier;
private final float mHideThresholdPx; private final float mHideThresholdPx;
private final Runnable mMessageDismissed;
private float mSwipeStartTranslationY; private float mSwipeStartTranslationY;
/** /**
* Constructs the message banner mediator. * Constructs the message banner mediator.
*/ */
MessageBannerMediator( MessageBannerMediator(PropertyModel model, Supplier<Integer> maxTranslationSupplier,
PropertyModel model, Supplier<Integer> maxTranslationSupplier, Resources resources) { Resources resources, Runnable messageDismissed) {
mModel = model; mModel = model;
mMaxTranslationSupplier = maxTranslationSupplier; mMaxTranslationSupplier = maxTranslationSupplier;
mModel.set(TRANSLATION_Y, -mMaxTranslationSupplier.get()); mModel.set(TRANSLATION_Y, -mMaxTranslationSupplier.get());
mHideThresholdPx = resources.getDimensionPixelSize(R.dimen.message_hide_threshold); mHideThresholdPx = resources.getDimensionPixelSize(R.dimen.message_hide_threshold);
mMessageDismissed = messageDismissed;
} }
/** /**
...@@ -121,8 +123,7 @@ class MessageBannerMediator implements SwipeHandler { ...@@ -121,8 +123,7 @@ class MessageBannerMediator implements SwipeHandler {
mAnimatorSet.addListener(new CancelAwareAnimatorListener() { mAnimatorSet.addListener(new CancelAwareAnimatorListener() {
@Override @Override
public void onEnd(Animator animator) { public void onEnd(Animator animator) {
// TODO(sinansahin): We need a way to notify someone to dismiss the message once mMessageDismissed.run();
// it's hidden.
mAnimatorSet = null; mAnimatorSet = null;
} }
}); });
......
...@@ -53,14 +53,15 @@ public class SingleActionMessage implements MessageStateHandler { ...@@ -53,14 +53,15 @@ public class SingleActionMessage implements MessageStateHandler {
if (mMessageBanner == null) { if (mMessageBanner == null) {
mView = (MessageBannerView) LayoutInflater.from(mContainer.getContext()) mView = (MessageBannerView) LayoutInflater.from(mContainer.getContext())
.inflate(R.layout.message_banner_view, mContainer, false); .inflate(R.layout.message_banner_view, mContainer, false);
mMessageBanner = new MessageBannerCoordinator( mMessageBanner = new MessageBannerCoordinator(mView, mModel, mMaxTranslationSupplier,
mView, mModel, mMaxTranslationSupplier, mContainer.getResources()); mContainer.getResources(), mDismissHandler.bind(mModel));
} }
mContainer.addMessage(mView); mContainer.addMessage(mView);
mMessageBanner.show(() -> { final Runnable onShown = () -> {
mMessageBanner.setOnTouchRunnable(mAutoDismissTimer::resetTimer); mMessageBanner.setOnTouchRunnable(mAutoDismissTimer::resetTimer);
mAutoDismissTimer.startTimer(() -> { mDismissHandler.onResult(mModel); }); mAutoDismissTimer.startTimer(() -> { mDismissHandler.onResult(mModel); });
}); };
mMessageBanner.show(onShown);
} }
/** /**
......
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