Remove unnecessary Card for Dialog

This commit is contained in:
Lonami Exo 2022-10-24 12:44:41 +02:00
parent 0db1599cf7
commit 35ed8e12c6
1 changed files with 56 additions and 57 deletions

View File

@ -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<Dialog>, 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