mirror of https://github.com/M66B/FairEmail.git
Added relative dates
This commit is contained in:
parent
7143ff6f41
commit
7ceba5451d
|
@ -1409,10 +1409,14 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
tvSize.setVisibility(
|
||||
message.totalSize != null && ("size".equals(sort) || "attachments".equals(sort))
|
||||
? View.VISIBLE : View.GONE);
|
||||
SpannableStringBuilder time = new SpannableStringBuilderEx(
|
||||
((date || date_fixed) && !date_week) && FragmentMessages.SORT_DATE_HEADER.contains(sort)
|
||||
? TF.format(message.received)
|
||||
: Helper.getRelativeTimeSpanString(context, message.received));
|
||||
SpannableStringBuilder time;
|
||||
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)
|
||||
: Helper.getRelativeTimeSpanString(context, message.received));
|
||||
if (show_recent && message.recent)
|
||||
time.setSpan(new UnderlineSpan(), 0, time.length(), 0);
|
||||
tvTime.setText(time);
|
||||
|
|
|
@ -147,6 +147,7 @@ import java.text.NumberFormat;
|
|||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
|
@ -1998,6 +1999,16 @@ public class Helper {
|
|||
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) {
|
||||
long now = System.currentTimeMillis();
|
||||
long span = Math.abs(now - millis);
|
||||
|
|
Loading…
Reference in New Issue