mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 19:38:08 +00:00
Added click on web links to open browser in chat bubble
This commit is contained in:
parent
1c7fe3fd3e
commit
d895fc6a09
4 changed files with 42 additions and 3 deletions
|
|
@ -23,10 +23,12 @@ import android.app.Dialog
|
|||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.RenderEffect
|
||||
import android.graphics.Shader
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
|
|
@ -298,6 +300,20 @@ class ConversationFragment : GenericFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
viewModel.openWebBrowserEvent.observe(viewLifecycleOwner) {
|
||||
it.consume { url ->
|
||||
Log.i("$TAG Requesting to open web browser on page [$url]")
|
||||
try {
|
||||
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
startActivity(browserIntent)
|
||||
} catch (ise: IllegalStateException) {
|
||||
Log.e(
|
||||
"$TAG Can't start ACTION_VIEW intent for URL [$url], IllegalStateException: $ise"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
binding.root.setKeyboardInsetListener { keyboardVisible ->
|
||||
if (keyboardVisible) {
|
||||
viewModel.isEmojiPickerOpen.value = false
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ package org.linphone.ui.main.chat.model
|
|||
import android.text.Spannable
|
||||
import android.text.SpannableStringBuilder
|
||||
import android.text.Spanned
|
||||
import android.util.Patterns
|
||||
import androidx.annotation.UiThread
|
||||
import androidx.annotation.WorkerThread
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
|
|
@ -54,7 +55,8 @@ class ChatMessageModel @WorkerThread constructor(
|
|||
val isGroupedWithPreviousOne: Boolean,
|
||||
val isGroupedWithNextOne: Boolean,
|
||||
private val onContentClicked: ((file: String) -> Unit)? = null,
|
||||
private val onJoinConferenceClicked: ((uri: String) -> Unit)? = null
|
||||
private val onJoinConferenceClicked: ((uri: String) -> Unit)? = null,
|
||||
private val onWebUrlClicked: ((url: String) -> Unit)? = null
|
||||
) {
|
||||
companion object {
|
||||
private const val TAG = "[Chat Message Model]"
|
||||
|
|
@ -318,6 +320,15 @@ class ChatMessageModel @WorkerThread constructor(
|
|||
}
|
||||
}
|
||||
)
|
||||
.add(
|
||||
Patterns.WEB_URL,
|
||||
object : SpannableClickedListener {
|
||||
override fun onSpanClicked(text: String) {
|
||||
Log.i("$TAG Clicked on web URL: $text")
|
||||
onWebUrlClicked?.invoke(text)
|
||||
}
|
||||
}
|
||||
)
|
||||
.build(spannableBuilder)
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,8 @@ class EventLogModel @WorkerThread constructor(
|
|||
isGroupedWithPreviousOne: Boolean,
|
||||
isGroupedWithNextOne: Boolean,
|
||||
onContentClicked: ((file: String) -> Unit)? = null,
|
||||
onJoinConferenceClicked: ((uri: String) -> Unit)? = null
|
||||
onJoinConferenceClicked: ((uri: String) -> Unit)? = null,
|
||||
onWebUrlClicked: ((url: String) -> Unit)? = null
|
||||
) {
|
||||
companion object {
|
||||
private const val TAG = "[Event Log Model]"
|
||||
|
|
@ -78,7 +79,8 @@ class EventLogModel @WorkerThread constructor(
|
|||
isGroupedWithPreviousOne,
|
||||
isGroupedWithNextOne,
|
||||
onContentClicked,
|
||||
onJoinConferenceClicked
|
||||
onJoinConferenceClicked,
|
||||
onWebUrlClicked
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -94,6 +94,10 @@ class ConversationViewModel @UiThread constructor() : ViewModel() {
|
|||
MutableLiveData<Event<String>>()
|
||||
}
|
||||
|
||||
val openWebBrowserEvent: MutableLiveData<Event<String>> by lazy {
|
||||
MutableLiveData<Event<String>>()
|
||||
}
|
||||
|
||||
val chatRoomFoundEvent = MutableLiveData<Event<Boolean>>()
|
||||
|
||||
lateinit var chatRoom: ChatRoom
|
||||
|
|
@ -130,6 +134,9 @@ class ConversationViewModel @UiThread constructor() : ViewModel() {
|
|||
},
|
||||
{ conferenceUri ->
|
||||
conferenceToJoinEvent.postValue(Event(conferenceUri))
|
||||
},
|
||||
{ url ->
|
||||
openWebBrowserEvent.postValue(Event(url))
|
||||
}
|
||||
)
|
||||
)
|
||||
|
|
@ -431,6 +438,9 @@ class ConversationViewModel @UiThread constructor() : ViewModel() {
|
|||
},
|
||||
{ conferenceUri ->
|
||||
conferenceToJoinEvent.postValue(Event(conferenceUri))
|
||||
},
|
||||
{ url ->
|
||||
openWebBrowserEvent.postValue(Event(url))
|
||||
}
|
||||
)
|
||||
eventsList.add(model)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue