Browse Source

Swa previous/next

main
M66B 6 years ago
parent
commit
e1b4d70543
2 changed files with 12 additions and 12 deletions
  1. +3
    -3
      app/src/main/java/eu/faircode/email/FragmentMessages.java
  2. +9
    -9
      app/src/main/java/eu/faircode/email/ViewModelMessages.java

+ 3
- 3
app/src/main/java/eu/faircode/email/FragmentMessages.java View File

@ -464,8 +464,8 @@ public class FragmentMessages extends FragmentEx {
bottom_navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { bottom_navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override @Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
ViewModelMessages.AccountThread[] pn = (ViewModelMessages.AccountThread[]) bottom_navigation.getTag();
ViewModelMessages.AccountThread target = (menuItem.getItemId() == R.id.action_prev ? pn[0] : pn[1]);
ViewModelMessages.Target[] pn = (ViewModelMessages.Target[]) bottom_navigation.getTag();
ViewModelMessages.Target target = (menuItem.getItemId() == R.id.action_prev ? pn[0] : pn[1]);
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext()); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.sendBroadcast( lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_THREAD) new Intent(ActivityView.ACTION_VIEW_THREAD)
@ -587,7 +587,7 @@ public class FragmentMessages extends FragmentEx {
if (viewType == AdapterMessage.ViewType.THREAD) { if (viewType == AdapterMessage.ViewType.THREAD) {
// Navigation // Navigation
ViewModelMessages model = ViewModelProviders.of(getActivity()).get(ViewModelMessages.class); ViewModelMessages model = ViewModelProviders.of(getActivity()).get(ViewModelMessages.class);
ViewModelMessages.AccountThread[] pn = model.getPrevNext(thread);
ViewModelMessages.Target[] pn = model.getPrevNext(thread);
bottom_navigation.setTag(pn); bottom_navigation.setTag(pn);
bottom_navigation.getMenu().findItem(R.id.action_prev).setEnabled(pn[0] != null); bottom_navigation.getMenu().findItem(R.id.action_prev).setEnabled(pn[0] != null);
bottom_navigation.getMenu().findItem(R.id.action_next).setEnabled(pn[1] != null); bottom_navigation.getMenu().findItem(R.id.action_next).setEnabled(pn[1] != null);


+ 9
- 9
app/src/main/java/eu/faircode/email/ViewModelMessages.java View File

@ -10,9 +10,9 @@ public class ViewModelMessages extends ViewModel {
this.messages = messages; this.messages = messages;
} }
AccountThread[] getPrevNext(String thread) {
Target[] getPrevNext(String thread) {
if (messages == null) if (messages == null)
return new AccountThread[]{null, null};
return new Target[]{null, null};
boolean found = false; boolean found = false;
TupleMessageEx prev = null; TupleMessageEx prev = null;
@ -22,25 +22,25 @@ public class ViewModelMessages extends ViewModel {
if (item == null) if (item == null)
continue; continue;
if (found) { if (found) {
next = item;
prev = item;
messages.loadAround(i); messages.loadAround(i);
break; break;
} }
if (thread.equals(item.thread)) if (thread.equals(item.thread))
found = true; found = true;
else else
prev = item;
next = item;
} }
return new AccountThread[]{
prev == null ? null : new AccountThread(prev.account, prev.thread),
next == null ? null : new AccountThread(next.account, next.thread)};
return new Target[]{
prev == null ? null : new Target(prev.account, prev.thread),
next == null ? null : new Target(next.account, next.thread)};
} }
class AccountThread {
class Target {
long account; long account;
String thread; String thread;
AccountThread(long account, String thread) {
Target(long account, String thread) {
this.account = account; this.account = account;
this.thread = thread; this.thread = thread;
} }


Loading…
Cancel
Save