Improves the wording of the Last Seen

This commit is contained in:
Vitor Pamplona
2026-03-23 15:51:35 -04:00
parent 306d76f793
commit f553489ddf
3 changed files with 14 additions and 8 deletions
@@ -45,9 +45,14 @@ var monthNoDayFormatter = SimpleDateFormat(MONTH_NO_DAY_DATE_FORMAT, locale)
fun timeAgo(
time: Long?,
context: Context,
prefix: String = "",
seconds: Int = R.string.now,
minutes: Int = R.string.m,
hours: Int = R.string.h,
days: Int = R.string.d,
): String {
if (time == null) return " "
if (time == 0L) return "${stringRes(context, R.string.never)}"
if (time == 0L) return prefix + stringRes(context, R.string.never)
val timeDifference = TimeUtils.now() - time
@@ -60,7 +65,7 @@ fun timeAgo(
monthFormatter = SimpleDateFormat(MONTH_DATE_FORMAT, locale)
}
"" + yearFormatter.format(time * 1000)
prefix + yearFormatter.format(time * 1000)
} else if (timeDifference > TimeUtils.ONE_MONTH) {
// Dec 12
if (locale != Locale.getDefault()) {
@@ -69,16 +74,16 @@ fun timeAgo(
monthFormatter = SimpleDateFormat(MONTH_DATE_FORMAT, locale)
}
"" + monthFormatter.format(time * 1000)
prefix + monthFormatter.format(time * 1000)
} else if (timeDifference > TimeUtils.ONE_DAY) {
// 2 days
"" + (timeDifference / TimeUtils.ONE_DAY).toString() + stringRes(context, R.string.d)
prefix + (timeDifference / TimeUtils.ONE_DAY).toString() + stringRes(context, days)
} else if (timeDifference > TimeUtils.ONE_HOUR) {
"" + (timeDifference / TimeUtils.ONE_HOUR).toString() + stringRes(context, R.string.h)
prefix + (timeDifference / TimeUtils.ONE_HOUR).toString() + stringRes(context, hours)
} else if (timeDifference > TimeUtils.ONE_MINUTE) {
"" + (timeDifference / TimeUtils.ONE_MINUTE).toString() + stringRes(context, R.string.m)
prefix + (timeDifference / TimeUtils.ONE_MINUTE).toString() + stringRes(context, minutes)
} else {
"" + stringRes(context, R.string.now)
prefix + stringRes(context, seconds)
}
}
@@ -309,7 +309,7 @@ fun DisplayLastSeen(
lastSeen?.let { timestamp ->
val context = LocalContext.current
Text(
text = stringRes(R.string.last_seen, timeAgo(timestamp, context)),
text = stringRes(R.string.last_seen, timeAgo(timestamp, context, prefix = "", seconds = R.string.seconds)),
color = MaterialTheme.colorScheme.placeholderText,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
+1
View File
@@ -309,6 +309,7 @@
<string name="lnurl" translatable="false">LNURL…</string>
<string name="never">never</string>
<string name="now">now</string>
<string name="seconds">seconds</string>
<string name="h">h</string>
<string name="m">m</string>
<string name="d">d</string>