Added relative dates

This commit is contained in:
M66B 2023-01-14 17:21:18 +01:00
parent 7143ff6f41
commit 7ceba5451d
2 changed files with 19 additions and 4 deletions

View File

@ -1409,8 +1409,12 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
tvSize.setVisibility( tvSize.setVisibility(
message.totalSize != null && ("size".equals(sort) || "attachments".equals(sort)) message.totalSize != null && ("size".equals(sort) || "attachments".equals(sort))
? View.VISIBLE : View.GONE); ? View.VISIBLE : View.GONE);
SpannableStringBuilder time = new SpannableStringBuilderEx( SpannableStringBuilder time;
((date || date_fixed) && !date_week) && FragmentMessages.SORT_DATE_HEADER.contains(sort) if (date_week)
time = new SpannableStringBuilderEx(Helper.getRelativeDateSpanString(context, message.received));
else
time = new SpannableStringBuilderEx(
(date || date_fixed) && FragmentMessages.SORT_DATE_HEADER.contains(sort)
? TF.format(message.received) ? TF.format(message.received)
: Helper.getRelativeTimeSpanString(context, message.received)); : Helper.getRelativeTimeSpanString(context, message.received));
if (show_recent && message.recent) if (show_recent && message.recent)

View File

@ -147,6 +147,7 @@ import java.text.NumberFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; import java.util.Date;
@ -1998,6 +1999,16 @@ public class Helper {
return android.text.format.DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton); return android.text.format.DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton);
} }
static CharSequence getRelativeDateSpanString(Context context, long millis) {
Calendar cal0 = Calendar.getInstance();
Calendar cal1 = Calendar.getInstance();
cal0.setTimeInMillis(millis);
boolean thisMonth = (cal0.get(Calendar.MONTH) == cal1.get(Calendar.MONTH));
String skeleton = (thisMonth ? "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) { static CharSequence getRelativeTimeSpanString(Context context, long millis) {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
long span = Math.abs(now - millis); long span = Math.abs(now - millis);