From 39717470a3b448850771bf0216209c6cb02acadc Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 27 Dec 2018 14:16:45 +0000 Subject: [PATCH] Updated action bar on load messages --- .../eu/faircode/email/FragmentMessages.java | 125 ++++++++---------- 1 file changed, 57 insertions(+), 68 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 1391528399..a7b2b5c4be 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -1334,74 +1334,6 @@ public class FragmentMessages extends FragmentEx { trashes.add(folder.account); loadMessages(); - - if (actionbar && viewType == AdapterMessage.ViewType.THREAD) { - boolean hasTrash = false; - boolean hasArchive = false; - for (EntityFolder folder : folders) - if (EntityFolder.TRASH.equals(folder.type)) - hasTrash = true; - else if (EntityFolder.ARCHIVE.equals(folder.type)) - hasArchive = true; - - ViewModelMessages model = ViewModelProviders.of(getActivity()).get(ViewModelMessages.class); - ViewModelMessages.Target[] 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); - - Bundle args = new Bundle(); - args.putLong("account", account); - args.putString("thread", thread); - args.putLong("id", id); - args.putBoolean("hasTrash", hasTrash); - args.putBoolean("hasArchive", hasArchive); - - new SimpleTask() { - @Override - protected Boolean[] onLoad(Context context, Bundle args) { - long account = args.getLong("account"); - String thread = args.getString("thread"); - long id = args.getLong("id"); - - List messages = db.message().getMessageByThread( - account, thread, threading ? null : id, null); - - boolean trashable = false; - boolean archivable = false; - for (EntityMessage message : messages) { - EntityFolder folder = db.folder().getFolder(message.folder); - if (!EntityFolder.DRAFTS.equals(folder.type) && - !EntityFolder.OUTBOX.equals(folder.type) && - // allow sent - !EntityFolder.TRASH.equals(folder.type) && - !EntityFolder.JUNK.equals(folder.type)) - trashable = true; - if (!EntityFolder.isOutgoing(folder.type) && - !EntityFolder.TRASH.equals(folder.type) && - !EntityFolder.JUNK.equals(folder.type) && - !EntityFolder.ARCHIVE.equals(folder.type)) - archivable = true; - } - - return new Boolean[]{trashable, archivable}; - } - - @Override - protected void onLoaded(Bundle args, Boolean[] data) { - boolean hasTrash = args.getBoolean("hasTrash"); - boolean hasArchive = args.getBoolean("hasArchive"); - bottom_navigation.getMenu().findItem(R.id.action_delete).setVisible(hasTrash && data[0]); - bottom_navigation.getMenu().findItem(R.id.action_archive).setVisible(hasArchive && data[1]); - bottom_navigation.setVisibility(View.VISIBLE); - } - - @Override - protected void onException(Bundle args, Throwable ex) { - - } - }.load(FragmentMessages.this, args); - } } }); @@ -1863,6 +1795,63 @@ public class FragmentMessages extends FragmentEx { } } } + + if (actionbar) { + ViewModelMessages model = ViewModelProviders.of(getActivity()).get(ViewModelMessages.class); + ViewModelMessages.Target[] 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); + + Bundle args = new Bundle(); + args.putLong("account", account); + args.putString("thread", thread); + args.putLong("id", id); + + new SimpleTask() { + @Override + protected Boolean[] onLoad(Context context, Bundle args) { + long account = args.getLong("account"); + String thread = args.getString("thread"); + long id = args.getLong("id"); + + List messages = db.message().getMessageByThread( + account, thread, threading ? null : id, null); + + boolean trashable = false; + boolean archivable = false; + for (EntityMessage message : messages) { + EntityFolder folder = db.folder().getFolder(message.folder); + if (!EntityFolder.DRAFTS.equals(folder.type) && + !EntityFolder.OUTBOX.equals(folder.type) && + // allow sent + !EntityFolder.TRASH.equals(folder.type) && + !EntityFolder.JUNK.equals(folder.type)) + trashable = true; + if (!EntityFolder.isOutgoing(folder.type) && + !EntityFolder.TRASH.equals(folder.type) && + !EntityFolder.JUNK.equals(folder.type) && + !EntityFolder.ARCHIVE.equals(folder.type)) + archivable = true; + } + + return new Boolean[]{trashable, archivable}; + } + + @Override + protected void onLoaded(Bundle args, Boolean[] data) { + bottom_navigation.getMenu().findItem(R.id.action_delete).setVisible(trashes.size() > 0 && data[0]); + bottom_navigation.getMenu().findItem(R.id.action_archive).setVisible(archives.size() > 0 && data[1]); + bottom_navigation.setVisibility(View.VISIBLE); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + + } + }.load(FragmentMessages.this, args); + } + } else { ViewModelMessages model = ViewModelProviders.of(getActivity()).get(ViewModelMessages.class); model.setMessages(messages);