From aad2f185056b56208910ec88974e9b81906924f0 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 18 Mar 2019 10:51:47 +0000 Subject: [PATCH] Keep message bodies --- .../eu/faircode/email/FragmentMessages.java | 22 +++++++++++++++---- .../main/java/eu/faircode/email/Helper.java | 9 ++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index ea75990c7a..416d1d56f6 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -149,8 +149,8 @@ public class FragmentMessages extends FragmentBase { private int autoCloseCount = 0; private boolean autoExpanded = true; private Map> values = new HashMap<>(); - private LongSparseArray bodies = new LongSparseArray<>(); - private LongSparseArray html = new LongSparseArray<>(); + private Map bodies = new HashMap<>(); + private Map html = new HashMap<>(); private LongSparseArray accountSwipes = new LongSparseArray<>(); private BoundaryCallbackMessages boundaryCallback = null; @@ -1485,6 +1485,7 @@ public class FragmentMessages extends FragmentBase { @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); + outState.putBoolean("fair:autoExpanded", autoExpanded); outState.putInt("fair:autoCloseCount", autoCloseCount); @@ -1492,6 +1493,14 @@ public class FragmentMessages extends FragmentBase { for (String name : values.keySet()) outState.putLongArray("fair:name:" + name, Helper.toLongArray(values.get(name))); + outState.putLongArray("fair:bodies", Helper.toLongArray(bodies.keySet())); + for (Long key : bodies.keySet()) + outState.putString("fair:bodies:" + key, HtmlHelper.toHtml(bodies.get(key))); + + outState.putLongArray("fair:html", Helper.toLongArray(html.keySet())); + for (Long key : html.keySet()) + outState.putString("fair:html:" + key, html.get(key)); + if (rvMessage != null) { Parcelable rv = rvMessage.getLayoutManager().onSaveInstanceState(); outState.putParcelable("fair:rv", rv); @@ -1509,13 +1518,18 @@ public class FragmentMessages extends FragmentBase { autoExpanded = savedInstanceState.getBoolean("fair:autoExpanded"); autoCloseCount = savedInstanceState.getInt("fair:autoCloseCount"); - String[] names = savedInstanceState.getStringArray("fair:values"); - for (String name : names) { + for (String name : savedInstanceState.getStringArray("fair:values")) { values.put(name, new ArrayList()); for (Long value : savedInstanceState.getLongArray("fair:name:" + name)) values.get(name).add(value); } + for (long id : savedInstanceState.getLongArray("fair:bodies")) + bodies.put(id, HtmlHelper.fromHtml(savedInstanceState.getString("fair:bodies:" + id))); + + for (long id : savedInstanceState.getLongArray("fair:html")) + html.put(id, savedInstanceState.getString("fair:html:" + id)); + if (rvMessage != null) { Parcelable rv = savedInstanceState.getBundle("fair:rv"); rvMessage.getLayoutManager().onRestoreInstanceState(rv); diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index 9ced4ce778..0cf2eb4f2f 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -88,6 +88,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.concurrent.ThreadFactory; import javax.mail.Address; @@ -1002,6 +1003,14 @@ public class Helper { return result; } + static long[] toLongArray(Set set) { + long[] result = new long[set.size()]; + int i = 0; + for (Long value : set) + result[i++] = value; + return result; + } + static List fromLongArray(long[] array) { List result = new ArrayList<>(); for (int i = 0; i < array.length; i++)