Fixed received/sent audio files handled as voice recordings

This commit is contained in:
Sylvain Berfini 2024-01-29 12:30:52 +01:00
parent ce1d3d4807
commit a024dd2278
5 changed files with 34 additions and 13 deletions

View file

@ -31,6 +31,8 @@ class FileModel @AnyThread constructor(
val isPdf: Boolean
val isAudio: Boolean
init {
path.postValue(file)
downloadProgress.postValue(-1)
@ -44,6 +46,7 @@ class FileModel @AnyThread constructor(
mimeType = FileUtils.getMimeType(mime)
isImage = mimeType == FileUtils.MimeType.Image
isVideoPreview = mimeType == FileUtils.MimeType.Video
isAudio = mimeType == FileUtils.MimeType.Audio
Log.d(
"$TAG File has already been downloaded, extension is [$extension], MIME is [$mime]"
)
@ -52,6 +55,7 @@ class FileModel @AnyThread constructor(
isPdf = false
isImage = false
isVideoPreview = false
isAudio = false
}
}

View file

@ -307,10 +307,26 @@ class MessageModel @WorkerThread constructor(
if (content.isIcalendar) {
Log.d("$TAG Found iCal content")
parseConferenceInvite(content)
displayableContentFound = true
} else if (content.isText) {
Log.d("$TAG Found plain text content")
computeTextContent(content)
displayableContentFound = true
} 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)
displayableContentFound = true
} else {
if (content.isFile) {
@ -339,18 +355,6 @@ class MessageModel @WorkerThread constructor(
displayableContentFound = true
}
"audio" -> {
voiceRecordPath = path
isVoiceRecord.postValue(true)
val duration = content.fileDuration
voiceRecordingDuration.postValue(duration)
val formattedDuration = SimpleDateFormat(
"mm:ss",
Locale.getDefault()
).format(duration) // duration is in ms
formattedVoiceRecordingDuration.postValue(formattedDuration)
displayableContentFound = true
}
else -> {
val fileModel = FileModel(path, name, content.fileSize.toLong()) { model ->
onContentClicked?.invoke(model.file)

View file

@ -42,6 +42,8 @@ class FileViewModel @UiThread constructor() : ViewModel() {
val isImage = MutableLiveData<Boolean>()
val isAudio = MutableLiveData<Boolean>()
val isVideo = MutableLiveData<Boolean>()
val isVideoPlaying = MutableLiveData<Boolean>()
@ -121,7 +123,9 @@ class FileViewModel @UiThread constructor() : ViewModel() {
fileReadyEvent.value = Event(true)
}
FileUtils.MimeType.Audio -> {
Log.i("$TAG File [$file] seems to be an audio")
// TODO: handle audio files
isAudio.value = true
fileReadyEvent.value = Event(true)
}
FileUtils.MimeType.PlainText -> {

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="256"
android:viewportHeight="256">
<path
android:pathData="M99.06,128.61a8,8 0,0 0,-8.72 1.73L68.69,152L48,152a8,8 0,0 0,-8 8v40a8,8 0,0 0,8 8L68.69,208l21.65,21.66A8,8 0,0 0,104 224L104,136A8,8 0,0 0,99.06 128.61ZM88,204.69 L77.66,194.34A8,8 0,0 0,72 192L56,192L56,168L72,168a8,8 0,0 0,5.66 -2.34L88,155.31ZM152,180a40.55,40.55 0,0 1,-20 34.91A8,8 0,0 1,124 201.09a24.49,24.49 0,0 0,0 -42.18A8,8 0,0 1,132 145.09,40.55 40.55,0 0,1 152,180ZM213.66,82.34 L157.66,26.34A8,8 0,0 0,152 24L56,24A16,16 0,0 0,40 40v80a8,8 0,0 0,16 0L56,40h88L144,88a8,8 0,0 0,8 8h48L200,216L168,216a8,8 0,0 0,0 16h32a16,16 0,0 0,16 -16L216,88A8,8 0,0 0,213.66 82.34ZM160,51.31 L188.69,80L160,80Z"
android:fillColor="#4e6074"/>
</vector>

View file

@ -53,7 +53,7 @@
android:layout_height="@dimen/chat_bubble_grid_image_size"
android:adjustViewBounds="true"
android:padding="18dp"
android:src="@{model.isWaitingToBeDownloaded ? @drawable/download_simple : model.isPdf ? @drawable/file_pdf : @drawable/file, default=@drawable/file_pdf}"
android:src="@{model.isWaitingToBeDownloaded ? @drawable/download_simple : model.isPdf ? @drawable/file_pdf : model.isAudio ? @drawable/file_audio : @drawable/file, default=@drawable/file_pdf}"
android:background="@drawable/shape_squircle_main2_200_left"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"