mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-20 08:39:22 +01:00
Fix talkback saying meters instead of minutes.
This commit is contained in:
committed by
jeffrey-signal
parent
942c155723
commit
282a707bf9
@@ -31,21 +31,23 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
import kotlin.Pair;
|
||||
|
||||
public class BackupUtil {
|
||||
|
||||
private static final String TAG = Log.tag(BackupUtil.class);
|
||||
|
||||
public static final int PASSPHRASE_LENGTH = 30;
|
||||
|
||||
public static @NonNull String getLastBackupTime(@NonNull Context context, @NonNull Locale locale) {
|
||||
public static @NonNull Pair<String, String> getLastBackupTime(@NonNull Context context, @NonNull Locale locale) {
|
||||
try {
|
||||
BackupInfo backup = getLatestBackup();
|
||||
|
||||
if (backup == null) return context.getString(R.string.BackupUtil_never);
|
||||
if (backup == null) return new Pair<>(context.getString(R.string.BackupUtil_never), context.getString(R.string.BackupUtil_never));
|
||||
else return DateUtils.getExtendedRelativeTimeSpanString(context, locale, backup.getTimestamp());
|
||||
} catch (NoExternalStorageException e) {
|
||||
Log.w(TAG, e);
|
||||
return context.getString(R.string.BackupUtil_unknown);
|
||||
return new Pair<>(context.getString(R.string.BackupUtil_unknown), context.getString(R.string.BackupUtil_unknown));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.text.format.DateFormat
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.conversation.v2.computed.FormattedDate
|
||||
import org.thoughtcrime.securesms.util.DateUtils.getBriefRelativeTimeSpanString
|
||||
import java.text.DateFormatSymbols
|
||||
import java.text.ParseException
|
||||
import java.text.SimpleDateFormat
|
||||
@@ -59,8 +60,8 @@ object DateUtils : android.text.format.DateUtils() {
|
||||
* A relative timestamp to use in space-constrained areas, like the conversation list.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getBriefRelativeTimeSpanString(c: Context, locale: Locale, timestamp: Long): String {
|
||||
return when {
|
||||
fun getBriefRelativeTimeSpanString(c: Context, locale: Locale, timestamp: Long): Pair<String, String> {
|
||||
val time = when {
|
||||
isNow(timestamp) -> {
|
||||
c.getString(R.string.DateUtils_just_now)
|
||||
}
|
||||
@@ -82,14 +83,15 @@ object DateUtils : android.text.format.DateUtils() {
|
||||
timestamp.toDateString("MMM d, yyyy", locale)
|
||||
}
|
||||
}
|
||||
return Pair(time, time.toAccessibleFormat(c, timestamp))
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to [getBriefRelativeTimeSpanString], except this will include additional time information in longer formats.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getExtendedRelativeTimeSpanString(context: Context, locale: Locale, timestamp: Long): String {
|
||||
return when {
|
||||
fun getExtendedRelativeTimeSpanString(context: Context, locale: Locale, timestamp: Long): Pair<String, String> {
|
||||
val time = when {
|
||||
isNow(timestamp) -> {
|
||||
context.getString(R.string.DateUtils_just_now)
|
||||
}
|
||||
@@ -117,6 +119,7 @@ object DateUtils : android.text.format.DateUtils() {
|
||||
timestamp.toDateString(format.toString(), locale)
|
||||
}
|
||||
}
|
||||
return Pair(time, time.toAccessibleFormat(context, timestamp))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,14 +135,14 @@ object DateUtils : android.text.format.DateUtils() {
|
||||
fun getDatelessRelativeTimeSpanFormattedDate(context: Context, locale: Locale, timestamp: Long): FormattedDate {
|
||||
return when {
|
||||
isNow(timestamp) -> {
|
||||
FormattedDate(isRelative = true, isNow = true, value = context.getString(R.string.DateUtils_just_now))
|
||||
FormattedDate(isRelative = true, isNow = true, value = context.getString(R.string.DateUtils_just_now), contentDescValue = context.getString(R.string.DateUtils_just_now))
|
||||
}
|
||||
timestamp.isWithin(1.hours) -> {
|
||||
val minutes = timestamp.convertDeltaTo(DurationUnit.MINUTES)
|
||||
FormattedDate(isRelative = true, isNow = false, value = context.resources.getString(R.string.DateUtils_minutes_ago, minutes))
|
||||
FormattedDate(isRelative = true, isNow = false, value = context.resources.getString(R.string.DateUtils_minutes_ago, minutes), contentDescValue = context.resources.getQuantityString(R.plurals.DateUtils_minutes_ago_content_description, minutes, minutes))
|
||||
}
|
||||
else -> {
|
||||
FormattedDate(isRelative = false, isNow = false, value = getOnlyTimeString(context, timestamp))
|
||||
FormattedDate(isRelative = false, isNow = false, value = getOnlyTimeString(context, timestamp), contentDescValue = getOnlyTimeString(context, timestamp))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -428,6 +431,15 @@ object DateUtils : android.text.format.DateUtils() {
|
||||
}
|
||||
}
|
||||
|
||||
fun String.toAccessibleFormat(context: Context, timestamp: Long): String {
|
||||
return if (!isNow(timestamp) && timestamp.isWithin(1.hours)) {
|
||||
val minutes = timestamp.convertDeltaTo(DurationUnit.MINUTES)
|
||||
context.resources.getQuantityString(R.plurals.DateUtils_minutes_ago_content_description, minutes, minutes)
|
||||
} else {
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
private fun SimpleDateFormat.setLowercaseAmPmStrings(locale: Locale): SimpleDateFormat {
|
||||
val symbols = dateFormatSymbolsCache.getOrPut(locale) {
|
||||
DateFormatSymbols(locale).apply {
|
||||
|
||||
Reference in New Issue
Block a user