@@ -14,17 +14,17 @@ import androidx.compose.ui.text.font.FontStyle
1414import androidx.compose.ui.text.font.FontWeight
1515import androidx.compose.ui.text.style.TextDecoration
1616import androidx.compose.ui.text.withStyle
17+ import org.koin.compose.koinInject
1718import org.monogram.domain.models.*
1819import org.monogram.presentation.R
1920import java.text.SimpleDateFormat
2021import java.util.*
2122
22- fun formatLastSeen (lastSeen : Long? , context : Context ): String {
23+ fun formatLastSeen (lastSeen : Long? , context : Context , timeFormat : String ): String {
2324 if (lastSeen == null || lastSeen <= 0L ) return context.getString(R .string.last_seen_recently)
2425
2526 val now = System .currentTimeMillis()
2627 val diff = now - lastSeen
27-
2828 if (diff < 0 ) return context.getString(R .string.last_seen_just_now)
2929
3030 return when {
@@ -35,12 +35,12 @@ fun formatLastSeen(lastSeen: Long?, context: Context): String {
3535 }
3636
3737 DateUtils .isToday(lastSeen) -> {
38- val time = SimpleDateFormat (" HH:mm " , Locale .getDefault()).format(Date (lastSeen))
38+ val time = SimpleDateFormat (timeFormat , Locale .getDefault()).format(Date (lastSeen))
3939 context.getString(R .string.last_seen_at, time)
4040 }
4141
4242 isYesterday(lastSeen) -> {
43- val time = SimpleDateFormat (" HH:mm " , Locale .getDefault()).format(Date (lastSeen))
43+ val time = SimpleDateFormat (timeFormat , Locale .getDefault()).format(Date (lastSeen))
4444 context.getString(R .string.last_seen_yesterday_at, time)
4545 }
4646
@@ -57,10 +57,12 @@ fun rememberUserStatusText(user: UserModel?): String {
5757 if (user.type == UserTypeEnum .BOT ) return stringResource(R .string.status_bot)
5858
5959 val context = LocalContext .current
60+ val dateFormatManager: DateFormatManager = koinInject()
61+ val timeFormat = dateFormatManager.getHourMinuteFormat()
6062 return remember(user.userStatus, user.lastSeen) {
6163 when (user.userStatus) {
6264 UserStatusType .ONLINE -> context.getString(R .string.status_online)
63- UserStatusType .OFFLINE -> formatLastSeen(user.lastSeen, context)
65+ UserStatusType .OFFLINE -> formatLastSeen(user.lastSeen, context, timeFormat )
6466 UserStatusType .RECENTLY -> context.getString(R .string.last_seen_recently)
6567 UserStatusType .LAST_WEEK -> context.getString(R .string.last_seen_within_week)
6668 UserStatusType .LAST_MONTH -> context.getString(R .string.last_seen_within_month)
@@ -73,13 +75,13 @@ private fun isYesterday(timestamp: Long): Boolean {
7375 return DateUtils .isToday(timestamp + DateUtils .DAY_IN_MILLIS )
7476}
7577
76- fun getUserStatusText (user : UserModel ? , context : Context ): String {
78+ fun getUserStatusText (user : UserModel ? , context : Context , timeFormat : String ): String {
7779 if (user == null ) return context.getString(R .string.status_offline)
7880 if (user.type == UserTypeEnum .BOT ) return context.getString(R .string.status_bot)
7981
8082 return when (user.userStatus) {
8183 UserStatusType .ONLINE -> context.getString(R .string.status_online)
82- UserStatusType .OFFLINE -> formatLastSeen(user.lastSeen, context)
84+ UserStatusType .OFFLINE -> formatLastSeen(user.lastSeen, context, timeFormat )
8385 UserStatusType .RECENTLY -> context.getString(R .string.last_seen_recently)
8486 UserStatusType .LAST_WEEK -> context.getString(R .string.last_seen_within_week)
8587 UserStatusType .LAST_MONTH -> context.getString(R .string.last_seen_within_month)
0 commit comments