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 {
* @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.
* @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,
Supplier<Integer> maxTranslationSupplier, Resources resources) {
Supplier<Integer> maxTranslationSupplier, Resources resources,
Runnable messageDismissed) {
PropertyModelChangeProcessor.create(model, view, MessageBannerViewBinder::bind);
mMediator = new MessageBannerMediator(model, maxTranslationSupplier, resources);
mMediator = new MessageBannerMediator(
model, maxTranslationSupplier, resources, messageDismissed);
view.setSwipeHandler(mMediator);
}
......
......@@ -40,18 +40,20 @@ class MessageBannerMediator implements SwipeHandler {
private Supplier<Integer> mMaxTranslationSupplier;
private final float mHideThresholdPx;
private final Runnable mMessageDismissed;
private float mSwipeStartTranslationY;
/**
* Constructs the message banner mediator.
*/
MessageBannerMediator(
PropertyModel model, Supplier<Integer> maxTranslationSupplier, Resources resources) {
MessageBannerMediator(PropertyModel model, Supplier<Integer> maxTranslationSupplier,
Resources resources, Runnable messageDismissed) {
mModel = model;
mMaxTranslationSupplier = maxTranslationSupplier;
mModel.set(TRANSLATION_Y, -mMaxTranslationSupplier.get());
mHideThresholdPx = resources.getDimensionPixelSize(R.dimen.message_hide_threshold);
mMessageDismissed = messageDismissed;
}
/**
......@@ -121,8 +123,7 @@ class MessageBannerMediator implements SwipeHandler {
mAnimatorSet.addListener(new CancelAwareAnimatorListener() {
@Override
public void onEnd(Animator animator) {
// TODO(sinansahin): We need a way to notify someone to dismiss the message once
// it's hidden.
mMessageDismissed.run();
mAnimatorSet = null;
}
});
......
......@@ -53,14 +53,15 @@ public class SingleActionMessage implements MessageStateHandler {
if (mMessageBanner == null) {
mView = (MessageBannerView) LayoutInflater.from(mContainer.getContext())
.inflate(R.layout.message_banner_view, mContainer, false);
mMessageBanner = new MessageBannerCoordinator(
mView, mModel, mMaxTranslationSupplier, mContainer.getResources());
mMessageBanner = new MessageBannerCoordinator(mView, mModel, mMaxTranslationSupplier,
mContainer.getResources(), mDismissHandler.bind(mModel));
}
mContainer.addMessage(mView);
mMessageBanner.show(() -> {
final Runnable onShown = () -> {
mMessageBanner.setOnTouchRunnable(mAutoDismissTimer::resetTimer);
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