From 5d4028fd63c5bc2cc73f605902bce4d6570e8155 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 28 Feb 2020 09:32:29 +0100 Subject: [PATCH] Prevent flicker on expanding messages --- .../eu/faircode/email/AdapterMessage.java | 6 +- .../eu/faircode/email/FragmentMessages.java | 64 ++++++++++--------- 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 0f7ab70b87..02fa2fef6b 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -2824,7 +2824,7 @@ public class AdapterMessage extends RecyclerView.Adapter(values.get(name))) - if (!other.equals(id)) { - values.get(name).remove(other); - int pos = adapter.getPositionForKey(other); - if (pos != RecyclerView.NO_POSITION) - adapter.notifyItemChanged(pos); - } - } - - updateExpanded(); - if (enabled) - handleExpand(id); - } } @Override @@ -1500,6 +1480,36 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. return false; } + public void setExpanded(TupleMessageEx message, boolean value) { + // Prevent flicker + if (value && + message.accountProtocol != EntityAccount.TYPE_IMAP || + (message.accountAutoSeen && !message.ui_seen && !message.folderReadOnly)) { + message.unseen = 0; + message.ui_seen = true; + } + + setValue("expanded", message.id, value); + + // Collapse other messages + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + boolean expand_all = prefs.getBoolean("expand_all", false); + boolean expand_one = prefs.getBoolean("expand_one", true); + if (!expand_all && expand_one) { + for (Long other : new ArrayList<>(values.get("expanded"))) + if (!other.equals(id)) { + values.get("expanded").remove(other); + int pos = adapter.getPositionForKey(other); + if (pos != RecyclerView.NO_POSITION) + adapter.notifyItemChanged(pos); + } + } + + updateExpanded(); + if (value) + handleExpand(id); + } + @Override public void setSize(long id, Float size) { if (size == null) @@ -3769,16 +3779,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. expand = messages.get(0); if (expand != null && - (expand.content || unmetered || (expand.size != null && expand.size < download))) { - // Prevent flicker - if (expand.accountProtocol != EntityAccount.TYPE_IMAP || - (expand.accountAutoSeen && !expand.ui_seen && !expand.folderReadOnly)) { - expand.unseen = 0; - expand.ui_seen = true; - } - - iProperties.setValue("expanded", expand.id, true); - } + (expand.content || unmetered || (expand.size != null && expand.size < download))) + iProperties.setExpanded(expand, true); } // Auto expand all seen messages @@ -3786,7 +3788,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. if (expand_all) for (TupleMessageEx message : messages) if (message != null && message.ui_seen) - iProperties.setValue("expanded", message.id, true); + iProperties.setExpanded(message, true); } else { if (autoCloseCount > 0 && (autoclose || onclose != null)) { int count = 0;