Improves the wording of the Last Seen
This commit is contained in:
@@ -45,9 +45,14 @@ var monthNoDayFormatter = SimpleDateFormat(MONTH_NO_DAY_DATE_FORMAT, locale)
|
|||||||
fun timeAgo(
|
fun timeAgo(
|
||||||
time: Long?,
|
time: Long?,
|
||||||
context: Context,
|
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 {
|
): String {
|
||||||
if (time == null) return " "
|
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
|
val timeDifference = TimeUtils.now() - time
|
||||||
|
|
||||||
@@ -60,7 +65,7 @@ fun timeAgo(
|
|||||||
monthFormatter = SimpleDateFormat(MONTH_DATE_FORMAT, locale)
|
monthFormatter = SimpleDateFormat(MONTH_DATE_FORMAT, locale)
|
||||||
}
|
}
|
||||||
|
|
||||||
" • " + yearFormatter.format(time * 1000)
|
prefix + yearFormatter.format(time * 1000)
|
||||||
} else if (timeDifference > TimeUtils.ONE_MONTH) {
|
} else if (timeDifference > TimeUtils.ONE_MONTH) {
|
||||||
// Dec 12
|
// Dec 12
|
||||||
if (locale != Locale.getDefault()) {
|
if (locale != Locale.getDefault()) {
|
||||||
@@ -69,16 +74,16 @@ fun timeAgo(
|
|||||||
monthFormatter = SimpleDateFormat(MONTH_DATE_FORMAT, locale)
|
monthFormatter = SimpleDateFormat(MONTH_DATE_FORMAT, locale)
|
||||||
}
|
}
|
||||||
|
|
||||||
" • " + monthFormatter.format(time * 1000)
|
prefix + monthFormatter.format(time * 1000)
|
||||||
} else if (timeDifference > TimeUtils.ONE_DAY) {
|
} else if (timeDifference > TimeUtils.ONE_DAY) {
|
||||||
// 2 days
|
// 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) {
|
} 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) {
|
} 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 {
|
} else {
|
||||||
" • " + stringRes(context, R.string.now)
|
prefix + stringRes(context, seconds)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -309,7 +309,7 @@ fun DisplayLastSeen(
|
|||||||
lastSeen?.let { timestamp ->
|
lastSeen?.let { timestamp ->
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
Text(
|
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,
|
color = MaterialTheme.colorScheme.placeholderText,
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
|||||||
@@ -309,6 +309,7 @@
|
|||||||
<string name="lnurl" translatable="false">LNURL…</string>
|
<string name="lnurl" translatable="false">LNURL…</string>
|
||||||
<string name="never">never</string>
|
<string name="never">never</string>
|
||||||
<string name="now">now</string>
|
<string name="now">now</string>
|
||||||
|
<string name="seconds">seconds</string>
|
||||||
<string name="h">h</string>
|
<string name="h">h</string>
|
||||||
<string name="m">m</string>
|
<string name="m">m</string>
|
||||||
<string name="d">d</string>
|
<string name="d">d</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user