Added navigating to a mentionned contact on click in chat bubble + low media volume alert when playing voice recording in chat bubble

This commit is contained in:
Sylvain Berfini 2023-12-18 11:54:59 +01:00
parent 4bf0a2fa5d
commit f702054ac4
5 changed files with 58 additions and 7 deletions

View file

@ -524,6 +524,22 @@ class ConversationFragment : SlidingPaneChildFragment() {
}
}
viewModel.contactToDisplayEvent.observe(viewLifecycleOwner) {
it.consume { friendRefKey ->
Log.i("$TAG Navigating to contact with ref key [$friendRefKey]")
sharedViewModel.navigateToContactsEvent.value = Event(true)
sharedViewModel.showContactEvent.value = Event(friendRefKey)
}
}
viewModel.showRedToastEvent.observe(viewLifecycleOwner) {
it.consume { pair ->
val message = pair.first
val icon = pair.second
(requireActivity() as MainActivity).showRedToast(message, icon)
}
}
sharedViewModel.richContentUri.observe(
viewLifecycleOwner
) {

View file

@ -34,7 +34,9 @@ class EventLogModel @WorkerThread constructor(
isGroupedWithNextOne: Boolean = false,
onContentClicked: ((file: String) -> Unit)? = null,
onJoinConferenceClicked: ((uri: String) -> Unit)? = null,
onWebUrlClicked: ((url: String) -> Unit)? = null
onWebUrlClicked: ((url: String) -> Unit)? = null,
onContactClicked: ((friendRefKey: String) -> Unit)? = null,
onRedToastToShow: ((pair: Pair<String, Int>) -> Unit)? = null
) {
companion object {
private const val TAG = "[Event Log Model]"
@ -83,7 +85,9 @@ class EventLogModel @WorkerThread constructor(
isGroupedWithNextOne,
onContentClicked,
onJoinConferenceClicked,
onWebUrlClicked
onWebUrlClicked,
onContactClicked,
onRedToastToShow
)
}

View file

@ -71,7 +71,9 @@ class MessageModel @WorkerThread constructor(
isGroupedWithNextOne: Boolean,
private val onContentClicked: ((file: String) -> Unit)? = null,
private val onJoinConferenceClicked: ((uri: String) -> Unit)? = null,
private val onWebUrlClicked: ((url: String) -> Unit)? = null
private val onWebUrlClicked: ((url: String) -> Unit)? = null,
private val onContactClicked: ((friendRefKey: String) -> Unit)? = null,
private val onRedToastToShow: ((pair: Pair<String, Int>) -> Unit)? = null
) {
companion object {
private const val TAG = "[Message Model]"
@ -487,17 +489,27 @@ class MessageModel @WorkerThread constructor(
}
// Find display name for address
if (address != null) {
val displayName = coreContext.contactsManager.findDisplayName(address)
val avatarModel = coreContext.contactsManager.getContactAvatarModelForAddress(
address
)
val friend = avatarModel.friend
val displayName = friend.name ?: LinphoneUtils.getDisplayName(address)
Log.d(
"$TAG Using display name [$displayName] instead of username [$source]"
)
spannableBuilder.replace(start, end, "@$displayName")
val span = PatternClickableSpan.StyledClickableSpan(
object :
SpannableClickedListener {
override fun onSpanClicked(text: String) {
Log.i("$TAG Clicked on [$text] span")
// TODO: go to contact page if not ourselves
val friendRefKey = friend.refKey ?: ""
Log.i(
"$TAG Clicked on [$text] span, matching friend ref key is [$friendRefKey]"
)
if (friendRefKey.isNotEmpty()) {
onContactClicked?.invoke(friendRefKey)
}
}
}
)
@ -631,8 +643,12 @@ class MessageModel @WorkerThread constructor(
initVoiceRecordPlayer()
}
// TODO: check media volume
val lowMediaVolume = AudioUtils.isMediaVolumeLow(coreContext.context)
if (lowMediaVolume) {
Log.w("$TAG Media volume is low, notifying user as they may not hear voice message")
val message = AppUtils.getString(R.string.toast_low_media_volume)
onRedToastToShow?.invoke(Pair(message, R.drawable.speaker_slash))
}
if (voiceRecordAudioFocusRequest == null) {
voiceRecordAudioFocusRequest = AudioUtils.acquireAudioFocusForVoiceRecordingOrPlayback(

View file

@ -87,6 +87,14 @@ class ConversationViewModel @UiThread constructor() : ViewModel() {
MutableLiveData<Event<String>>()
}
val contactToDisplayEvent: MutableLiveData<Event<String>> by lazy {
MutableLiveData<Event<String>>()
}
val showRedToastEvent: MutableLiveData<Event<Pair<String, Int>>> by lazy {
MutableLiveData<Event<Pair<String, Int>>>()
}
val chatRoomFoundEvent = MutableLiveData<Event<Boolean>>()
lateinit var chatRoom: ChatRoom
@ -473,6 +481,12 @@ class ConversationViewModel @UiThread constructor() : ViewModel() {
},
{ url ->
openWebBrowserEvent.postValue(Event(url))
},
{ friendRefKey ->
contactToDisplayEvent.postValue(Event(friendRefKey))
},
{ redToast ->
showRedToastEvent.postValue(Event(redToast))
}
)
eventsList.add(model)

View file

@ -573,6 +573,7 @@ class SendMessageInConversationViewModel @UiThread constructor() : ViewModel() {
val context = coreContext.context
val lowMediaVolume = AudioUtils.isMediaVolumeLow(context)
if (lowMediaVolume) {
Log.w("$TAG Media volume is low, notifying user as they may not hear voice message")
val message = AppUtils.getString(R.string.toast_low_media_volume)
showRedToastEvent.postValue(Event(Pair(message, R.drawable.speaker_slash)))
}