From 2444aad6c7280eb255b3a46c228bbcaea9ac82d3 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 8 Aug 2021 12:01:49 +0200 Subject: [PATCH] Swipe delete / keep deleted --- .../eu/faircode/email/FragmentMessages.java | 63 +++++++++++++------ 1 file changed, 44 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 1bbdd5486c..31e8f19219 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -2437,27 +2437,52 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. private void onSwipeDelete(@NonNull TupleMessageEx message) { Bundle args = new Bundle(); - args.putString("question", getString(R.string.title_ask_delete)); - args.putString("remark", message.getRemark()); - args.putLong("id", message.id); - args.putInt("faq", 160); - args.putString("notagain", "delete_asked"); - args.putString("accept", getString(R.string.title_ask_delete_accept)); - args.putBoolean("warning", true); + args.putLong("account", message.account == null ? -1 : message.account); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - boolean delete_asked = prefs.getBoolean("delete_asked", false); - if (delete_asked) { - Intent data = new Intent(); - data.putExtra("args", args); - onActivityResult(REQUEST_MESSAGE_DELETE, RESULT_OK, data); - return; - } + new SimpleTask() { + @Override + protected EntityAccount onExecute(Context context, Bundle args) throws Throwable { + long aid = args.getLong("account"); - FragmentDialogAsk ask = new FragmentDialogAsk(); - ask.setArguments(args); - ask.setTargetFragment(FragmentMessages.this, REQUEST_MESSAGE_DELETE); - ask.show(getParentFragmentManager(), "swipe:delete"); + DB db = DB.getInstance(context); + return db.account().getAccount(aid); + } + + @Override + protected void onExecuted(Bundle args, EntityAccount account) { + boolean leave_deleted = (account != null && + account.protocol == EntityAccount.TYPE_POP && + account.leave_deleted); + + Bundle aargs = new Bundle(); + aargs.putString("question", getString(R.string.title_ask_delete)); + aargs.putString("remark", message.getRemark()); + aargs.putLong("id", message.id); + aargs.putInt("faq", 160); + aargs.putString("notagain", "delete_asked"); + aargs.putString("accept", getString(R.string.title_ask_delete_accept)); + aargs.putBoolean("warning", true); + + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + boolean delete_asked = prefs.getBoolean("delete_asked", false); + if (delete_asked || leave_deleted) { + Intent data = new Intent(); + data.putExtra("args", aargs); + onActivityResult(REQUEST_MESSAGE_DELETE, RESULT_OK, data); + return; + } + + FragmentDialogAsk ask = new FragmentDialogAsk(); + ask.setArguments(aargs); + ask.setTargetFragment(FragmentMessages.this, REQUEST_MESSAGE_DELETE); + ask.show(getParentFragmentManager(), "swipe:delete"); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(getParentFragmentManager(), ex); + } + }.execute(FragmentMessages.this, args, "message:delete"); } private void swipeFolder(@NonNull TupleMessageEx message, @NonNull Long target) {