diff --git a/src/org/thoughtcrime/securesms/DeviceListItem.java b/src/org/thoughtcrime/securesms/DeviceListItem.java index fe35005053..082f9e311a 100644 --- a/src/org/thoughtcrime/securesms/DeviceListItem.java +++ b/src/org/thoughtcrime/securesms/DeviceListItem.java @@ -39,14 +39,14 @@ public class DeviceListItem extends LinearLayout { else this.name.setText(deviceInfo.getName()); this.created.setText(getContext().getString(R.string.DeviceListItem_linked_s, - DateUtils.getExtendedRelativeTimeSpanString(getContext(), - Locale.getDefault(), - deviceInfo.getCreated()))); + DateUtils.getDayPrecisionTimeSpanString(getContext(), + Locale.getDefault(), + deviceInfo.getCreated()))); this.lastActive.setText(getContext().getString(R.string.DeviceListItem_last_active_s, - DateUtils.getExtendedRelativeTimeSpanString(getContext(), - Locale.getDefault(), - deviceInfo.getLastSeen()))); + DateUtils.getDayPrecisionTimeSpanString(getContext(), + Locale.getDefault(), + deviceInfo.getLastSeen()))); this.deviceId = deviceInfo.getId(); } diff --git a/src/org/thoughtcrime/securesms/util/DateUtils.java b/src/org/thoughtcrime/securesms/util/DateUtils.java index 35bc2557f1..830020dd3d 100644 --- a/src/org/thoughtcrime/securesms/util/DateUtils.java +++ b/src/org/thoughtcrime/securesms/util/DateUtils.java @@ -83,6 +83,22 @@ public class DateUtils extends android.text.format.DateUtils { } } + public static String getDayPrecisionTimeSpanString(Context context, Locale locale, long timestamp) { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd"); + + if (simpleDateFormat.format(System.currentTimeMillis()).equals(simpleDateFormat.format(timestamp))) { + return "Today"; + } else { + String format; + + if (isWithin(timestamp, 6, TimeUnit.DAYS)) format = "EEE "; + else if (isWithin(timestamp, 365, TimeUnit.DAYS)) format = "MMM d"; + else format = "MMM d, yyy"; + + return getFormattedDateTime(timestamp, format, locale); + } + } + public static SimpleDateFormat getDetailedDateFormatter(Context context, Locale locale) { String dateFormatPattern;