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(
|
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)
|
||||||
? TF.format(message.received)
|
time = new SpannableStringBuilderEx(Helper.getRelativeDateSpanString(context, message.received));
|
||||||
: Helper.getRelativeTimeSpanString(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)
|
if (show_recent && message.recent)
|
||||||
time.setSpan(new UnderlineSpan(), 0, time.length(), 0);
|
time.setSpan(new UnderlineSpan(), 0, time.length(), 0);
|
||||||
tvTime.setText(time);
|
tvTime.setText(time);
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue