From de2f5e7a836a270acc94d8d8efbb3fdb67adf3ef Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 5 Mar 2018 13:23:04 +0100 Subject: [PATCH] reorder and scroll down after resending a message --- .../conversations/entities/Conversation.java | 17 +++++++---------- .../services/XmppConnectionService.java | 2 ++ .../conversations/ui/ConversationFragment.java | 9 ++++++++- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index 1d03e7b1c..d66b1c99c 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -848,16 +848,13 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl public void sort() { synchronized (this.messages) { - Collections.sort(this.messages, new Comparator() { - @Override - public int compare(Message left, Message right) { - if (left.getTimeSent() < right.getTimeSent()) { - return -1; - } else if (left.getTimeSent() > right.getTimeSent()) { - return 1; - } else { - return 0; - } + Collections.sort(this.messages, (left, right) -> { + if (left.getTimeSent() < right.getTimeSent()) { + return -1; + } else if (left.getTimeSent() > right.getTimeSent()) { + return 1; + } else { + return 0; } }); untieMessages(); diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index f2106c64a..cdfb1b19a 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -3588,6 +3588,8 @@ public class XmppConnectionService extends Service { markMessage(msg, Message.STATUS_WAITING); this.resendMessage(msg, false); } + message.getConversation().sort(); + updateConversationUi(); } public void clearConversationHistory(final Conversation conversation) { diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 1b4a2efc3..3d1afea63 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -1528,6 +1528,10 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke activity.selectPresence(conversation, () -> { message.setCounterpart(conversation.getNextCounterpart()); activity.xmppConnectionService.resendFailedMessages(message); + new Handler().post(() -> { + int size = messageList.size(); + this.binding.messagesView.setSelection(size - 1); + }); }); return; } @@ -1540,7 +1544,10 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } } activity.xmppConnectionService.resendFailedMessages(message); - } + new Handler().post(() -> { + int size = messageList.size(); + this.binding.messagesView.setSelection(size - 1); + }); } private void copyUrl(Message message) { final String url;