improve scroll to bottom button behavior

This commit is contained in:
kosyak 2024-05-07 01:13:45 +02:00
parent 42a57ca532
commit 82b4208304

View file

@ -226,7 +226,7 @@ public class ConversationFragment extends XmppFragment
@ColorInt @ColorInt
private int primaryColor = -1; private int primaryColor = -1;
private LinkedList<Message> replyJumps = new LinkedList<>(); private Message previousClickedReply = null;
private ActionMode selectionActionMode; private ActionMode selectionActionMode;
private final OnClickListener clickToMuc = private final OnClickListener clickToMuc =
@ -590,19 +590,16 @@ public class ConversationFragment extends XmppFragment
public void onClick(View v) { public void onClick(View v) {
stopScrolling(); stopScrolling();
if (!replyJumps.isEmpty()) { if (previousClickedReply != null) {
int lastVisiblePosition = binding.messagesView.getLastVisiblePosition(); int lastVisiblePosition = binding.messagesView.getLastVisiblePosition();
Message lastVisibleMessage = messageListAdapter.getItem(lastVisiblePosition); Message lastVisibleMessage = messageListAdapter.getItem(lastVisiblePosition);
if (lastVisibleMessage == null) { Message jump = previousClickedReply;
replyJumps.clear(); previousClickedReply = null;
} else { if (lastVisibleMessage != null) {
while (!replyJumps.isEmpty()) { if (jump.getMergedTimeSent() > lastVisibleMessage.getMergedTimeSent()) {
Message jump = replyJumps.pop(); Runnable postSelectionRunnable = () -> highlightMessage(jump.getUuid());
if (jump.getMergedTimeSent() > lastVisibleMessage.getMergedTimeSent()) { updateSelection(jump.getUuid(), binding.messagesView.getHeight() / 2, postSelectionRunnable, false, false);
Runnable postSelectionRunnable = () -> highlightMessage(jump.getUuid()); return;
updateSelection(jump.getUuid(), binding.messagesView.getHeight() / 2, postSelectionRunnable, false, false);
return;
}
} }
} }
} }
@ -1592,7 +1589,7 @@ public class ConversationFragment extends XmppFragment
if (replyId != null) { if (replyId != null) {
Runnable postSelectionRunnable = () -> highlightMessage(replyId); Runnable postSelectionRunnable = () -> highlightMessage(replyId);
replyJumps.push(message); previousClickedReply = message;
updateSelection(replyId, binding.messagesView.getHeight() / 2, postSelectionRunnable, true, false); updateSelection(replyId, binding.messagesView.getHeight() / 2, postSelectionRunnable, true, false);
} }
} }
@ -3075,7 +3072,7 @@ public class ConversationFragment extends XmppFragment
refreshCommands(); refreshCommands();
} }
replyJumps.clear(); previousClickedReply = null;
return true; return true;
} }
@ -3128,7 +3125,7 @@ public class ConversationFragment extends XmppFragment
} }
this.binding.scrollToBottomButton.setEnabled(false); this.binding.scrollToBottomButton.setEnabled(false);
this.binding.scrollToBottomButton.hide(); this.binding.scrollToBottomButton.hide();
replyJumps.clear(); previousClickedReply = null;
this.binding.unreadCountCustomView.setVisibility(View.GONE); this.binding.unreadCountCustomView.setVisibility(View.GONE);
} }