From 866213a891fd418ee05e3b9a53fa0bab1cb8a17f Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 28 Sep 2020 20:36:54 +0200 Subject: [PATCH] Updated selected message on navigating --- .../eu/faircode/email/FragmentMessages.java | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index cd8b1bd1d2..4f59aa9a12 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -100,6 +100,7 @@ import androidx.core.content.ContextCompat; import androidx.core.graphics.ColorUtils; import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentResultListener; import androidx.fragment.app.FragmentTransaction; import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleOwner; @@ -293,6 +294,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. private boolean loading = false; private boolean swiping = false; private boolean scrolling = false; + private boolean navigating = false; private AdapterMessage adapter; @@ -424,6 +426,15 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. viewType = AdapterMessage.ViewType.SEARCH; setTitle(server ? R.string.title_search_server : R.string.title_search_device); } + + if (viewType != AdapterMessage.ViewType.THREAD) + getParentFragmentManager().setFragmentResultListener("message.selected", this, new FragmentResultListener() { + @Override + public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle result) { + long id = result.getLong("id", -1); + iProperties.setValue("selected", id, true); + } + }); } @Override @@ -1587,9 +1598,11 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. values.get(name).remove(id); if ("selected".equals(name) && enabled) { + final List changed = new ArrayList<>(); + int pos = adapter.getPositionForKey(id); if (pos != NO_POSITION) - adapter.notifyItemChanged(pos); + changed.add(pos); for (Long other : new ArrayList<>(values.get("selected"))) if (!other.equals(id)) { @@ -1597,8 +1610,20 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. pos = adapter.getPositionForKey(other); if (pos != NO_POSITION) - adapter.notifyItemChanged(pos); + changed.add(pos); } + + rvMessage.post(new Runnable() { + @Override + public void run() { + try { + for (Integer pos : changed) + adapter.notifyItemChanged(pos); + } catch (Throwable ex) { + Log.e(ex); + } + } + }); } } @@ -4870,6 +4895,13 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. private void navigate(long id, final boolean left) { if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) return; + if (navigating) + return; + navigating = true; + + Bundle result = new Bundle(); + result.putLong("id", id); + getParentFragmentManager().setFragmentResult("message.selected", result); Bundle args = new Bundle(); args.putLong("id", id);