Limit 'last active' device timestamp to day level precision

Closes #4614
// FREEBIE
This commit is contained in:
Moxie Marlinspike 2015-11-23 16:25:04 -08:00
parent 67415a8dcb
commit 785f737244
2 changed files with 22 additions and 6 deletions

View File

@ -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();
}

View File

@ -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;