diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt index d64d75a82d..2be3706269 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt @@ -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() } } 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 a78ca90913..3a4ec7fa87 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 @@ -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(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) } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt index d3d3b7f0d0..a7d707c69a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt @@ -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)) 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 d3453840fb..df57e44469 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 @@ -257,5 +257,9 @@ class VisibleMessageView : LinearLayout { performHapticFeedback(HapticFeedbackConstants.LONG_PRESS) onLongPress?.invoke() } + + fun onContentClick() { + messageContentView.onContentClick?.invoke() + } // endregion } diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VoiceMessageView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VoiceMessageView.kt index 136c9d9661..f85ebec0f6 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VoiceMessageView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VoiceMessageView.kt @@ -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)