Fix gestures interfering with eachother

This commit is contained in:
Niels Andriesse 2021-06-21 14:48:27 +10:00
parent 48df733773
commit ae078d8ee9
5 changed files with 16 additions and 7 deletions

View File

@ -30,6 +30,7 @@ import org.thoughtcrime.securesms.conversation.v2.input_bar.InputBarRecordingVie
import org.thoughtcrime.securesms.conversation.v2.input_bar.mentions.MentionCandidatesView
import org.thoughtcrime.securesms.conversation.v2.menus.ConversationActionModeCallback
import org.thoughtcrime.securesms.conversation.v2.menus.ConversationMenuHelper
import org.thoughtcrime.securesms.conversation.v2.messages.VisibleMessageView
import org.thoughtcrime.securesms.database.DatabaseFactory
import org.thoughtcrime.securesms.database.model.MessageRecord
import org.thoughtcrime.securesms.loki.utilities.toPx
@ -54,8 +55,8 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
val adapter = ConversationAdapter(
this,
cursor,
onItemPress = { message, position ->
handlePress(message, position)
onItemPress = { message, position, view ->
handlePress(message, position, view)
},
onItemSwipeToReply = { message, position ->
handleSwipeToReply(message, position)
@ -285,7 +286,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
}
// `position` is the adapter position; not the visual position
private fun handlePress(message: MessageRecord, position: Int) {
private fun handlePress(message: MessageRecord, position: Int, view: VisibleMessageView) {
val actionMode = this.actionMode
if (actionMode != null) {
adapter.toggleSelection(message, position)
@ -295,6 +296,8 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
actionMode.finish()
this.actionMode = null
}
} else {
view.onContentClick()
}
}

View File

@ -16,7 +16,7 @@ import org.thoughtcrime.securesms.database.model.MessageRecord
import org.thoughtcrime.securesms.loki.utilities.getColorWithID
import java.lang.IllegalStateException
class ConversationAdapter(context: Context, cursor: Cursor, private val onItemPress: (MessageRecord, Int) -> Unit,
class ConversationAdapter(context: Context, cursor: Cursor, private val onItemPress: (MessageRecord, Int, VisibleMessageView) -> Unit,
private val onItemSwipeToReply: (MessageRecord, Int) -> Unit, private val onItemLongPress: (MessageRecord, Int) -> Unit)
: CursorRecyclerViewAdapter<ViewHolder>(context, cursor) {
private val messageDB = DatabaseFactory.getMmsSmsDatabase(context)
@ -70,7 +70,7 @@ class ConversationAdapter(context: Context, cursor: Cursor, private val onItemPr
view.messageTimestampTextView.isVisible = isSelected
val position = viewHolder.adapterPosition
view.bind(message, getMessageBefore(position, cursor), getMessageAfter(position, cursor))
view.onPress = { onItemPress(message, viewHolder.adapterPosition) }
view.onPress = { onItemPress(message, viewHolder.adapterPosition, view) }
view.onSwipeToReply = { onItemSwipeToReply(message, viewHolder.adapterPosition) }
view.onLongPress = { onItemLongPress(message, viewHolder.adapterPosition) }
}

View File

@ -26,6 +26,7 @@ import org.thoughtcrime.securesms.loki.utilities.toPx
import java.lang.IllegalStateException
class VisibleMessageContentView : LinearLayout {
var onContentClick: (() -> Unit)? = null
// TODO: Large emojis
@ -50,6 +51,7 @@ class VisibleMessageContentView : LinearLayout {
setBackground(background)
// Body
mainContainer.removeAllViews()
onContentClick = null
if (message is MmsMessageRecord && message.linkPreviews.isNotEmpty()) {
val linkPreviewView = LinkPreviewView(context)
linkPreviewView.bind(message)
@ -66,6 +68,7 @@ class VisibleMessageContentView : LinearLayout {
val voiceMessageView = VoiceMessageView(context)
voiceMessageView.bind(message, background)
mainContainer.addView(voiceMessageView)
onContentClick = { voiceMessageView.togglePlayback() }
} else if (message is MmsMessageRecord && message.slideDeck.documentSlide != null) {
val documentView = DocumentView(context)
documentView.bind(message, getTextColor(message))

View File

@ -257,5 +257,9 @@ class VisibleMessageView : LinearLayout {
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
onLongPress?.invoke()
}
fun onContentClick() {
messageContentView.onContentClick?.invoke()
}
// endregion
}

View File

@ -31,7 +31,6 @@ class VoiceMessageView : LinearLayout {
private fun initialize() {
LayoutInflater.from(context).inflate(R.layout.view_voice_message, this)
setOnClickListener { togglePlayBack() }
voiceMessageViewDurationTextView.text = String.format("%01d:%02d",
TimeUnit.MILLISECONDS.toMinutes(mockDuration),
TimeUnit.MILLISECONDS.toSeconds(mockDuration))
@ -63,7 +62,7 @@ class VoiceMessageView : LinearLayout {
// endregion
// region Interaction
private fun togglePlayBack() {
fun togglePlayback() {
mockIsPlaying = !mockIsPlaying
val iconID = if (mockIsPlaying) R.drawable.exo_icon_pause else R.drawable.exo_icon_play
voiceMessagePlaybackImageView.setImageResource(iconID)