From dcc4d099d5f3c0491bf065c97878e8eae7094db5 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 23 Jan 2019 10:16:14 +0000 Subject: [PATCH] Show date/time header after two days --- .../eu/faircode/email/AdapterMessage.java | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 5442d79bc7..1a3e078196 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -112,6 +112,8 @@ import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.StaggeredGridLayoutManager; import static android.text.format.DateUtils.DAY_IN_MILLIS; +import static android.text.format.DateUtils.FORMAT_SHOW_DATE; +import static android.text.format.DateUtils.FORMAT_SHOW_WEEKDAY; public class AdapterMessage extends RecyclerView.Adapter { private Context context; @@ -149,7 +151,7 @@ public class AdapterMessage extends RecyclerView.Adapter 0) prev = differ.getItem(position - 1); message.day = getDay(prev, message); - if (message.day) - tvDay.setText( - DateUtils.getRelativeTimeSpanString( - message.received, - new Date().getTime(), - DAY_IN_MILLIS, 0)); + if (message.day) { + Calendar cal = Calendar.getInstance(); + cal.setTime(new Date()); + cal.set(Calendar.HOUR_OF_DAY, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); + cal.set(Calendar.MILLISECOND, 0); + cal.add(Calendar.DAY_OF_MONTH, -2); + if (message.received <= cal.getTimeInMillis()) + tvDay.setText( + DateUtils.formatDateRange( + context, + message.received, + message.received, + FORMAT_SHOW_WEEKDAY | FORMAT_SHOW_DATE)); + else + tvDay.setText( + DateUtils.getRelativeTimeSpanString( + message.received, + new Date().getTime(), + DAY_IN_MILLIS, 0)); + } grpDay.setVisibility(message.day ? View.VISIBLE : View.GONE); itemView.setAlpha(message.uid == null && !EntityFolder.OUTBOX.equals(message.folderType) @@ -592,7 +610,7 @@ public class AdapterMessage extends RecyclerView.Adapter