Fixed long press on chat message if spannable link if found below
This commit is contained in:
parent
e4c64a2b5b
commit
fb4019f5b9
5 changed files with 59 additions and 4 deletions
|
@ -41,6 +41,7 @@ import org.linphone.activities.main.chat.data.EventLogData
|
|||
import org.linphone.activities.main.chat.data.OnContentClickedListener
|
||||
import org.linphone.activities.main.viewmodels.ListTopBarViewModel
|
||||
import org.linphone.core.*
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.databinding.ChatEventListCellBinding
|
||||
import org.linphone.databinding.ChatMessageListCellBinding
|
||||
import org.linphone.databinding.ChatMessageLongPressMenuBindingImpl
|
||||
|
@ -86,6 +87,10 @@ class ChatMessagesListAdapter(
|
|||
MutableLiveData<Event<Content>>()
|
||||
}
|
||||
|
||||
val urlClickEvent: MutableLiveData<Event<String>> by lazy {
|
||||
MutableLiveData<Event<String>>()
|
||||
}
|
||||
|
||||
val sipUriClickedEvent: MutableLiveData<Event<String>> by lazy {
|
||||
MutableLiveData<Event<String>>()
|
||||
}
|
||||
|
@ -107,7 +112,19 @@ class ChatMessagesListAdapter(
|
|||
openContentEvent.value = Event(content)
|
||||
}
|
||||
|
||||
override fun onWebUrlClicked(url: String) {
|
||||
if (popup?.isShowing == true) {
|
||||
Log.w("[Chat Message Data] Long press that displayed context menu detected, aborting click on URL [$url]")
|
||||
return
|
||||
}
|
||||
urlClickEvent.value = Event(url)
|
||||
}
|
||||
|
||||
override fun onSipAddressClicked(sipUri: String) {
|
||||
if (popup?.isShowing == true) {
|
||||
Log.w("[Chat Message Data] Long press that displayed context menu detected, aborting click on SIP URI [$sipUri]")
|
||||
return
|
||||
}
|
||||
sipUriClickedEvent.value = Event(sipUri)
|
||||
}
|
||||
|
||||
|
@ -121,6 +138,7 @@ class ChatMessagesListAdapter(
|
|||
}
|
||||
|
||||
private var advancedContextMenuOptionsDisabled: Boolean = false
|
||||
private var popup: PopupWindow? = null
|
||||
|
||||
private var unreadMessagesCount: Int = 0
|
||||
private var firstUnreadMessagePosition: Int = -1
|
||||
|
@ -330,6 +348,8 @@ class ChatMessagesListAdapter(
|
|||
totalSize,
|
||||
true
|
||||
)
|
||||
popup = popupWindow
|
||||
|
||||
// Elevation is for showing a shadow around the popup
|
||||
popupWindow.elevation = 20f
|
||||
|
||||
|
|
|
@ -473,6 +473,8 @@ interface OnContentClickedListener {
|
|||
|
||||
fun onSipAddressClicked(sipUri: String)
|
||||
|
||||
fun onWebUrlClicked(url: String)
|
||||
|
||||
fun onCallConference(address: String, subject: String?)
|
||||
|
||||
fun onError(messageId: Int)
|
||||
|
|
|
@ -21,8 +21,7 @@ package org.linphone.activities.main.chat.data
|
|||
|
||||
import android.os.CountDownTimer
|
||||
import android.text.Spannable
|
||||
import android.text.util.Linkify
|
||||
import androidx.core.text.util.LinkifyCompat
|
||||
import android.util.Patterns
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import java.util.regex.Pattern
|
||||
import org.linphone.R
|
||||
|
@ -189,7 +188,6 @@ class ChatMessageData(val chatMessage: ChatMessage) : GenericContactData(chatMes
|
|||
list.add(data)
|
||||
} else if (content.isText) {
|
||||
val spannable = Spannable.Factory.getInstance().newSpannable(content.utf8Text?.trim())
|
||||
LinkifyCompat.addLinks(spannable, Linkify.WEB_URLS or Linkify.PHONE_NUMBERS)
|
||||
text.value = PatternClickableSpan()
|
||||
.add(
|
||||
Pattern.compile("(?:<?sips?:)?[^@\\s]+(?:@([^\\s]+))+"),
|
||||
|
@ -199,6 +197,24 @@ class ChatMessageData(val chatMessage: ChatMessage) : GenericContactData(chatMes
|
|||
contentListener?.onSipAddressClicked(text)
|
||||
}
|
||||
}
|
||||
)
|
||||
.add(
|
||||
Patterns.WEB_URL,
|
||||
object : PatternClickableSpan.SpannableClickedListener {
|
||||
override fun onSpanClicked(text: String) {
|
||||
Log.i("[Chat Message Data] Clicked on web URL: $text")
|
||||
contentListener?.onWebUrlClicked(text)
|
||||
}
|
||||
}
|
||||
)
|
||||
.add(
|
||||
Patterns.PHONE,
|
||||
object : PatternClickableSpan.SpannableClickedListener {
|
||||
override fun onSpanClicked(text: String) {
|
||||
Log.i("[Chat Message Data] Clicked on phone number: $text")
|
||||
contentListener?.onSipAddressClicked(text)
|
||||
}
|
||||
}
|
||||
).build(spannable)
|
||||
} else {
|
||||
Log.e("[Chat Message Data] Unexpected content with type: ${content.type}/${content.subtype}")
|
||||
|
|
|
@ -23,6 +23,7 @@ import android.app.Activity
|
|||
import android.app.Dialog
|
||||
import android.content.*
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.Parcelable
|
||||
import android.provider.MediaStore
|
||||
|
@ -496,6 +497,22 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
|
|||
}
|
||||
}
|
||||
|
||||
adapter.urlClickEvent.observe(
|
||||
viewLifecycleOwner
|
||||
) {
|
||||
it.consume { url ->
|
||||
val browserIntent = Intent(
|
||||
Intent.ACTION_VIEW,
|
||||
Uri.parse(url)
|
||||
)
|
||||
try {
|
||||
startActivity(browserIntent)
|
||||
} catch (se: SecurityException) {
|
||||
Log.e("[Chat Room] Failed to start browser intent, $se")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
adapter.sipUriClickedEvent.observe(
|
||||
viewLifecycleOwner
|
||||
) {
|
||||
|
|
|
@ -11,7 +11,7 @@ buildscript {
|
|||
} // for com.github.chrisbanes:PhotoView
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:7.2.2'
|
||||
classpath 'com.android.tools.build:gradle:7.3.0'
|
||||
classpath 'com.google.gms:google-services:4.3.13'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0"
|
||||
classpath "org.jlleitschuh.gradle:ktlint-gradle:10.1.0"
|
||||
|
|
Loading…
Reference in a new issue