From 82b420830402c2ba5ed6114542daabfd74658065 Mon Sep 17 00:00:00 2001 From: kosyak Date: Tue, 7 May 2024 01:13:45 +0200 Subject: [PATCH] improve scroll to bottom button behavior --- .../ui/ConversationFragment.java | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 026021e3f..747e2f48c 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -226,7 +226,7 @@ public class ConversationFragment extends XmppFragment @ColorInt private int primaryColor = -1; - private LinkedList replyJumps = new LinkedList<>(); + private Message previousClickedReply = null; private ActionMode selectionActionMode; private final OnClickListener clickToMuc = @@ -590,19 +590,16 @@ public class ConversationFragment extends XmppFragment public void onClick(View v) { stopScrolling(); - if (!replyJumps.isEmpty()) { + if (previousClickedReply != null) { int lastVisiblePosition = binding.messagesView.getLastVisiblePosition(); Message lastVisibleMessage = messageListAdapter.getItem(lastVisiblePosition); - if (lastVisibleMessage == null) { - replyJumps.clear(); - } else { - while (!replyJumps.isEmpty()) { - Message jump = replyJumps.pop(); - if (jump.getMergedTimeSent() > lastVisibleMessage.getMergedTimeSent()) { - Runnable postSelectionRunnable = () -> highlightMessage(jump.getUuid()); - updateSelection(jump.getUuid(), binding.messagesView.getHeight() / 2, postSelectionRunnable, false, false); - return; - } + Message jump = previousClickedReply; + previousClickedReply = null; + if (lastVisibleMessage != null) { + if (jump.getMergedTimeSent() > lastVisibleMessage.getMergedTimeSent()) { + Runnable postSelectionRunnable = () -> highlightMessage(jump.getUuid()); + updateSelection(jump.getUuid(), binding.messagesView.getHeight() / 2, postSelectionRunnable, false, false); + return; } } } @@ -1592,7 +1589,7 @@ public class ConversationFragment extends XmppFragment if (replyId != null) { Runnable postSelectionRunnable = () -> highlightMessage(replyId); - replyJumps.push(message); + previousClickedReply = message; updateSelection(replyId, binding.messagesView.getHeight() / 2, postSelectionRunnable, true, false); } } @@ -3075,7 +3072,7 @@ public class ConversationFragment extends XmppFragment refreshCommands(); } - replyJumps.clear(); + previousClickedReply = null; return true; } @@ -3128,7 +3125,7 @@ public class ConversationFragment extends XmppFragment } this.binding.scrollToBottomButton.setEnabled(false); this.binding.scrollToBottomButton.hide(); - replyJumps.clear(); + previousClickedReply = null; this.binding.unreadCountCustomView.setVisibility(View.GONE); }