Skip to content

Commit

Permalink
feat: display messages count in a conversation (#57)
Browse files Browse the repository at this point in the history
- display messages count in a conversation
  • Loading branch information
migulyaev authored Sep 20, 2023
1 parent 2ac9506 commit 98a2cff
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -131,3 +149,61 @@ private fun EmptyConversationsView() {
)
}
}

@Preview(showBackground = true)
@Composable
fun Conversation_Preview() {
val conversationId = UUID.randomUUID()
val message = ExtendedMessage(
conversationId = conversationId,
senderVeraId = "[email protected]",
recipientVeraId = "[email protected]",
isOutgoing = true,
contactDisplayName = "Alias",
text = "Hello man!",
sentAtFormatted = "01:03 PM",
)
Column {
Conversation(
conversation = ExtendedConversation(
conversationId = conversationId,
ownerVeraId = "[email protected]",
contactVeraId = "[email protected]",
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 = "[email protected]",
contactVeraId = "[email protected]",
contactDisplayName = "Alias",
subject = "Subject Preview",
lastMessageTimestamp = System.currentTimeMillis(),
isRead = true,
lastMessageFormattedTimestamp = "01:03 PM",
lastMessage = message,
totalMessagesFormattedText = "(2)",
messages = listOf(
message,
),
),
noSubjectText = "(No subject)",
) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ data class ExtendedConversation(
val lastMessageFormattedTimestamp: String,
val lastMessage: ExtendedMessage,
val isRead: Boolean,
val totalMessagesFormattedText: String?,
val messages: List<ExtendedMessage>,
)

0 comments on commit 98a2cff

Please sign in to comment.