From 35ed8e12c6cdaa9cc9443e4d18288cedee07a3f5 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Mon, 24 Oct 2022 12:44:41 +0200 Subject: [PATCH] Remove unnecessary Card for Dialog --- .../lonami/talaria/ui/screens/DialogScreen.kt | 113 +++++++++--------- 1 file changed, 56 insertions(+), 57 deletions(-) diff --git a/app/src/main/java/dev/lonami/talaria/ui/screens/DialogScreen.kt b/app/src/main/java/dev/lonami/talaria/ui/screens/DialogScreen.kt index 790d650..ac60e14 100644 --- a/app/src/main/java/dev/lonami/talaria/ui/screens/DialogScreen.kt +++ b/app/src/main/java/dev/lonami/talaria/ui/screens/DialogScreen.kt @@ -4,9 +4,9 @@ import androidx.compose.foundation.Image import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.material.Card +import androidx.compose.material.Divider import androidx.compose.material.Icon -import androidx.compose.material.MaterialTheme +import androidx.compose.material.Surface import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState @@ -31,71 +31,67 @@ import java.time.format.DateTimeFormatter import java.time.format.FormatStyle @Composable -fun DialogCard(dialog: Dialog, onDialogSelected: () -> Unit) { - Card( - shape = MaterialTheme.shapes.large, +fun Dialog(dialog: Dialog, onDialogSelected: () -> Unit) { + Row( modifier = Modifier - .fillMaxWidth() - .padding(0.dp, 2.dp) + .padding(4.dp) .clickable(onClick = onDialogSelected) ) { - Row(modifier = Modifier.padding(4.dp)) { - Image( - painter = painterResource(R.drawable.ic_launcher_foreground), - contentDescription = stringResource(R.string.profile_photo), - contentScale = ContentScale.Fit, - modifier = Modifier.height(48.dp), + Image( + painter = painterResource(R.drawable.ic_launcher_foreground), + contentDescription = stringResource(R.string.profile_photo), + contentScale = ContentScale.Fit, + modifier = Modifier.height(48.dp), + ) + Column(modifier = Modifier.weight(1.0f)) { + Text( + dialog.title, + fontWeight = FontWeight.SemiBold, + maxLines = 1, + overflow = TextOverflow.Ellipsis ) - Column(modifier = Modifier.weight(1.0f)) { + if (dialog.lastMessage != null) { Text( - dialog.title, - fontWeight = FontWeight.SemiBold, + stringResource( + R.string.message_preview, + dialog.lastMessage.sender, + dialog.lastMessage.text + ), maxLines = 1, - overflow = TextOverflow.Ellipsis + overflow = TextOverflow.Ellipsis, ) - if (dialog.lastMessage != null) { + } + } + Column { + if (dialog.lastMessage != null) { + Row { + when (dialog.lastMessage.ack) { + MessageAck.RECEIVED -> {} + MessageAck.SENT -> Icon( + painterResource(R.drawable.sent), + stringResource(R.string.sent) + ) + MessageAck.SEEN -> Icon( + painterResource(R.drawable.seen), + stringResource(R.string.seen) + ) + } + Spacer(Modifier.width(8.dp)) Text( - stringResource( - R.string.message_preview, - dialog.lastMessage.sender, - dialog.lastMessage.text + dialog.lastMessage.date.format( + DateTimeFormatter.ofLocalizedTime( + FormatStyle.SHORT + ) ), - maxLines = 1, - overflow = TextOverflow.Ellipsis, ) } } - Column { - if (dialog.lastMessage != null) { - Row { - when (dialog.lastMessage.ack) { - MessageAck.RECEIVED -> {} - MessageAck.SENT -> Icon( - painterResource(R.drawable.sent), - stringResource(R.string.sent) - ) - MessageAck.SEEN -> Icon( - painterResource(R.drawable.seen), - stringResource(R.string.seen) - ) - } - Spacer(Modifier.width(8.dp)) - Text( - dialog.lastMessage.date.format( - DateTimeFormatter.ofLocalizedTime( - FormatStyle.SHORT - ) - ), - ) - } - } - if (dialog.pinned) { - Icon( - painterResource(R.drawable.tack), - stringResource(R.string.pinned), - modifier = Modifier.align(Alignment.End) - ) - } + if (dialog.pinned) { + Icon( + painterResource(R.drawable.tack), + stringResource(R.string.pinned), + modifier = Modifier.align(Alignment.End) + ) } } } @@ -105,9 +101,10 @@ fun DialogCard(dialog: Dialog, onDialogSelected: () -> Unit) { fun DialogList(dialogs: List, onDialogSelected: (String) -> Unit) { LazyColumn { items(dialogs.size) { - DialogCard(dialogs[it], onDialogSelected = { + Dialog(dialogs[it], onDialogSelected = { onDialogSelected(dialogs[it].id) }) + Divider(startIndent = 52.dp) } } } @@ -118,7 +115,9 @@ fun DialogScreen( dialogViewModel: DialogViewModel = viewModel() ) { val dialogUiState by dialogViewModel.uiState.collectAsState() - DialogList(dialogUiState.dialogs, onDialogSelected = onDialogSelected) + Surface { + DialogList(dialogUiState.dialogs, onDialogSelected = onDialogSelected) + } } @Preview