From 785f7372446a9b51c9e44963725cdeaa1af98a8f Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Mon, 23 Nov 2015 16:25:04 -0800 Subject: [PATCH] Limit 'last active' device timestamp to day level precision Closes #4614 // FREEBIE --- .../thoughtcrime/securesms/DeviceListItem.java | 12 ++++++------ .../thoughtcrime/securesms/util/DateUtils.java | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) 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;