From ec4e1d2400d6ab2b21aff4039c954da5f968ec25 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 19 Oct 2018 06:38:03 +0000 Subject: [PATCH] Auto close conversations --- .../eu/faircode/email/FragmentMessages.java | 74 ++++++++++++------- 1 file changed, 48 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index bcdff944..dbbd8e0c 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -89,6 +89,7 @@ public class FragmentMessages extends FragmentEx { private AdapterMessage.ViewType viewType; private LiveData> messages = null; + private int autoCount = 0; private boolean autoExpand = true; private List expanded = new ArrayList<>(); private List headers = new ArrayList<>(); @@ -827,37 +828,58 @@ public class FragmentMessages extends FragmentEx { return; } - if (viewType == AdapterMessage.ViewType.THREAD && autoExpand) { - autoExpand = false; - - int count = 0; - int unseen = 0; - TupleMessageEx single = null; - TupleMessageEx see = null; - for (int i = 0; i < messages.size(); i++) { - TupleMessageEx message = messages.get(i); - if (!EntityFolder.ARCHIVE.equals(message.folderType) && - !EntityFolder.SENT.equals(message.folderType)) { - count++; - single = message; - if (!message.ui_seen) { - unseen++; - see = message; + if (viewType == AdapterMessage.ViewType.THREAD) + if (autoExpand) { + autoExpand = false; + + int unseen = 0; + TupleMessageEx single = null; + TupleMessageEx see = null; + for (int i = 0; i < messages.size(); i++) { + TupleMessageEx message = messages.get(i); + if (!EntityFolder.ARCHIVE.equals(message.folderType) && + !EntityFolder.SENT.equals(message.folderType)) { + autoCount++; + single = message; + if (!message.ui_seen) { + unseen++; + see = message; + } } } - } - TupleMessageEx expand = null; - if (count == 1) - expand = single; - else if (unseen == 1) - expand = see; + // Auto expand when: + // - single, non archived/sent message + // - one unread, non archived/sent message in conversation + + TupleMessageEx expand = null; + if (autoCount == 1) + expand = single; + else if (unseen == 1) + expand = see; + + if (expand != null) { + expanded.add(expand.id); + handleExpand(expand.id); + } + } else { + if (autoCount > 0) { + int count = 0; + for (int i = 0; i < messages.size(); i++) { + TupleMessageEx message = messages.get(i); + if (!EntityFolder.ARCHIVE.equals(message.folderType) && + !EntityFolder.SENT.equals(message.folderType)) { + count++; + } + } - if (expand != null) { - expanded.add(expand.id); - handleExpand(expand.id); + // Auto close when: + // - no more non archived/sent messages + + if (count == 0) + finish(); + } } - } Log.i(Helper.TAG, "Submit messages=" + messages.size()); adapter.submitList(messages);