From 8492bc0b94e5dcd31d46e5848876ad0943c2d6b9 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 29 Jan 2019 11:38:38 +0000 Subject: [PATCH] Improved day header handling --- .../eu/faircode/email/AdapterMessage.java | 51 ++++++++----------- .../java/eu/faircode/email/EntityMessage.java | 2 +- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 31a6887a53..72a8be78c5 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -440,10 +440,6 @@ public class AdapterMessage extends RecyclerView.Adapter 0) - prev = differ.getItem(position - 1); - message.day = getDay(prev, message); if (message.day) { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); @@ -2229,33 +2225,30 @@ public class AdapterMessage extends RecyclerView.Adapter pagedList) { - TupleMessageEx prev = null; - for (TupleMessageEx message : pagedList) { - if (message != null) - message.day = getDay(prev, message); - prev = message; + void submitList(PagedList list) { + if (date && "time".equals(sort)) { + TupleMessageEx prev = null; + for (int i = 0; i < list.size(); i++) { + TupleMessageEx message = list.get(i); + if (message != null) + if (i == 0) + message.day = true; + else if (prev != null) { + Calendar cal0 = Calendar.getInstance(); + Calendar cal1 = Calendar.getInstance(); + cal0.setTimeInMillis(prev.received); + cal1.setTimeInMillis(message.received); + int year0 = cal0.get(Calendar.YEAR); + int year1 = cal1.get(Calendar.YEAR); + int day0 = cal0.get(Calendar.DAY_OF_YEAR); + int day1 = cal1.get(Calendar.DAY_OF_YEAR); + message.day = (year0 != year1 || day0 != day1); + } + prev = message; + } } - differ.submitList(pagedList); - } - - boolean getDay(TupleMessageEx prev, TupleMessageEx cur) { - if (!(date && "time".equals(sort))) - return false; - - if (prev == null) - return true; - - Calendar cal0 = Calendar.getInstance(); - Calendar cal1 = Calendar.getInstance(); - cal0.setTimeInMillis(prev.received); - cal1.setTimeInMillis(cur.received); - int year0 = cal0.get(Calendar.YEAR); - int year1 = cal1.get(Calendar.YEAR); - int day0 = cal0.get(Calendar.DAY_OF_YEAR); - int day1 = cal1.get(Calendar.DAY_OF_YEAR); - return (year0 != year1 || day0 != day1); + differ.submitList(list); } PagedList getCurrentList() { diff --git a/app/src/main/java/eu/faircode/email/EntityMessage.java b/app/src/main/java/eu/faircode/email/EntityMessage.java index 9b02c1160c..196f3ba491 100644 --- a/app/src/main/java/eu/faircode/email/EntityMessage.java +++ b/app/src/main/java/eu/faircode/email/EntityMessage.java @@ -137,7 +137,7 @@ public class EntityMessage implements Serializable { public Long last_attempt; // send @Ignore - public boolean day = false; + boolean day = false; static String generateMessageId() { StringBuilder sb = new StringBuilder();