From 98a2cfff4969f81be356b2c6efa79dfe88b5a5f5 Mon Sep 17 00:00:00 2001 From: Mikhail Gulyaev <48011967+mgulyaev10@users.noreply.github.com> Date: Wed, 20 Sep 2023 14:35:16 +0200 Subject: [PATCH] feat: display messages count in a conversation (#57) - display messages count in a conversation --- .../ExtendedConversationConverter.kt | 1 + .../messages/list/ConversationsListScreen.kt | 76 +++++++++++++++++++ .../messages/model/ExtendedConversation.kt | 1 + 3 files changed, 78 insertions(+) diff --git a/app/src/main/java/tech/relaycorp/letro/messages/converter/ExtendedConversationConverter.kt b/app/src/main/java/tech/relaycorp/letro/messages/converter/ExtendedConversationConverter.kt index 49a2a96e..a07527fa 100644 --- a/app/src/main/java/tech/relaycorp/letro/messages/converter/ExtendedConversationConverter.kt +++ b/app/src/main/java/tech/relaycorp/letro/messages/converter/ExtendedConversationConverter.kt @@ -75,6 +75,7 @@ class ExtendedConversationConverterImpl @Inject constructor( messages = extendedMessagesList, lastMessage = extendedMessagesList.last(), isRead = conversation.isRead, + totalMessagesFormattedText = if (extendedMessagesList.count() <= 1) null else "(${extendedMessagesList.count()})", ) } .forEach { extendedConversations.add(it) } diff --git a/app/src/main/java/tech/relaycorp/letro/messages/list/ConversationsListScreen.kt b/app/src/main/java/tech/relaycorp/letro/messages/list/ConversationsListScreen.kt index 4ef60c3e..f19a9d92 100644 --- a/app/src/main/java/tech/relaycorp/letro/messages/list/ConversationsListScreen.kt +++ b/app/src/main/java/tech/relaycorp/letro/messages/list/ConversationsListScreen.kt @@ -10,8 +10,10 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items +import androidx.compose.material3.Divider import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable @@ -21,13 +23,16 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import tech.relaycorp.letro.R import tech.relaycorp.letro.messages.model.ExtendedConversation +import tech.relaycorp.letro.messages.model.ExtendedMessage import tech.relaycorp.letro.ui.theme.LargeProminent import tech.relaycorp.letro.ui.theme.MediumProminent import tech.relaycorp.letro.ui.theme.SmallProminent import tech.relaycorp.letro.ui.utils.ConversationsStringsProvider +import java.util.UUID @Composable fun ConversationsListScreen( @@ -84,6 +89,19 @@ private fun Conversation( color = MaterialTheme.colorScheme.onSurface, maxLines = 1, ) + if (conversation.totalMessagesFormattedText != null) { + Spacer(modifier = Modifier.width(4.dp)) + Text( + text = conversation.totalMessagesFormattedText, + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.onSurface, + maxLines = 1, + modifier = Modifier + .padding( + top = if (conversation.isRead) 3.dp else 1.dp, + ), + ) + } Spacer(modifier = Modifier.weight(1f)) Text( text = conversation.lastMessageFormattedTimestamp, @@ -131,3 +149,61 @@ private fun EmptyConversationsView() { ) } } + +@Preview(showBackground = true) +@Composable +fun Conversation_Preview() { + val conversationId = UUID.randomUUID() + val message = ExtendedMessage( + conversationId = conversationId, + senderVeraId = "ft@applepie.rocks", + recipientVeraId = "contact@vera.id", + isOutgoing = true, + contactDisplayName = "Alias", + text = "Hello man!", + sentAtFormatted = "01:03 PM", + ) + Column { + Conversation( + conversation = ExtendedConversation( + conversationId = conversationId, + ownerVeraId = "ft@applepie.rocks", + contactVeraId = "contact@vera.id", + contactDisplayName = "Alias", + subject = "Subject Preview", + lastMessageTimestamp = System.currentTimeMillis(), + isRead = false, + lastMessageFormattedTimestamp = "01:03 PM", + lastMessage = message, + totalMessagesFormattedText = "(2)", + messages = listOf( + message, + ), + ), + noSubjectText = "(No subject)", + ) { + } + Divider( + modifier = Modifier.height(1.dp), + ) + Conversation( + conversation = ExtendedConversation( + conversationId = conversationId, + ownerVeraId = "ft@applepie.rocks", + contactVeraId = "contact@vera.id", + contactDisplayName = "Alias", + subject = "Subject Preview", + lastMessageTimestamp = System.currentTimeMillis(), + isRead = true, + lastMessageFormattedTimestamp = "01:03 PM", + lastMessage = message, + totalMessagesFormattedText = "(2)", + messages = listOf( + message, + ), + ), + noSubjectText = "(No subject)", + ) { + } + } +} diff --git a/app/src/main/java/tech/relaycorp/letro/messages/model/ExtendedConversation.kt b/app/src/main/java/tech/relaycorp/letro/messages/model/ExtendedConversation.kt index 642d5df7..a75c3613 100644 --- a/app/src/main/java/tech/relaycorp/letro/messages/model/ExtendedConversation.kt +++ b/app/src/main/java/tech/relaycorp/letro/messages/model/ExtendedConversation.kt @@ -12,5 +12,6 @@ data class ExtendedConversation( val lastMessageFormattedTimestamp: String, val lastMessage: ExtendedMessage, val isRead: Boolean, + val totalMessagesFormattedText: String?, val messages: List, )