android: show message time instead of message id in bubbles
Some checks failed
CI / test (push) Failing after 2m10s
Some checks failed
CI / test (push) Failing after 2m10s
This commit is contained in:
@@ -55,6 +55,9 @@ import androidx.hilt.navigation.compose.hiltViewModel
|
|||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import coil.compose.AsyncImage
|
import coil.compose.AsyncImage
|
||||||
import ru.daemonlord.messenger.domain.message.model.MessageItem
|
import ru.daemonlord.messenger.domain.message.model.MessageItem
|
||||||
|
import java.time.Instant
|
||||||
|
import java.time.ZoneId
|
||||||
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ChatRoute(
|
fun ChatRoute(
|
||||||
@@ -609,7 +612,7 @@ private fun MessageBubble(
|
|||||||
else -> ""
|
else -> ""
|
||||||
}
|
}
|
||||||
Text(
|
Text(
|
||||||
text = "${message.id}$status",
|
text = "${formatMessageTime(message.createdAt)}$status",
|
||||||
style = MaterialTheme.typography.labelSmall,
|
style = MaterialTheme.typography.labelSmall,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -617,6 +620,17 @@ private fun MessageBubble(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val messageTimeFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm")
|
||||||
|
|
||||||
|
private fun formatMessageTime(createdAt: String): String {
|
||||||
|
return runCatching {
|
||||||
|
Instant.parse(createdAt)
|
||||||
|
.atZone(ZoneId.systemDefault())
|
||||||
|
.toLocalTime()
|
||||||
|
.format(messageTimeFormatter)
|
||||||
|
}.getOrElse { "--:--" }
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun AudioAttachmentPlayer(url: String) {
|
private fun AudioAttachmentPlayer(url: String) {
|
||||||
var isPlaying by remember(url) { mutableStateOf(false) }
|
var isPlaying by remember(url) { mutableStateOf(false) }
|
||||||
|
|||||||
Reference in New Issue
Block a user