~singpolyma/cheogram-android

9b566820e81c35c24937b56de151e69aae5fd775 — Stephen Paul Weber 8 months ago 2928cad
Do not refresh message list while selecting

To prevent blowing away the selection randomly
M src/main/java/eu/siacs/conversations/ui/ConversationFragment.java => src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +11 -7
@@ 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);
                }

M src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java => src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +21 -0
@@ 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<Message> {
    private boolean mUseGreenBackground = false;
    private final boolean mForceNames;
    private final Map<String, WebxdcUpdate> lastWebxdcUpdate = new HashMap<>();
    private String selectionUuid = null;

    public MessageAdapter(final XmppActivity activity, final List<Message> messages, final boolean forceNames) {
        super(activity, 0, messages);


@@ 179,6 181,10 @@ public class MessageAdapter extends ArrayAdapter<Message> {
        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<Message> {
                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<Message> {

        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;
    }