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.clickable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn 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.Icon
import androidx.compose.material.MaterialTheme import androidx.compose.material.Surface
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState import androidx.compose.runtime.collectAsState
@ -31,71 +31,67 @@ import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle import java.time.format.FormatStyle
@Composable @Composable
fun DialogCard(dialog: Dialog, onDialogSelected: () -> Unit) { fun Dialog(dialog: Dialog, onDialogSelected: () -> Unit) {
Card( Row(
shape = MaterialTheme.shapes.large,
modifier = Modifier modifier = Modifier
.fillMaxWidth() .padding(4.dp)
.padding(0.dp, 2.dp)
.clickable(onClick = onDialogSelected) .clickable(onClick = onDialogSelected)
) { ) {
Row(modifier = Modifier.padding(4.dp)) { Image(
Image( painter = painterResource(R.drawable.ic_launcher_foreground),
painter = painterResource(R.drawable.ic_launcher_foreground), contentDescription = stringResource(R.string.profile_photo),
contentDescription = stringResource(R.string.profile_photo), contentScale = ContentScale.Fit,
contentScale = ContentScale.Fit, modifier = Modifier.height(48.dp),
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( Text(
dialog.title, stringResource(
fontWeight = FontWeight.SemiBold, R.string.message_preview,
dialog.lastMessage.sender,
dialog.lastMessage.text
),
maxLines = 1, 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( Text(
stringResource( dialog.lastMessage.date.format(
R.string.message_preview, DateTimeFormatter.ofLocalizedTime(
dialog.lastMessage.sender, FormatStyle.SHORT
dialog.lastMessage.text )
), ),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
) )
} }
} }
Column { if (dialog.pinned) {
if (dialog.lastMessage != null) { Icon(
Row { painterResource(R.drawable.tack),
when (dialog.lastMessage.ack) { stringResource(R.string.pinned),
MessageAck.RECEIVED -> {} modifier = Modifier.align(Alignment.End)
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)
)
}
} }
} }
} }
@ -105,9 +101,10 @@ fun DialogCard(dialog: Dialog, onDialogSelected: () -> Unit) {
fun DialogList(dialogs: List<Dialog>, onDialogSelected: (String) -> Unit) { fun DialogList(dialogs: List<Dialog>, onDialogSelected: (String) -> Unit) {
LazyColumn { LazyColumn {
items(dialogs.size) { items(dialogs.size) {
DialogCard(dialogs[it], onDialogSelected = { Dialog(dialogs[it], onDialogSelected = {
onDialogSelected(dialogs[it].id) onDialogSelected(dialogs[it].id)
}) })
Divider(startIndent = 52.dp)
} }
} }
} }
@ -118,7 +115,9 @@ fun DialogScreen(
dialogViewModel: DialogViewModel = viewModel() dialogViewModel: DialogViewModel = viewModel()
) { ) {
val dialogUiState by dialogViewModel.uiState.collectAsState() val dialogUiState by dialogViewModel.uiState.collectAsState()
DialogList(dialogUiState.dialogs, onDialogSelected = onDialogSelected) Surface {
DialogList(dialogUiState.dialogs, onDialogSelected = onDialogSelected)
}
} }
@Preview @Preview