Shorten with date/time

pull/213/head
M66B 10 months ago
parent 8494591ec5
commit 81b9085380

@ -1450,7 +1450,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
? View.VISIBLE : View.GONE);
SpannableStringBuilder time;
if (date_time)
time = new SpannableStringBuilderEx(DTFS.format(message.received));
time = new SpannableStringBuilderEx(Helper.getRelativeDateTimeSpanString(context, message.received));
else if (date_week)
time = new SpannableStringBuilderEx(Helper.getRelativeDateSpanString(context, message.received));
else

@ -2165,24 +2165,30 @@ public class Helper {
}
static CharSequence getRelativeDateSpanString(Context context, long millis) {
return getRelativeTimeSpanString(context, millis, false, true);
}
static CharSequence getRelativeTimeSpanString(Context context, long millis) {
return getRelativeTimeSpanString(context, millis, true, false);
}
static CharSequence getRelativeDateTimeSpanString(Context context, long millis) {
return getRelativeTimeSpanString(context, millis, true, true);
}
static CharSequence getRelativeTimeSpanString(Context context, long millis, boolean withTime, boolean withDate) {
Calendar cal0 = Calendar.getInstance();
Calendar cal1 = Calendar.getInstance();
cal0.setTimeInMillis(millis);
boolean thisMonth = (cal0.get(Calendar.MONTH) == cal1.get(Calendar.MONTH));
boolean thisYear = (cal0.get(Calendar.YEAR) == cal1.get(Calendar.YEAR));
String skeleton = (thisMonth && thisYear ? "MMM-d" : "Y-M-d");
String format = android.text.format.DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton);
return new SimpleDateFormat(format).format(millis);
}
static CharSequence getRelativeTimeSpanString(Context context, long millis) {
long now = System.currentTimeMillis();
long span = Math.abs(now - millis);
Time nowTime = new Time();
Time thenTime = new Time();
nowTime.set(now);
thenTime.set(millis);
if (span < DateUtils.DAY_IN_MILLIS && nowTime.weekDay == thenTime.weekDay)
boolean thisYear = (cal0.get(Calendar.YEAR) == cal1.get(Calendar.YEAR));
boolean thisMonth = (cal0.get(Calendar.MONTH) == cal1.get(Calendar.MONTH));
boolean thisDay = (cal0.get(Calendar.DAY_OF_MONTH) == cal1.get(Calendar.DAY_OF_MONTH));
if (withDate) {
String skeleton = (thisMonth && thisYear ? "MMM-d" : "Y-M-d") + (withTime ? " Hm" : "");
String format = android.text.format.DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton);
return new SimpleDateFormat(format).format(millis);
} else if (thisYear && thisMonth && thisDay)
return getTimeInstance(context, SimpleDateFormat.SHORT).format(millis);
else
return DateUtils.getRelativeTimeSpanString(context, millis);

Loading…
Cancel
Save