mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-08-22 07:59:48 +00:00
align time format with iOS app, use kotlix-datetime only (#340)
This commit is contained in:
@@ -1,14 +1,13 @@
|
|||||||
package chat.simplex.app.model
|
package chat.simplex.app.model
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import androidx.compose.runtime.mutableStateListOf
|
import androidx.compose.runtime.mutableStateListOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import chat.simplex.app.SimplexApp
|
import chat.simplex.app.SimplexApp
|
||||||
import kotlinx.datetime.*
|
import kotlinx.datetime.*
|
||||||
|
import kotlinx.datetime.TimeZone
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import java.time.format.DateTimeFormatter
|
|
||||||
|
|
||||||
class ChatModel(val controller: ChatController, val alertManager: SimplexApp.AlertManager) {
|
class ChatModel(val controller: ChatController, val alertManager: SimplexApp.AlertManager) {
|
||||||
var currentUser = mutableStateOf<User?>(null)
|
var currentUser = mutableStateOf<User?>(null)
|
||||||
@@ -495,13 +494,14 @@ class CIMeta (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO use old api?
|
fun getTimestampText(t: Instant): String {
|
||||||
// TODO date for older timestamps
|
val tz = TimeZone.currentSystemDefault()
|
||||||
@SuppressLint("NewApi")
|
val now: LocalDateTime = Clock.System.now().toLocalDateTime(tz)
|
||||||
fun getTimestampText(d: Instant): String {
|
val time: LocalDateTime = t.toLocalDateTime(tz)
|
||||||
val dt = d.toLocalDateTime(TimeZone.currentSystemDefault()).toJavaLocalDateTime()
|
val recent = now.date == time.date ||
|
||||||
val formatter = DateTimeFormatter.ofPattern("HH:mm")
|
(now.date.minus(time.date).days == 1 && now.hour < 12 && time.hour >= 18 )
|
||||||
return dt.format(formatter)
|
return if (recent) String.format("%02d:%02d", time.hour, time.minute)
|
||||||
|
else String.format("%02d/%02d", time.dayOfMonth, time.monthNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package chat.simplex.app.views.chatlist
|
package chat.simplex.app.views.chatlist
|
||||||
|
|
||||||
import android.icu.text.SimpleDateFormat
|
|
||||||
import androidx.compose.foundation.*
|
import androidx.compose.foundation.*
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
@@ -14,31 +13,9 @@ import androidx.compose.ui.text.font.FontWeight
|
|||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import chat.simplex.app.model.Chat
|
import chat.simplex.app.model.*
|
||||||
import chat.simplex.app.model.ChatInfo
|
|
||||||
import chat.simplex.app.ui.theme.HighOrLowlight
|
import chat.simplex.app.ui.theme.HighOrLowlight
|
||||||
import chat.simplex.app.ui.theme.SimpleXTheme
|
import chat.simplex.app.ui.theme.SimpleXTheme
|
||||||
import kotlinx.datetime.Instant
|
|
||||||
import kotlinx.datetime.toJavaInstant
|
|
||||||
import java.time.LocalDateTime
|
|
||||||
import java.util.*
|
|
||||||
import java.time.Instant as JavaInstant
|
|
||||||
|
|
||||||
fun getDisplayTime(t: Instant) : String {
|
|
||||||
val timeFormatter = SimpleDateFormat("HH:mm", Locale.getDefault())
|
|
||||||
val dateFormatter = SimpleDateFormat("dd/MM/y", Locale.getDefault())
|
|
||||||
val timeProvided: JavaInstant = t.toJavaInstant()
|
|
||||||
val tz = TimeZone.getDefault()
|
|
||||||
val dateProvided = LocalDateTime.ofInstant(timeProvided, tz.toZoneId()).toLocalDate()
|
|
||||||
val today = LocalDateTime.now().atZone(tz.toZoneId()).toLocalDate()
|
|
||||||
val yesterday = today.minusDays(1)
|
|
||||||
|
|
||||||
return when (dateProvided) {
|
|
||||||
today -> timeFormatter.format(Date.from(timeProvided))
|
|
||||||
yesterday -> "yesterday"
|
|
||||||
else -> dateFormatter.format(Date.from(timeProvided))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ChatPreviewView(chat: Chat, goToChat: () -> Unit) {
|
fun ChatPreviewView(chat: Chat, goToChat: () -> Unit) {
|
||||||
@@ -70,9 +47,9 @@ fun ChatPreviewView(chat: Chat, goToChat: () -> Unit) {
|
|||||||
Text(chat.chatInfo.chatViewName, fontWeight = FontWeight.Bold)
|
Text(chat.chatInfo.chatViewName, fontWeight = FontWeight.Bold)
|
||||||
(
|
(
|
||||||
if (chat.chatItems.count() > 0) {
|
if (chat.chatItems.count() > 0) {
|
||||||
Text(getDisplayTime(chat.chatItems.last().meta.itemTs), color = HighOrLowlight)
|
Text(getTimestampText(chat.chatItems.last().meta.itemTs), color = HighOrLowlight)
|
||||||
}
|
}
|
||||||
else Text(getDisplayTime(chat.chatInfo.createdAt), color = HighOrLowlight)
|
else Text(getTimestampText(chat.chatInfo.createdAt), color = HighOrLowlight)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (chat.chatItems.count() > 0) {
|
if (chat.chatItems.count() > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user