forked from upstream-mirrors/quik
fix(reactions): make swipe-to-react work and give REACT a visible icon
- Remove the message item OnTouchListener that was swallowing swipe gestures, so ItemTouchHelper receives swipes again. Single-tap and long-press use plain click/long-click listeners like the conversations list; double-tap is detected via tap timing instead. - Use ic_favorite_black_24dp for the REACT swipe action. message_emoji is a transparent spacer shape, so it rendered no icon. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+1
-1
@@ -144,7 +144,7 @@ class MessageItemTouchCallback @Inject constructor(
|
|||||||
|
|
||||||
private fun iconForAction(action: Int, tint: Int): Bitmap? {
|
private fun iconForAction(action: Int, tint: Int): Bitmap? {
|
||||||
val res = when (action) {
|
val res = when (action) {
|
||||||
Preferences.MESSAGE_SWIPE_ACTION_REACT -> R.drawable.message_emoji
|
Preferences.MESSAGE_SWIPE_ACTION_REACT -> R.drawable.ic_favorite_black_24dp
|
||||||
Preferences.MESSAGE_SWIPE_ACTION_REPLY -> R.drawable.ic_reply_white_24dp
|
Preferences.MESSAGE_SWIPE_ACTION_REPLY -> R.drawable.ic_reply_white_24dp
|
||||||
Preferences.MESSAGE_SWIPE_ACTION_COPY -> R.drawable.ic_content_copy_black_24dp
|
Preferences.MESSAGE_SWIPE_ACTION_COPY -> R.drawable.ic_content_copy_black_24dp
|
||||||
Preferences.MESSAGE_SWIPE_ACTION_FORWARD -> R.drawable.ic_forward_black_24dp
|
Preferences.MESSAGE_SWIPE_ACTION_FORWARD -> R.drawable.ic_forward_black_24dp
|
||||||
|
|||||||
@@ -32,9 +32,7 @@ import android.text.style.ClickableSpan
|
|||||||
import android.text.style.StyleSpan
|
import android.text.style.StyleSpan
|
||||||
import android.text.style.URLSpan
|
import android.text.style.URLSpan
|
||||||
import android.text.util.Linkify
|
import android.text.util.Linkify
|
||||||
import android.view.GestureDetector
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.MotionEvent
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
@@ -103,8 +101,15 @@ class MessagesAdapter @Inject constructor(
|
|||||||
private const val VIEW_TYPE_MESSAGE_OUT = 1
|
private const val VIEW_TYPE_MESSAGE_OUT = 1
|
||||||
|
|
||||||
private const val MAX_MESSAGE_DISPLAY_LENGTH = 5000
|
private const val MAX_MESSAGE_DISPLAY_LENGTH = 5000
|
||||||
|
|
||||||
|
private const val DOUBLE_TAP_TIMEOUT_MS = 300L
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tracks the previous tap so we can detect a double-tap without an OnTouchListener
|
||||||
|
// (an OnTouchListener on the item would swallow swipe gestures from ItemTouchHelper)
|
||||||
|
private var lastTapMessageId = -1L
|
||||||
|
private var lastTapTime = 0L
|
||||||
|
|
||||||
// click events passed back to compose view model
|
// click events passed back to compose view model
|
||||||
val partClicks: Subject<Long> = PublishSubject.create()
|
val partClicks: Subject<Long> = PublishSubject.create()
|
||||||
val messageLinkClicks: Subject<Uri> = PublishSubject.create()
|
val messageLinkClicks: Subject<Uri> = PublishSubject.create()
|
||||||
@@ -174,34 +179,29 @@ class MessagesAdapter @Inject constructor(
|
|||||||
|
|
||||||
return QkViewHolder(view).apply {
|
return QkViewHolder(view).apply {
|
||||||
val holder = this
|
val holder = this
|
||||||
// GestureDetector handles single-tap (select/expand) and double-tap (react).
|
// Plain click + long-click listeners (no OnTouchListener) so the RecyclerView's
|
||||||
// It must NOT consume events, otherwise the RecyclerView's ItemTouchHelper never
|
// ItemTouchHelper still receives swipe gestures, same as the conversations list.
|
||||||
// sees swipe gestures. The view is long-clickable (below), so it stays a touch
|
view.setOnClickListener {
|
||||||
// target and the detector keeps receiving move/up events for double-tap detection.
|
getItem(holder.adapterPosition)?.let { item ->
|
||||||
val gestureDetector = GestureDetector(context, object : GestureDetector.SimpleOnGestureListener() {
|
val now = System.currentTimeMillis()
|
||||||
override fun onDown(e: MotionEvent): Boolean = true
|
if (item.id == lastTapMessageId && (now - lastTapTime) <= DOUBLE_TAP_TIMEOUT_MS) {
|
||||||
|
// second quick tap on the same message -> double-tap reaction
|
||||||
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
|
lastTapMessageId = -1L
|
||||||
getItem(holder.adapterPosition)?.let {
|
lastTapTime = 0L
|
||||||
when (toggleSelection(it.id, false)) {
|
doubleTapIntent.onNext(item.id)
|
||||||
true -> view.isActivated = isSelected(it.id)
|
} else {
|
||||||
|
lastTapMessageId = item.id
|
||||||
|
lastTapTime = now
|
||||||
|
when (toggleSelection(item.id, false)) {
|
||||||
|
true -> view.isActivated = isSelected(item.id)
|
||||||
false -> {
|
false -> {
|
||||||
expanded[it.id] = status.visibility != View.VISIBLE
|
expanded[item.id] = status.visibility != View.VISIBLE
|
||||||
notifyItemChanged(holder.adapterPosition)
|
notifyItemChanged(holder.adapterPosition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
override fun onDoubleTap(e: MotionEvent): Boolean {
|
|
||||||
getItem(holder.adapterPosition)?.let { doubleTapIntent.onNext(it.id) }
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// return false: don't consume, so swipe-to-react (ItemTouchHelper) keeps working
|
|
||||||
view.setOnTouchListener { _, e -> gestureDetector.onTouchEvent(e); false }
|
|
||||||
|
|
||||||
// long-press enters/extends message selection mode
|
// long-press enters/extends message selection mode
|
||||||
view.setOnLongClickListener {
|
view.setOnLongClickListener {
|
||||||
|
|||||||
+1
-1
@@ -69,7 +69,7 @@ class MessageSwipeActionsPresenter @Inject constructor(
|
|||||||
|
|
||||||
@DrawableRes
|
@DrawableRes
|
||||||
private fun iconForAction(action: Int) = when (action) {
|
private fun iconForAction(action: Int) = when (action) {
|
||||||
Preferences.MESSAGE_SWIPE_ACTION_REACT -> R.drawable.message_emoji
|
Preferences.MESSAGE_SWIPE_ACTION_REACT -> R.drawable.ic_favorite_black_24dp
|
||||||
Preferences.MESSAGE_SWIPE_ACTION_REPLY -> R.drawable.ic_reply_white_24dp
|
Preferences.MESSAGE_SWIPE_ACTION_REPLY -> R.drawable.ic_reply_white_24dp
|
||||||
Preferences.MESSAGE_SWIPE_ACTION_COPY -> R.drawable.ic_content_copy_black_24dp
|
Preferences.MESSAGE_SWIPE_ACTION_COPY -> R.drawable.ic_content_copy_black_24dp
|
||||||
Preferences.MESSAGE_SWIPE_ACTION_FORWARD -> R.drawable.ic_forward_black_24dp
|
Preferences.MESSAGE_SWIPE_ACTION_FORWARD -> R.drawable.ic_forward_black_24dp
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@ import androidx.annotation.DrawableRes
|
|||||||
import dev.octoshrimpy.quik.R
|
import dev.octoshrimpy.quik.R
|
||||||
|
|
||||||
data class MessageSwipeActionsState(
|
data class MessageSwipeActionsState(
|
||||||
@DrawableRes val rightIcon: Int = R.drawable.message_emoji,
|
@DrawableRes val rightIcon: Int = R.drawable.ic_favorite_black_24dp,
|
||||||
val rightLabel: String = "",
|
val rightLabel: String = "",
|
||||||
|
|
||||||
@DrawableRes val leftIcon: Int = R.drawable.ic_reply_white_24dp,
|
@DrawableRes val leftIcon: Int = R.drawable.ic_reply_white_24dp,
|
||||||
|
|||||||
@@ -163,7 +163,7 @@
|
|||||||
android:id="@+id/defaultReaction"
|
android:id="@+id/defaultReaction"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:icon="@drawable/message_emoji"
|
app:icon="@drawable/ic_favorite_black_24dp"
|
||||||
app:title="@string/settings_default_reaction_title" />
|
app:title="@string/settings_default_reaction_title" />
|
||||||
|
|
||||||
<dev.octoshrimpy.quik.common.widget.PreferenceView
|
<dev.octoshrimpy.quik.common.widget.PreferenceView
|
||||||
|
|||||||
Reference in New Issue
Block a user