From e0a3ea189eee7167f0df824c649dcbfffa520b2f Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 18 Oct 2018 07:01:35 +0000 Subject: [PATCH] Disable message action in outbox --- .../eu/faircode/email/AdapterMessage.java | 70 ++++++++++--------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 0aee9b41..bb244810 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -386,46 +386,48 @@ public class AdapterMessage extends PagedListAdapter>() { - @Override - public void onChanged(@Nullable List folders) { - if (bnvActions.hasTransientState()) { - boolean hasTrash = false; - boolean hasArchive = false; - boolean hasUser = false; - - if (folders != null) - for (EntityFolder folder : folders) { - if (EntityFolder.TRASH.equals(folder.type)) - hasTrash = true; - else if (EntityFolder.ARCHIVE.equals(folder.type)) - hasArchive = true; - else if (EntityFolder.USER.equals(folder.type)) - hasUser = true; - } + if (!EntityFolder.OUTBOX.equals(message.folderType)) { + bnvActions.setHasTransientState(true); + db.folder().liveFolders(message.account).observe(owner, new Observer>() { + @Override + public void onChanged(@Nullable List folders) { + if (bnvActions.hasTransientState()) { + boolean hasTrash = false; + boolean hasArchive = false; + boolean hasUser = false; + + if (folders != null) + for (EntityFolder folder : folders) { + if (EntityFolder.TRASH.equals(folder.type)) + hasTrash = true; + else if (EntityFolder.ARCHIVE.equals(folder.type)) + hasArchive = true; + else if (EntityFolder.USER.equals(folder.type)) + hasUser = true; + } - boolean inInbox = EntityFolder.INBOX.equals(message.folderType); - boolean inOutbox = EntityFolder.OUTBOX.equals(message.folderType); - boolean inArchive = EntityFolder.ARCHIVE.equals(message.folderType); - boolean inTrash = EntityFolder.TRASH.equals(message.folderType); + boolean inInbox = EntityFolder.INBOX.equals(message.folderType); + boolean inOutbox = EntityFolder.OUTBOX.equals(message.folderType); + boolean inArchive = EntityFolder.ARCHIVE.equals(message.folderType); + boolean inTrash = EntityFolder.TRASH.equals(message.folderType); - ActionData data = new ActionData(); - data.delete = (inTrash || !hasTrash || inOutbox); - data.message = message; - bnvActions.setTag(data); + ActionData data = new ActionData(); + data.delete = (inTrash || !hasTrash || inOutbox); + data.message = message; + bnvActions.setTag(data); - bnvActions.getMenu().findItem(R.id.action_delete).setVisible((message.uid != null && hasTrash) || (inOutbox && !TextUtils.isEmpty(message.error))); - bnvActions.getMenu().findItem(R.id.action_move).setVisible(message.uid != null && (!inInbox || hasUser)); - bnvActions.getMenu().findItem(R.id.action_archive).setVisible(message.uid != null && !inArchive && hasArchive); - bnvActions.getMenu().findItem(R.id.action_reply).setVisible(message.content && !inOutbox); + bnvActions.getMenu().findItem(R.id.action_delete).setVisible((message.uid != null && hasTrash) || (inOutbox && !TextUtils.isEmpty(message.error))); + bnvActions.getMenu().findItem(R.id.action_move).setVisible(message.uid != null && (!inInbox || hasUser)); + bnvActions.getMenu().findItem(R.id.action_archive).setVisible(message.uid != null && !inArchive && hasArchive); + bnvActions.getMenu().findItem(R.id.action_reply).setVisible(message.content && !inOutbox); - bnvActions.setVisibility(View.VISIBLE); + bnvActions.setVisibility(View.VISIBLE); - bnvActions.setHasTransientState(false); + bnvActions.setHasTransientState(false); + } } - } - }); + }); + } // Observe attachments db.attachment().liveAttachments(message.id).observe(owner,