From 9b566820e81c35c24937b56de151e69aae5fd775 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 11 Sep 2023 13:15:56 -0500 Subject: [PATCH] Do not refresh message list while selecting To prevent blowing away the selection randomly --- .../ui/ConversationFragment.java | 18 +++++++++------- .../ui/adapter/MessageAdapter.java | 21 +++++++++++++++++++ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 0b6086168..85275f83f 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -1040,8 +1040,8 @@ public class ConversationFragment extends XmppFragment this.binding.textinput.setHint(R.string.you_are_not_participating); } else { this.binding.textInputHint.setVisibility(View.GONE); - this.binding.textinput.setHint(UIHelper.getMessageHint(getActivity(), conversation)); - getActivity().invalidateOptionsMenu(); + this.binding.textinput.setHint(UIHelper.getMessageHint(activity, conversation)); + activity.invalidateOptionsMenu(); } binding.messagesView.post(this::updateThreadFromLastMessage); @@ -3461,16 +3461,20 @@ public class ConversationFragment extends XmppFragment private void refresh(boolean notifyConversationRead) { synchronized (this.messageList) { if (this.conversation != null) { - conversation.populateWithMessages(this.messageList); - updateSnackBar(conversation); - updateStatusMessages(); + if (messageListAdapter.hasSelection()) { + if (notifyConversationRead) binding.messagesView.postDelayed(this::refresh, 1000L); + } else { + conversation.populateWithMessages(this.messageList); + updateStatusMessages(); + this.messageListAdapter.notifyDataSetChanged(); + } if (conversation.getReceivedMessagesCountSinceUuid(lastMessageUuid) != 0) { binding.unreadCountCustomView.setVisibility(View.VISIBLE); binding.unreadCountCustomView.setUnreadCount( conversation.getReceivedMessagesCountSinceUuid(lastMessageUuid)); } - this.messageListAdapter.notifyDataSetChanged(); - updateChatMsgHint(); + updateSnackBar(conversation); + if (activity != null) updateChatMsgHint(); if (notifyConversationRead && activity != null) { binding.messagesView.post(this::fireReadEvent); } diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 09ae3adb0..6b8aee83e 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -24,6 +24,7 @@ import android.text.style.StyleSpan; import android.text.style.URLSpan; import android.util.DisplayMetrics; import android.util.LruCache; +import android.view.accessibility.AccessibilityEvent; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; @@ -127,6 +128,7 @@ public class MessageAdapter extends ArrayAdapter { private boolean mUseGreenBackground = false; private final boolean mForceNames; private final Map lastWebxdcUpdate = new HashMap<>(); + private String selectionUuid = null; public MessageAdapter(final XmppActivity activity, final List messages, final boolean forceNames) { super(activity, 0, messages); @@ -179,6 +181,10 @@ public class MessageAdapter extends ArrayAdapter { if (mConversationFragment != null) mConversationFragment.quoteText(text); } + public boolean hasSelection() { + return selectionUuid != null; + } + public Activity getActivity() { return activity; } @@ -1059,6 +1065,7 @@ public class MessageAdapter extends ArrayAdapter { return false; } }); + viewHolder.messageBody.setAccessibilityDelegate(null); final Transferable transferable = message.getTransferable(); final boolean unInitiatedButKnownSize = MessageUtils.unInitiatedButKnownSize(message); @@ -1181,6 +1188,20 @@ public class MessageAdapter extends ArrayAdapter { displayStatus(viewHolder, message, type, darkBackground); + viewHolder.messageBody.setAccessibilityDelegate(new View.AccessibilityDelegate() { + @Override + public void sendAccessibilityEvent(View host, int eventType) { + super.sendAccessibilityEvent(host, eventType); + if (eventType == AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED) { + if (viewHolder.messageBody.hasSelection()) { + selectionUuid = message.getUuid(); + } else if (message.getUuid() != null && message.getUuid().equals(selectionUuid)) { + selectionUuid = null; + } + } + } + }); + return view; } -- 2.45.2