From 7a44c279365537b4ce38859b8656e2ca8d327d0a Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Wed, 9 Jun 2021 12:04:50 +1000 Subject: [PATCH] Ignore swipe on selected message --- .../conversation/v2/ConversationAdapter.kt | 6 +----- .../conversation/v2/messages/VisibleMessageView.kt | 14 +++++++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationAdapter.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationAdapter.kt index abb9b5d518..a78ca90913 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationAdapter.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationAdapter.kt @@ -66,11 +66,7 @@ class ConversationAdapter(context: Context, cursor: Cursor, private val onItemPr is VisibleMessageViewHolder -> { val view = viewHolder.view val isSelected = selectedItems.contains(message) - view.background = if (isSelected) { - ColorDrawable(context.resources.getColorWithID(R.color.accent, context.theme)) - } else { - null - } + view.snIsSelected = isSelected view.messageTimestampTextView.isVisible = isSelected val position = viewHolder.adapterPosition view.bind(message, getMessageBefore(position, cursor), getMessageAfter(position, cursor)) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt index e0eb7b342f..6c53e3ae8e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt @@ -1,6 +1,7 @@ package org.thoughtcrime.securesms.conversation.v2.messages import android.content.Context +import android.graphics.drawable.ColorDrawable import android.os.Build import android.os.Handler import android.os.Looper @@ -14,6 +15,7 @@ import org.session.libsession.messaging.contacts.Contact.ContactContext import org.session.libsession.utilities.ViewUtil import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.database.model.MessageRecord +import org.thoughtcrime.securesms.loki.utilities.getColorWithID import org.thoughtcrime.securesms.loki.utilities.toDp import org.thoughtcrime.securesms.util.DateUtils import java.util.* @@ -27,6 +29,8 @@ class VisibleMessageView : LinearLayout { private val gestureHandler = Handler(Looper.getMainLooper()) private var longPressCallback: Runnable? = null private var onDownTimestamp = 0L + var snIsSelected = false + set(value) { field = value; handleIsSelectedChanged()} var onPress: (() -> Unit)? = null var onSwipeToReply: (() -> Unit)? = null var onLongPress: (() -> Unit)? = null @@ -135,6 +139,14 @@ class VisibleMessageView : LinearLayout { } } + private fun handleIsSelectedChanged() { + background = if (snIsSelected) { + ColorDrawable(context.resources.getColorWithID(R.color.accent, context.theme)) + } else { + null + } + } + fun recycle() { profilePictureView.recycle() messageContentView.recycle() @@ -162,7 +174,7 @@ class VisibleMessageView : LinearLayout { private fun onMove(event: MotionEvent) { val translationX = toDp(event.rawX + dx, context.resources) - if (abs(translationX) < VisibleMessageView.longPressMovementTreshold) { + if (abs(translationX) < VisibleMessageView.longPressMovementTreshold || snIsSelected) { return } else { longPressCallback?.let { gestureHandler.removeCallbacks(it) }