Ignore swipe on selected message

This commit is contained in:
Niels Andriesse 2021-06-09 12:04:50 +10:00
parent 2988ac8b7a
commit 7a44c27936
2 changed files with 14 additions and 6 deletions

View File

@ -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))

View File

@ -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) }