From a85b5434ab25925c70f75c5e1968ddfc12321b5e Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 18 Oct 2018 10:17:58 +0000 Subject: [PATCH] Fixed crash --- .../java/eu/faircode/email/ActivityView.java | 25 ------------------- .../eu/faircode/email/FragmentMessages.java | 10 +++++--- 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index 49cf5c96..e56850f7 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -885,29 +885,4 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB }.load(this, args); } } - - void setMessages(PagedList messages) { - this.messages = messages; - } - - public String[] getPrevNext(String thread) { - boolean found = false; - TupleMessageEx prev = null; - TupleMessageEx next = null; - for (int i = 0; i < messages.size(); i++) { - TupleMessageEx item = messages.get(i); - if (item == null) - continue; - if (found) { - next = item; - messages.loadAround(i); - break; - } - if (thread.equals(item.thread)) - found = true; - else - prev = item; - } - return new String[]{prev == null ? null : prev.thread, next == null ? null : next.thread}; - } } diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index f531afa1..84ac25bf 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -57,6 +57,7 @@ import androidx.fragment.app.FragmentTransaction; import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LiveData; import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewModelProviders; import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.paging.LivePagedListBuilder; import androidx.paging.PagedList; @@ -585,7 +586,8 @@ public class FragmentMessages extends FragmentEx { // Compose FAB if (viewType == AdapterMessage.ViewType.THREAD) { - String[] pn = ((ActivityView) getActivity()).getPrevNext(thread); + ViewModelMessages model = ViewModelProviders.of(getActivity()).get(ViewModelMessages.class); + String[] pn = model.getPrevNext(thread); fabPrev.setTag(pn[0]); fabNext.setTag(pn[1]); @@ -854,8 +856,10 @@ public class FragmentMessages extends FragmentEx { return; } - if (viewType != AdapterMessage.ViewType.THREAD) - ((ActivityView) getActivity()).setMessages(messages); + if (viewType != AdapterMessage.ViewType.THREAD) { + ViewModelMessages model = ViewModelProviders.of(getActivity()).get(ViewModelMessages.class); + model.setMessages(messages); + } if (viewType == AdapterMessage.ViewType.THREAD && autoExpand) { autoExpand = false;