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.chat.data.OnContentClickedListener
|
||||||
import org.linphone.activities.main.viewmodels.ListTopBarViewModel
|
import org.linphone.activities.main.viewmodels.ListTopBarViewModel
|
||||||
import org.linphone.core.*
|
import org.linphone.core.*
|
||||||
|
import org.linphone.core.tools.Log
|
||||||
import org.linphone.databinding.ChatEventListCellBinding
|
import org.linphone.databinding.ChatEventListCellBinding
|
||||||
import org.linphone.databinding.ChatMessageListCellBinding
|
import org.linphone.databinding.ChatMessageListCellBinding
|
||||||
import org.linphone.databinding.ChatMessageLongPressMenuBindingImpl
|
import org.linphone.databinding.ChatMessageLongPressMenuBindingImpl
|
||||||
|
@ -86,6 +87,10 @@ class ChatMessagesListAdapter(
|
||||||
MutableLiveData<Event<Content>>()
|
MutableLiveData<Event<Content>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val urlClickEvent: MutableLiveData<Event<String>> by lazy {
|
||||||
|
MutableLiveData<Event<String>>()
|
||||||
|
}
|
||||||
|
|
||||||
val sipUriClickedEvent: MutableLiveData<Event<String>> by lazy {
|
val sipUriClickedEvent: MutableLiveData<Event<String>> by lazy {
|
||||||
MutableLiveData<Event<String>>()
|
MutableLiveData<Event<String>>()
|
||||||
}
|
}
|
||||||
|
@ -107,7 +112,19 @@ class ChatMessagesListAdapter(
|
||||||
openContentEvent.value = Event(content)
|
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) {
|
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)
|
sipUriClickedEvent.value = Event(sipUri)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,6 +138,7 @@ class ChatMessagesListAdapter(
|
||||||
}
|
}
|
||||||
|
|
||||||
private var advancedContextMenuOptionsDisabled: Boolean = false
|
private var advancedContextMenuOptionsDisabled: Boolean = false
|
||||||
|
private var popup: PopupWindow? = null
|
||||||
|
|
||||||
private var unreadMessagesCount: Int = 0
|
private var unreadMessagesCount: Int = 0
|
||||||
private var firstUnreadMessagePosition: Int = -1
|
private var firstUnreadMessagePosition: Int = -1
|
||||||
|
@ -330,6 +348,8 @@ class ChatMessagesListAdapter(
|
||||||
totalSize,
|
totalSize,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
popup = popupWindow
|
||||||
|
|
||||||
// Elevation is for showing a shadow around the popup
|
// Elevation is for showing a shadow around the popup
|
||||||
popupWindow.elevation = 20f
|
popupWindow.elevation = 20f
|
||||||
|
|
||||||
|
|
|
@ -473,6 +473,8 @@ interface OnContentClickedListener {
|
||||||
|
|
||||||
fun onSipAddressClicked(sipUri: String)
|
fun onSipAddressClicked(sipUri: String)
|
||||||
|
|
||||||
|
fun onWebUrlClicked(url: String)
|
||||||
|
|
||||||
fun onCallConference(address: String, subject: String?)
|
fun onCallConference(address: String, subject: String?)
|
||||||
|
|
||||||
fun onError(messageId: Int)
|
fun onError(messageId: Int)
|
||||||
|
|
|
@ -21,8 +21,7 @@ package org.linphone.activities.main.chat.data
|
||||||
|
|
||||||
import android.os.CountDownTimer
|
import android.os.CountDownTimer
|
||||||
import android.text.Spannable
|
import android.text.Spannable
|
||||||
import android.text.util.Linkify
|
import android.util.Patterns
|
||||||
import androidx.core.text.util.LinkifyCompat
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
import org.linphone.R
|
import org.linphone.R
|
||||||
|
@ -189,7 +188,6 @@ class ChatMessageData(val chatMessage: ChatMessage) : GenericContactData(chatMes
|
||||||
list.add(data)
|
list.add(data)
|
||||||
} else if (content.isText) {
|
} else if (content.isText) {
|
||||||
val spannable = Spannable.Factory.getInstance().newSpannable(content.utf8Text?.trim())
|
val spannable = Spannable.Factory.getInstance().newSpannable(content.utf8Text?.trim())
|
||||||
LinkifyCompat.addLinks(spannable, Linkify.WEB_URLS or Linkify.PHONE_NUMBERS)
|
|
||||||
text.value = PatternClickableSpan()
|
text.value = PatternClickableSpan()
|
||||||
.add(
|
.add(
|
||||||
Pattern.compile("(?:<?sips?:)?[^@\\s]+(?:@([^\\s]+))+"),
|
Pattern.compile("(?:<?sips?:)?[^@\\s]+(?:@([^\\s]+))+"),
|
||||||
|
@ -199,6 +197,24 @@ class ChatMessageData(val chatMessage: ChatMessage) : GenericContactData(chatMes
|
||||||
contentListener?.onSipAddressClicked(text)
|
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)
|
).build(spannable)
|
||||||
} else {
|
} else {
|
||||||
Log.e("[Chat Message Data] Unexpected content with type: ${content.type}/${content.subtype}")
|
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.app.Dialog
|
||||||
import android.content.*
|
import android.content.*
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import android.provider.MediaStore
|
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(
|
adapter.sipUriClickedEvent.observe(
|
||||||
viewLifecycleOwner
|
viewLifecycleOwner
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -11,7 +11,7 @@ buildscript {
|
||||||
} // for com.github.chrisbanes:PhotoView
|
} // for com.github.chrisbanes:PhotoView
|
||||||
}
|
}
|
||||||
dependencies {
|
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 'com.google.gms:google-services:4.3.13'
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0"
|
||||||
classpath "org.jlleitschuh.gradle:ktlint-gradle:10.1.0"
|
classpath "org.jlleitschuh.gradle:ktlint-gradle:10.1.0"
|
||||||
|
|
Loading…
Reference in a new issue