blob: 4701e3d69b76e12d29c9406f1c81ea4259b91397 [file] [log] [blame]
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.components.messages;
import org.chromium.base.supplier.Supplier;
import org.chromium.ui.base.WindowAndroid;
import org.chromium.ui.modelutil.PropertyModel;
/**
* This class implements public MessageDispatcher interface, delegating the actual work to
* MessageQueueManager.
*/
public class MessageDispatcherImpl implements ManagedMessageDispatcher {
private final MessageQueueManager mMessageQueueManager = new MessageQueueManager();
private final MessageContainer mMessageContainer;
private final Supplier<Integer> mMessageMaxTranslationSupplier;
private final WindowAndroid mWindowAndroid;
/**
* Build a new message dispatcher
* @param messageContainer A container view for displaying message banners.
* @param messageMaxTranslation 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 windowAndroid The {@link WindowAndroid} with which the Message is associated.
*/
public MessageDispatcherImpl(MessageContainer messageContainer,
Supplier<Integer> messageMaxTranslation, WindowAndroid windowAndroid) {
mMessageContainer = messageContainer;
mMessageMaxTranslationSupplier = messageMaxTranslation;
mWindowAndroid = windowAndroid;
}
@Override
public void enqueueMessage(PropertyModel messageProperties) {
MessageStateHandler messageStateHandler =
new SingleActionMessage(mMessageContainer, messageProperties, this::dismissMessage,
mMessageMaxTranslationSupplier, mWindowAndroid);
mMessageQueueManager.enqueueMessage(messageStateHandler, messageProperties);
}
@Override
public void dismissMessage(PropertyModel messageProperties) {
mMessageQueueManager.dismissMessage(messageProperties);
}
@Override
public void dismissAllMessages() {
mMessageQueueManager.dismissAllMessages();
}
@Override
public int suspend() {
return mMessageQueueManager.suspend();
}
@Override
public void resume(int token) {
mMessageQueueManager.resume(token);
}
@Override
public void setDelegate(MessageQueueDelegate delegate) {
mMessageQueueManager.setDelegate(delegate);
}
}