From 24b6da0598810435f592d99fb99e03cc2fa33149 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 20 Aug 2020 22:31:39 +0200 Subject: [PATCH] Simplification --- .../eu/faircode/email/FragmentAccounts.java | 17 +++++++++-------- .../eu/faircode/email/FragmentFolders.java | 16 ++++++++++++++-- .../eu/faircode/email/FragmentMessages.java | 18 ++++++++---------- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentAccounts.java b/app/src/main/java/eu/faircode/email/FragmentAccounts.java index 36a8fd825d..bfcafa376f 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccounts.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccounts.java @@ -195,14 +195,15 @@ public class FragmentAccounts extends FragmentBase { @Override protected void onExecuted(Bundle args, EntityFolder drafts) { - if (drafts != null) { - LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext()); - lbm.sendBroadcast( - new Intent(ActivityView.ACTION_VIEW_MESSAGES) - .putExtra("account", drafts.account) - .putExtra("folder", drafts.id) - .putExtra("type", drafts.type)); - } + if (drafts == null) + return; + + LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext()); + lbm.sendBroadcast( + new Intent(ActivityView.ACTION_VIEW_MESSAGES) + .putExtra("account", drafts.account) + .putExtra("folder", drafts.id) + .putExtra("type", drafts.type)); } @Override diff --git a/app/src/main/java/eu/faircode/email/FragmentFolders.java b/app/src/main/java/eu/faircode/email/FragmentFolders.java index 40f7d9b5d1..329ba6d004 100644 --- a/app/src/main/java/eu/faircode/email/FragmentFolders.java +++ b/app/src/main/java/eu/faircode/email/FragmentFolders.java @@ -207,14 +207,26 @@ public class FragmentFolders extends FragmentBase { fabCompose.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { + Bundle args = new Bundle(); + args.putLong("account", account); + new SimpleTask() { @Override protected EntityFolder onExecute(Context context, Bundle args) { - return DB.getInstance(context).folder().getPrimaryDrafts(); + long account = args.getLong("account"); + + DB db = DB.getInstance(context); + if (account < 0) + return db.folder().getPrimaryDrafts(); + else + return db.folder().getFolderByType(account, EntityFolder.DRAFTS); } @Override protected void onExecuted(Bundle args, EntityFolder drafts) { + if (drafts == null) + return; + LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext()); lbm.sendBroadcast( new Intent(ActivityView.ACTION_VIEW_MESSAGES) @@ -227,7 +239,7 @@ public class FragmentFolders extends FragmentBase { protected void onException(Bundle args, Throwable ex) { Log.unexpectedError(getParentFragmentManager(), ex); } - }.execute(FragmentFolders.this, new Bundle(), "folders:drafts"); + }.execute(FragmentFolders.this, args, "folders:drafts"); return true; } diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 0c7cbe5cbd..ed99d74a01 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -987,16 +987,14 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. @Override protected void onExecuted(Bundle args, EntityFolder drafts) { if (drafts == null) - Snackbar.make(view, R.string.title_no_drafts, Snackbar.LENGTH_LONG) - .setGestureInsetBottomIgnored(true).show(); - else { - LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext()); - lbm.sendBroadcast( - new Intent(ActivityView.ACTION_VIEW_MESSAGES) - .putExtra("account", drafts.account) - .putExtra("folder", drafts.id) - .putExtra("type", drafts.type)); - } + return; + + LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext()); + lbm.sendBroadcast( + new Intent(ActivityView.ACTION_VIEW_MESSAGES) + .putExtra("account", drafts.account) + .putExtra("folder", drafts.id) + .putExtra("type", drafts.type)); } @Override