From 049f63b61e62210779eb0c4550f34e2a02996140 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Wed, 18 Dec 2024 22:07:25 +0100 Subject: [PATCH] Added icon next to last message in conversations list depending on it's content --- .../ui/main/chat/model/ConversationModel.kt | 40 +++++++++++++++++-- app/src/main/res/layout/chat_list_cell.xml | 7 ++-- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/linphone/ui/main/chat/model/ConversationModel.kt b/app/src/main/java/org/linphone/ui/main/chat/model/ConversationModel.kt index 5324963ee..8da2b98d2 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/model/ConversationModel.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/model/ConversationModel.kt @@ -36,6 +36,7 @@ import org.linphone.core.Friend import org.linphone.core.tools.Log import org.linphone.ui.main.contacts.model.ContactAvatarModel import org.linphone.utils.AppUtils +import org.linphone.utils.FileUtils import org.linphone.utils.LinphoneUtils import org.linphone.utils.ShortcutUtils import org.linphone.utils.TimestampUtils @@ -77,9 +78,9 @@ class ConversationModel val lastMessageText = MutableLiveData() - val lastMessageIcon = MutableLiveData() + val lastMessageDeliveryIcon = MutableLiveData() - val isLastMessageForwarded = MutableLiveData() + val lastMessageContentIcon = MutableLiveData() val isLastMessageOutgoing = MutableLiveData() @@ -186,6 +187,7 @@ class ConversationModel Log.d( "$TAG Ephemeral messages are [${if (chatRoom.isEphemeralEnabled) "enabled" else "disabled"}], lifetime is [${chatRoom.ephemeralLifetime}]" ) + lastMessageContentIcon.postValue(0) updateLastMessage() updateLastUpdatedTime() @@ -292,9 +294,36 @@ class ConversationModel isLastMessageOutgoing.postValue(isOutgoing) if (isOutgoing) { - lastMessageIcon.postValue(LinphoneUtils.getChatIconResId(message.state)) + lastMessageDeliveryIcon.postValue(LinphoneUtils.getChatIconResId(message.state)) + } + + if (message.isForward) { + lastMessageContentIcon.postValue(R.drawable.forward) + } else { + val firstContent = message.contents.firstOrNull() + val icon = if (firstContent?.isIcalendar == true) { + R.drawable.calendar + } else if (firstContent?.isVoiceRecording == true) { + R.drawable.waveform + } else if (firstContent?.isFile == true) { + val mime = "${firstContent.type}/${firstContent.subtype}" + val mimeType = FileUtils.getMimeType(mime) + val drawable = when (mimeType) { + FileUtils.MimeType.Image -> R.drawable.file_image + FileUtils.MimeType.Video -> R.drawable.file_video + FileUtils.MimeType.Audio -> R.drawable.file_audio + FileUtils.MimeType.Pdf -> R.drawable.file_pdf + FileUtils.MimeType.PlainText -> R.drawable.file_text + else -> R.drawable.file + } + drawable + } else if (firstContent?.isFileTransfer == true) { + R.drawable.download_simple + } else { + 0 + } + lastMessageContentIcon.postValue(icon) } - isLastMessageForwarded.postValue(message.isForward) } @WorkerThread @@ -309,6 +338,9 @@ class ConversationModel if (message.isOutgoing && message.state != ChatMessage.State.Displayed) { message.addListener(chatMessageListener) lastMessage = message + } else if (message.contents.find { it.isFileTransfer == true } != null) { + message.addListener(chatMessageListener) + lastMessage = message } } else { Log.w("$TAG No last message to display for conversation [$id]") diff --git a/app/src/main/res/layout/chat_list_cell.xml b/app/src/main/res/layout/chat_list_cell.xml index cb6250bbb..74dbd8502 100644 --- a/app/src/main/res/layout/chat_list_cell.xml +++ b/app/src/main/res/layout/chat_list_cell.xml @@ -104,9 +104,10 @@ android:layout_marginStart="@{model.lastMessageTextSender.length() > 0 ? @dimen/five : @dimen/zero}" android:layout_marginEnd="5dp" android:layout_marginTop="3dp" - android:src="@drawable/forward" - android:visibility="@{model.isLastMessageForwarded ? View.VISIBLE : View.GONE, default=gone}" + android:src="@{model.lastMessageContentIcon, default=@drawable/forward}" + android:visibility="@{model.lastMessageContentIcon > 0 && !model.isComposing ? View.VISIBLE : View.GONE}" android:contentDescription="@null" + app:tint="?attr/color_main2_600" app:layout_constraintStart_toEndOf="@id/last_message_sender" app:layout_constraintEnd_toStartOf="@id/last_message_or_composing" app:layout_constraintTop_toTopOf="@id/last_message_or_composing" @@ -164,7 +165,7 @@ android:layout_height="@dimen/small_icon_size" android:layout_marginEnd="10dp" android:contentDescription="@string/content_description_chat_bubble_delivery_status" - android:src="@{model.lastMessageIcon, default=@drawable/animated_in_progress}" + android:src="@{model.lastMessageDeliveryIcon, default=@drawable/animated_in_progress}" android:visibility="@{model.isLastMessageOutgoing ? View.VISIBLE : View.GONE}" app:layout_constraintEnd_toStartOf="@id/notifications_count" app:layout_constraintTop_toBottomOf="@id/date_time"