Fixed previous/next cross account

pull/146/head
M66B 6 years ago
parent be6f1d206e
commit 74216a2e4d

@ -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);

@ -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;
}
}
}

Loading…
Cancel
Save