Commit 9b9fd45a authored by Lucio Maciel's avatar Lucio Maciel

Disable message input while saving the message...

Also debounce clicks on MessageFormLayout
parent 9d8197a7
......@@ -22,6 +22,10 @@ public interface RoomContract {
void onMessageSendSuccessfully();
void disableMessageInput();
void enableMessageInput();
void showUnreadCount(int count);
void showMessages(List<Message> messages);
......
......@@ -607,6 +607,16 @@ public class RoomFragment extends AbstractChatRoomFragment implements
edittingMessage = null;
}
@Override
public void disableMessageInput() {
messageFormManager.enableComposingText(false);
}
@Override
public void enableMessageInput() {
messageFormManager.enableComposingText(true);
}
@Override
public void showUnreadCount(int count) {
newMessageIndicatorManager.updateNewMessageCount(count);
......
......@@ -119,6 +119,7 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
@Override
public void sendMessage(String messageText) {
view.disableMessageInput();
final Disposable subscription = getRoomUserPair()
.flatMap(pair -> messageInteractor.send(pair.first, pair.second, messageText))
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
......@@ -128,8 +129,12 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
if (success) {
view.onMessageSendSuccessfully();
}
view.enableMessageInput();
},
Logger::report
throwable -> {
view.enableMessageInput();
Logger.report(throwable);
}
);
addSubscription(subscription);
......@@ -148,6 +153,7 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
@Override
public void updateMessage(Message message, String content) {
view.disableMessageInput();
final Disposable subscription = getCurrentUser()
.flatMap(user -> messageInteractor.update(message, user, content))
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
......@@ -157,8 +163,12 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
if (success) {
view.onMessageSendSuccessfully();
}
view.enableMessageInput();
},
Logger::report
throwable -> {
view.enableMessageInput();
Logger.report(throwable);
}
);
addSubscription(subscription);
......
package chat.rocket.android.widget.helper;
import android.view.View;
/**
* A {@linkplain View.OnClickListener click listener} that debounces multiple clicks posted in the
* same frame. A click on one button disables all buttons for that frame.
*
* Shamelessly copied from butterknife -> https://github.com/JakeWharton/butterknife/blob/master/butterknife/src/main/java/butterknife/internal/DebouncingOnClickListener.java
*/
public abstract class DebouncingOnClickListener implements View.OnClickListener {
static boolean enabled = true;
private static final Runnable ENABLE_AGAIN = new Runnable() {
@Override public void run() {
enabled = true;
}
};
@Override public final void onClick(View v) {
if (enabled) {
enabled = false;
v.post(ENABLE_AGAIN);
doClick(v);
}
}
public abstract void doClick(View v);
}
......@@ -18,6 +18,7 @@ import android.widget.ImageButton;
import android.widget.LinearLayout;
import chat.rocket.android.widget.R;
import chat.rocket.android.widget.helper.DebouncingOnClickListener;
public class MessageFormLayout extends LinearLayout {
......@@ -57,18 +58,18 @@ public class MessageFormLayout extends LinearLayout {
attachButton = composer.findViewById(R.id.button_attach);
attachButton.setOnClickListener(new OnClickListener() {
attachButton.setOnClickListener(new DebouncingOnClickListener() {
@Override
public void onClick(View view) {
public void doClick(View view) {
onExtraActionSelectionClick();
}
});
sendButton = composer.findViewById(R.id.button_send);
sendButton.setOnClickListener(new OnClickListener() {
sendButton.setOnClickListener(new DebouncingOnClickListener() {
@Override
public void onClick(View view) {
public void doClick(View v) {
String messageText = getText();
if (messageText.length() > 0 && submitTextListener != null) {
submitTextListener.onSubmitText(messageText);
......
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