From 2d2a5e26f68a010d6012eeb8f00283bb33cdf07d Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 25 Nov 2024 14:49:52 +0100 Subject: [PATCH] Automatically play next message voice record, if any --- CHANGELOG.md | 1 + .../chat/fragment/ConversationFragment.kt | 24 +++++++++++++++++++ .../ui/main/chat/model/EventLogModel.kt | 6 +++-- .../ui/main/chat/model/MessageModel.kt | 4 +++- .../chat/viewmodel/ConversationViewModel.kt | 7 ++++++ 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 456b10a0d..4469ba211 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ Group changes to describe their impact on the project, as follows: - Media & documents exchanged in a conversation can be easily found through a dedicated screen. - A brand new chat message search feature has been added to conversations. - You can now react to a chat message using any emoji. +- If next message is also a voice recording, playback will automatically start after the currently playing one ends. - Chat while in call: a shortcut to a conversation screen with the remote. - Chat while in a conference: if the conference has a text stream enabled, you can chat with the other participants of the conference while it lasts. At the end, you'll find the messages history in the call history (and not in the list of conversations). - Screen sharing in conference: only desktop app starting with 6.0 version is able to start it, but on mobiles you'll be able to see it. diff --git a/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationFragment.kt b/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationFragment.kt index d27096a2f..95d31e7f9 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationFragment.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationFragment.kt @@ -502,6 +502,30 @@ open class ConversationFragment : SlidingPaneChildFragment() { } } + viewModel.voiceRecordPlaybackEndedEvent.observe(viewLifecycleOwner) { + it.consume { id -> + Log.i( + "$TAG Voice record playback finished, looking for voice record in next message" + ) + val list = viewModel.eventsList + val model = list.find { + (it.model as? MessageModel)?.id == id + } + if (model != null) { + val index = list.indexOf(model) + if (index < list.size - 1) { + val nextModel = list[index + 1].model as? MessageModel + if (nextModel?.isVoiceRecord?.value == true) { + Log.i( + "$TAG Next message model is also a voice record, start playing it" + ) + nextModel.togglePlayPauseVoiceRecord() + } + } + } + } + } + viewModel.updateEvents.observe(viewLifecycleOwner) { it.consume { val items = viewModel.eventsList diff --git a/app/src/main/java/org/linphone/ui/main/chat/model/EventLogModel.kt b/app/src/main/java/org/linphone/ui/main/chat/model/EventLogModel.kt index c01913fb0..527ae23a3 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/model/EventLogModel.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/model/EventLogModel.kt @@ -35,7 +35,8 @@ class EventLogModel @WorkerThread constructor( onJoinConferenceClicked: ((uri: String) -> Unit)? = null, onWebUrlClicked: ((url: String) -> Unit)? = null, onContactClicked: ((friendRefKey: String) -> Unit)? = null, - onRedToastToShow: ((pair: Pair) -> Unit)? = null + onRedToastToShow: ((pair: Pair) -> Unit)? = null, + onVoiceRecordingPlaybackEnded: ((id: String) -> Unit)? = null ) { companion object { private const val TAG = "[Event Log Model]" @@ -85,7 +86,8 @@ class EventLogModel @WorkerThread constructor( onJoinConferenceClicked, onWebUrlClicked, onContactClicked, - onRedToastToShow + onRedToastToShow, + onVoiceRecordingPlaybackEnded ) } diff --git a/app/src/main/java/org/linphone/ui/main/chat/model/MessageModel.kt b/app/src/main/java/org/linphone/ui/main/chat/model/MessageModel.kt index d562c516c..e2b930107 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/model/MessageModel.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/model/MessageModel.kt @@ -79,7 +79,8 @@ class MessageModel @WorkerThread constructor( private val onJoinConferenceClicked: ((uri: String) -> Unit)? = null, private val onWebUrlClicked: ((url: String) -> Unit)? = null, private val onContactClicked: ((friendRefKey: String) -> Unit)? = null, - private val onRedToastToShow: ((pair: Pair) -> Unit)? = null + private val onRedToastToShow: ((pair: Pair) -> Unit)? = null, + private val onVoiceRecordingPlaybackEnded: ((id: String) -> Unit)? = null ) { companion object { private const val TAG = "[Message Model]" @@ -182,6 +183,7 @@ class MessageModel @WorkerThread constructor( private val playerListener = PlayerListener { Log.i("$TAG End of file reached") stopVoiceRecordPlayer() + onVoiceRecordingPlaybackEnded?.invoke(id) } // End of voice record related fields diff --git a/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationViewModel.kt b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationViewModel.kt index 2f3108acf..e6fd16b83 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationViewModel.kt @@ -130,6 +130,10 @@ class ConversationViewModel @UiThread constructor() : AbstractConversationViewMo MutableLiveData>() } + val voiceRecordPlaybackEndedEvent: MutableLiveData> by lazy { + MutableLiveData>() + } + var eventsList = arrayListOf() var pendingForwardMessage: MessageModel? = null @@ -752,6 +756,9 @@ class ConversationViewModel @UiThread constructor() : AbstractConversationViewMo }, { redToast -> showRedToastEvent.postValue(Event(redToast)) + }, + { id -> + voiceRecordPlaybackEndedEvent.postValue(Event(id)) } ) eventsList.add(model)