Added IMDN status in chat rooms list for last message if outgoing + removed sender name in front of last message for 1-1 chat rooms

This commit is contained in:
Sylvain Berfini 2023-03-27 11:19:15 +02:00
parent 7136a991b3
commit 2fd0b87467
4 changed files with 68 additions and 18 deletions

View file

@ -60,6 +60,10 @@ class ChatRoomData(private val chatRoom: ChatRoom) : ContactDataInterface {
val lastMessageText = MutableLiveData<SpannableStringBuilder>()
val showLastMessageImdnIcon = MutableLiveData<Boolean>()
val lastMessageImdnIcon = MutableLiveData<Int>()
val notificationsMuted = MutableLiveData<Boolean>()
private val basicChatRoom: Boolean by lazy {
@ -160,14 +164,26 @@ class ChatRoomData(private val chatRoom: ChatRoom) : ContactDataInterface {
val builder = SpannableStringBuilder()
if (msg == null) {
lastMessageText.value = builder
showLastMessageImdnIcon.value = false
return
}
val sender: String =
coreContext.contactsManager.findContactByAddress(msg.fromAddress)?.name
?: LinphoneUtils.getDisplayName(msg.fromAddress)
builder.append(sender)
builder.append(": ")
if (msg.isOutgoing && msg.state != ChatMessage.State.Displayed) {
msg.addListener(object : ChatMessageListenerStub() {
override fun onMsgStateChanged(message: ChatMessage, state: ChatMessage.State) {
computeLastMessageImdnIcon(message)
}
})
}
computeLastMessageImdnIcon(msg)
if (!chatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt())) {
val sender: String =
coreContext.contactsManager.findContactByAddress(msg.fromAddress)?.name
?: LinphoneUtils.getDisplayName(msg.fromAddress)
builder.append(coreContext.context.getString(R.string.chat_room_last_message_sender_format, sender))
builder.append(" ")
}
for (content in msg.contents) {
if (content.isIcalendar) {
@ -189,6 +205,25 @@ class ChatRoomData(private val chatRoom: ChatRoom) : ContactDataInterface {
lastMessageText.value = builder
}
private fun computeLastMessageImdnIcon(msg: ChatMessage) {
val state = msg.state
showLastMessageImdnIcon.value = if (msg.isOutgoing) {
when (state) {
ChatMessage.State.DeliveredToUser, ChatMessage.State.Displayed,
ChatMessage.State.NotDelivered, ChatMessage.State.FileTransferError -> true
else -> false
}
} else {
false
}
lastMessageImdnIcon.value = when (state) {
ChatMessage.State.DeliveredToUser -> R.drawable.chat_delivered
ChatMessage.State.Displayed -> R.drawable.chat_read
ChatMessage.State.FileTransferError, ChatMessage.State.NotDelivered -> R.drawable.chat_error
else -> R.drawable.chat_error
}
}
private fun areNotificationsMuted(): Boolean {
val id = LinphoneUtils.getChatRoomId(chatRoom.localAddress, chatRoom.peerAddress)
return corePreferences.chatRoomMuted(id)

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
@ -42,7 +43,7 @@
coilContact="@{data}"
android:layout_width="@dimen/contact_avatar_size"
android:layout_height="@dimen/contact_avatar_size"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:contentDescription="@null"
android:background="@drawable/generated_avatar_bg"
android:src="@drawable/voip_single_contact_avatar"
@ -67,7 +68,7 @@
android:id="@+id/securityLevel"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginLeft="25dp"
android:layout_marginStart="25dp"
android:contentDescription="@{data.securityLevelContentDescription}"
android:src="@{data.securityLevelIcon, default=@drawable/security_alert_indicator}"
android:visibility="@{data.encryptedChatRoom ? View.VISIBLE : View.INVISIBLE, default=invisible}"
@ -86,15 +87,16 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@id/avatar"
app:layout_constraintEnd_toEndOf="@id/securityLevel"
app:layout_constraintTop_toBottomOf="@id/avatar" />
app:layout_constraintTop_toBottomOf="@id/avatar"
tools:ignore="RtlHardcoded,RtlSymmetry" />
<TextView
android:id="@+id/title"
style="@style/contact_name_list_cell_font"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="5dp"
android:singleLine="true"
android:ellipsize="end"
android:text="@{data.oneToOneChatRoom ? (data.contact.name ?? data.displayName) : data.subject, default=`Lorem Ipsum`}"
@ -102,17 +104,27 @@
app:layout_constraintEnd_toStartOf="@id/unread"
app:layout_constraintTop_toTopOf="@id/avatar" />
<ImageView
android:id="@+id/imdn"
android:layout_width="15dp"
android:layout_height="wrap_content"
android:paddingEnd="3dp"
android:contentDescription="@string/content_description_delivery_status"
android:src="@{data.lastMessageImdnIcon, default=@drawable/chat_delivered}"
android:visibility="@{data.showLastMessageImdnIcon ? View.VISIBLE : View.GONE}"
app:layout_constraintStart_toStartOf="@id/title"
app:layout_constraintTop_toTopOf="@id/lastMessage"/>
<TextView
android:id="@+id/lastMessage"
style="@style/standard_small_text_font"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_marginEnd="10dp"
android:ellipsize="end"
android:maxLines="2"
android:text="@{data.lastMessageText, default=`Lorem ipsum dolor sit amet`}"
app:layout_constraintStart_toEndOf="@id/date"
app:layout_constraintStart_toEndOf="@id/imdn"
app:layout_constraintEnd_toStartOf="@id/endBarrier"
app:layout_constraintTop_toBottomOf="@id/title" />
@ -130,7 +142,7 @@
android:id="@+id/muted"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:adjustViewBounds="true"
android:contentDescription="@string/content_description_muted_chat_room"
android:src="@drawable/chat_room_menu_mute_notifications"
@ -143,7 +155,7 @@
style="@style/unread_count_font"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:background="@drawable/unread_message_count_bg"
android:ellipsize="end"
android:gravity="center"
@ -157,7 +169,7 @@
android:id="@+id/ephemeral"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="5dp"
android:adjustViewBounds="true"
android:contentDescription="@string/content_description_ephemeral_chat_room"
@ -185,7 +197,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="left"
app:constraint_referenced_ids="ephemeral, muted, forward"/>
app:constraint_referenced_ids="ephemeral, muted, forward"
app:layout_constraintStart_toEndOf="@id/lastMessage"/>
<androidx.constraintlayout.widget.Barrier
android:id="@+id/endBarrier3"

View file

@ -771,4 +771,5 @@
<string name="account_setting_delete_generic_confirmation_dialog">Votre compte sera supprimé localement.\nPour le supprimer de manière définitive, rendez-vous sur le site internet de votre fournisseur SIP.</string>
<string name="account_setting_delete_sip_linphone_org_confirmation_dialog">Votre compte sera supprimé localement.\nPour le supprimer de manière définitive, rendez-vous sur notre plateforme de gestion des comptes :</string>
<string name="call_action_attended_transfer_call">Transfert supervisé</string>
<string name="chat_room_last_message_sender_format">%s :</string>
</resources>

View file

@ -137,6 +137,7 @@
<!-- Chat -->
<string name="no_chat_history">No conversations</string>
<string name="chat_room_last_message_sender_format">%s:</string>
<string name="chat_remote_is_composing">Remote is writing&#8230;</string>
<string name="chat_event_conference_created">You have joined the group</string>
<string name="chat_event_conference_destroyed">You have left the group</string>