mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-16 19:18:52 +01:00
#1067 - Fix long-clicks for messages with links
This commit is contained in:
@@ -22,6 +22,7 @@ import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.PorterDuff
|
||||
import android.os.Build
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.EditText
|
||||
@@ -55,3 +56,36 @@ fun View.setVisible(visible: Boolean, invisible: Int = View.GONE) {
|
||||
visibility = if (visible) View.VISIBLE else invisible
|
||||
}
|
||||
|
||||
/**
|
||||
* If a view captures clicks at all, then the parent won't ever receive touch events. This is a
|
||||
* problem when we're trying to capture link clicks, but tapping or long pressing other areas of
|
||||
* the view no longer work. Also problematic when we try to long press on an image in the message
|
||||
* view
|
||||
*/
|
||||
fun View.forwardTouches(parent: View) {
|
||||
var isLongClick = false
|
||||
|
||||
setOnLongClickListener {
|
||||
isLongClick = true
|
||||
true
|
||||
}
|
||||
|
||||
setOnTouchListener { v, event ->
|
||||
parent.onTouchEvent(event)
|
||||
|
||||
when {
|
||||
event.action == MotionEvent.ACTION_UP && isLongClick -> {
|
||||
isLongClick = true
|
||||
true
|
||||
}
|
||||
|
||||
event.action == MotionEvent.ACTION_DOWN -> {
|
||||
isLongClick = false
|
||||
v.onTouchEvent(event)
|
||||
}
|
||||
|
||||
else -> v.onTouchEvent(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.jakewharton.rxbinding2.view.RxView
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.jakewharton.rxbinding2.view.longClicks
|
||||
import com.moez.QKSMS.R
|
||||
import common.Navigator
|
||||
import common.base.QkRealmAdapter
|
||||
@@ -40,6 +39,7 @@ import common.util.Colors
|
||||
import common.util.DateFormatter
|
||||
import common.util.GlideApp
|
||||
import common.util.extensions.dpToPx
|
||||
import common.util.extensions.forwardTouches
|
||||
import common.util.extensions.setBackgroundTint
|
||||
import common.util.extensions.setPadding
|
||||
import common.util.extensions.setVisible
|
||||
@@ -128,6 +128,8 @@ class MessagesAdapter @Inject constructor(
|
||||
.subscribe { color -> view.body.setBackgroundTint(color) }
|
||||
}
|
||||
|
||||
view.body.forwardTouches(view)
|
||||
|
||||
return QkViewHolder(view)
|
||||
}
|
||||
|
||||
@@ -149,6 +151,8 @@ class MessagesAdapter @Inject constructor(
|
||||
}
|
||||
RxView.longClicks(view).subscribe { longClicks.onNext(message) }
|
||||
|
||||
|
||||
// Bind the message status
|
||||
bindStatus(viewHolder, position)
|
||||
|
||||
|
||||
@@ -211,7 +215,7 @@ class MessagesAdapter @Inject constructor(
|
||||
media.forEachIndexed { index, part ->
|
||||
val mediaView = layoutInflater.inflate(R.layout.mms_preview_list_item, view.attachments, false)
|
||||
mediaView.video.setVisible(part.isVideo())
|
||||
mediaView.longClicks().subscribe { longClicks.onNext(message) }
|
||||
mediaView.forwardTouches(view)
|
||||
mediaView.clicks().subscribe {
|
||||
when {
|
||||
part.isImage() -> navigator.showImage(part.id)
|
||||
|
||||
Reference in New Issue
Block a user