From f6d4f56bbc8c2ea165ffaf20d09f7428e80f821f Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Sun, 29 Sep 2024 14:34:42 +0200 Subject: [PATCH] Fix voice record not playable if displayed before download terminated --- .../ui/main/chat/model/MessageModel.kt | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) 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 e61e04b42..a4ccc1679 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 @@ -209,6 +209,14 @@ class MessageModel @WorkerThread constructor( if (!allFilesDownloaded) { computeContentsList() } + + for (content in message.contents) { + if (content.isVoiceRecording) { + Log.i("$TAG File transfer done, updating voice record info") + computeVoiceRecordContent(content) + break + } + } } } @@ -390,16 +398,7 @@ class MessageModel @WorkerThread constructor( } else if (content.isVoiceRecording) { Log.d("$TAG Found voice recording content") isVoiceRecord.postValue(true) - voiceRecordPath = content.filePath ?: "" - - val duration = content.fileDuration - voiceRecordingDuration.postValue(duration) - - val formattedDuration = SimpleDateFormat( - "mm:ss", - Locale.getDefault() - ).format(duration) // duration is in ms - formattedVoiceRecordingDuration.postValue(formattedDuration) + computeVoiceRecordContent(content) displayableContentFound = true } else { if (content.isFile) { @@ -952,4 +951,21 @@ class MessageModel @WorkerThread constructor( } } } + + @WorkerThread + private fun computeVoiceRecordContent(content: Content) { + voiceRecordPath = content.filePath ?: "" + + val duration = content.fileDuration + voiceRecordingDuration.postValue(duration) + + val formattedDuration = SimpleDateFormat( + "mm:ss", + Locale.getDefault() + ).format(duration) // duration is in ms + formattedVoiceRecordingDuration.postValue(formattedDuration) + Log.i( + "$TAG Found voice record with path [$voiceRecordPath] and duration [$formattedDuration]" + ) + } }