Merge pull request #4620 from vector-im/feature/adm/duplicate-long-press

Avoiding duplicate message long press events
This commit is contained in:
Benoit Marty 2021-12-02 19:44:42 +01:00 committed by GitHub
commit f9a88db2f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 2 deletions

1
changelog.d/4324.bugfix Normal file
View File

@ -0,0 +1 @@
Fixes message menu showing when copying message urls

View File

@ -17,6 +17,7 @@
package im.vector.app.core.epoxy
import android.view.View
import android.widget.TextView
import im.vector.app.core.utils.DebouncedClickListener
/**
@ -32,6 +33,26 @@ fun View.onClick(listener: ClickListener?) {
}
}
fun TextView.onLongClickIgnoringLinks(listener: View.OnLongClickListener?) {
if (listener == null) {
setOnLongClickListener(null)
} else {
setOnLongClickListener(object : View.OnLongClickListener {
override fun onLongClick(v: View): Boolean {
if (hasLongPressedLink()) {
return false
}
return listener.onLongClick(v)
}
/**
* Infer that a Clickable span has been click by the presence of a selection
*/
private fun hasLongPressedLink() = selectionStart != -1 || selectionEnd != -1
})
}
}
/**
* Simple Text listener lambda
*/

View File

@ -25,6 +25,7 @@ import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.epoxy.onLongClickIgnoringLinks
import im.vector.app.features.home.room.detail.timeline.TimelineEventController
import im.vector.app.features.home.room.detail.timeline.tools.findPillsAndProcess
import im.vector.app.features.home.room.detail.timeline.url.PreviewUrlRetriever
@ -94,10 +95,9 @@ abstract class MessageTextItem : AbsMessageItem<MessageTextItem.Holder>() {
}
super.bind(holder)
holder.messageView.movementMethod = movementMethod
renderSendState(holder.messageView, holder.messageView)
holder.messageView.onClick(attributes.itemClickListener)
holder.messageView.setOnLongClickListener(attributes.itemLongClickListener)
holder.messageView.onLongClickIgnoringLinks(attributes.itemLongClickListener)
if (canUseTextFuture) {
holder.messageView.setTextFuture(textFuture)
@ -133,6 +133,7 @@ abstract class MessageTextItem : AbsMessageItem<MessageTextItem.Holder>() {
previewUrlView?.render(state, safeImageContentRenderer)
}
}
companion object {
private const val STUB_ID = R.id.messageContentTextStub
}