From 74216a2e4d18f9bda71759295c07b2774105df2a Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 20 Oct 2018 19:04:05 +0000 Subject: [PATCH] Fixed previous/next cross account --- .../eu/faircode/email/FragmentMessages.java | 10 +++++----- .../eu/faircode/email/ViewModelMessages.java | 18 +++++++++++++++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index be31a2ca..d5ab6a94 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -464,13 +464,13 @@ public class FragmentMessages extends FragmentEx { bottom_navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { - String[] pn = (String[]) bottom_navigation.getTag(); - String thread = (menuItem.getItemId() == R.id.action_prev ? pn[0] : pn[1]); + ViewModelMessages.AccountThread[] pn = (ViewModelMessages.AccountThread[]) bottom_navigation.getTag(); + ViewModelMessages.AccountThread target = (menuItem.getItemId() == R.id.action_prev ? pn[0] : pn[1]); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext()); lbm.sendBroadcast( new Intent(ActivityView.ACTION_VIEW_THREAD) - .putExtra("account", account) - .putExtra("thread", thread)); + .putExtra("account", target.account) + .putExtra("thread", target.thread)); return true; } }); @@ -587,7 +587,7 @@ public class FragmentMessages extends FragmentEx { if (viewType == AdapterMessage.ViewType.THREAD) { // Navigation ViewModelMessages model = ViewModelProviders.of(getActivity()).get(ViewModelMessages.class); - String[] pn = model.getPrevNext(thread); + ViewModelMessages.AccountThread[] pn = model.getPrevNext(thread); bottom_navigation.setTag(pn); bottom_navigation.getMenu().findItem(R.id.action_prev).setEnabled(pn[0] != null); bottom_navigation.getMenu().findItem(R.id.action_next).setEnabled(pn[1] != null); diff --git a/app/src/main/java/eu/faircode/email/ViewModelMessages.java b/app/src/main/java/eu/faircode/email/ViewModelMessages.java index baa22ee4..c26b7fab 100644 --- a/app/src/main/java/eu/faircode/email/ViewModelMessages.java +++ b/app/src/main/java/eu/faircode/email/ViewModelMessages.java @@ -10,9 +10,9 @@ public class ViewModelMessages extends ViewModel { this.messages = messages; } - String[] getPrevNext(String thread) { + AccountThread[] getPrevNext(String thread) { if (messages == null) - return new String[]{null, null}; + return new AccountThread[]{null, null}; boolean found = false; TupleMessageEx prev = null; @@ -31,6 +31,18 @@ public class ViewModelMessages extends ViewModel { else prev = item; } - return new String[]{prev == null ? null : prev.thread, next == null ? null : next.thread}; + return new AccountThread[]{ + prev == null ? null : new AccountThread(prev.account, prev.thread), + next == null ? null : new AccountThread(next.account, next.thread)}; + } + + class AccountThread { + long account; + String thread; + + AccountThread(long account, String thread) { + this.account = account; + this.thread = thread; + } } }