mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-23 18:30:20 +01:00
Update message bubble and date header timestamps.
This commit is contained in:
@@ -103,6 +103,18 @@ public class DateUtils extends android.text.format.DateUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getSimpleRelativeTimeSpanString(final Context context, final Locale locale, final long timestamp) {
|
||||
if (isWithin(timestamp, 1, TimeUnit.MINUTES)) {
|
||||
return context.getString(R.string.DateUtils_just_now);
|
||||
} else if (isWithin(timestamp, 1, TimeUnit.HOURS)) {
|
||||
int mins = (int) TimeUnit.MINUTES.convert(System.currentTimeMillis() - timestamp, TimeUnit.MILLISECONDS);
|
||||
return context.getResources().getString(R.string.DateUtils_minutes_ago, mins);
|
||||
} else {
|
||||
String format = DateFormat.is24HourFormat(context) ? "HH:mm" : "hh:mm a";
|
||||
return getFormattedDateTime(timestamp, format, locale);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getTimeString(final Context c, final Locale locale, final long timestamp) {
|
||||
StringBuilder format = new StringBuilder();
|
||||
|
||||
@@ -145,19 +157,29 @@ public class DateUtils extends android.text.format.DateUtils {
|
||||
return new SimpleDateFormat(dateFormatPattern, locale);
|
||||
}
|
||||
|
||||
public static String getRelativeDate(@NonNull Context context,
|
||||
@NonNull Locale locale,
|
||||
long timestamp)
|
||||
public static String getConversationDateHeaderString(@NonNull Context context,
|
||||
@NonNull Locale locale,
|
||||
long timestamp)
|
||||
{
|
||||
if (isToday(timestamp)) {
|
||||
return context.getString(R.string.DateUtils_today);
|
||||
} else if (isYesterday(timestamp)) {
|
||||
return context.getString(R.string.DateUtils_yesterday);
|
||||
} else if (isWithin(timestamp, 182, TimeUnit.DAYS)) {
|
||||
return formatDateWithDayOfWeek(locale, timestamp);
|
||||
} else {
|
||||
return formatDate(locale, timestamp);
|
||||
return formatDateWithYear(locale, timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatDateWithDayOfWeek(@NonNull Locale locale, long timestamp) {
|
||||
return getFormattedDateTime(timestamp, "EEE, MMM d", locale);
|
||||
}
|
||||
|
||||
public static String formatDateWithYear(@NonNull Locale locale, long timestamp) {
|
||||
return getFormattedDateTime(timestamp, "MMM d, yyyy", locale);
|
||||
}
|
||||
|
||||
public static String formatDate(@NonNull Locale locale, long timestamp) {
|
||||
return getFormattedDateTime(timestamp, "EEE, MMM d, yyyy", locale);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user