From 64af3ba9b87c8898cdecb08d7550409d7cf5d09f Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 1 Jan 2020 10:08:04 +0100 Subject: [PATCH] Allow deleting trash/spam of all accounts --- .../eu/faircode/email/FragmentMessages.java | 51 ++++++++++++------- app/src/main/res/values/strings.xml | 2 + 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 6255289009..19dc260d53 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -2927,10 +2927,12 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. menu.findItem(R.id.menu_select_all).setVisible(!outbox && (viewType == AdapterMessage.ViewType.UNIFIED || viewType == AdapterMessage.ViewType.FOLDER)); menu.findItem(R.id.menu_select_found).setVisible(viewType == AdapterMessage.ViewType.SEARCH); - menu.findItem(R.id.menu_empty_trash).setVisible( - viewType == AdapterMessage.ViewType.FOLDER && EntityFolder.TRASH.equals(type)); - menu.findItem(R.id.menu_empty_spam).setVisible( - viewType == AdapterMessage.ViewType.FOLDER && EntityFolder.JUNK.equals(type)); + menu.findItem(R.id.menu_empty_trash).setVisible(EntityFolder.TRASH.equals(type) && + (viewType == AdapterMessage.ViewType.UNIFIED || + viewType == AdapterMessage.ViewType.FOLDER)); + menu.findItem(R.id.menu_empty_spam).setVisible(EntityFolder.JUNK.equals(type) && + (viewType == AdapterMessage.ViewType.UNIFIED || + viewType == AdapterMessage.ViewType.FOLDER)); menu.findItem(R.id.menu_force_sync).setVisible(viewType == AdapterMessage.ViewType.UNIFIED); @@ -3132,12 +3134,14 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. private void onMenuEmpty(String type) { Bundle aargs = new Bundle(); if (EntityFolder.TRASH.equals(type)) - aargs.putString("question", getString(R.string.title_empty_trash_ask)); + aargs.putString("question", getString( + account < 0 ? R.string.title_empty_trash_all_ask : R.string.title_empty_trash_ask)); else if (EntityFolder.JUNK.equals(type)) - aargs.putString("question", getString(R.string.title_empty_spam_ask)); + aargs.putString("question", getString( + account < 0 ? R.string.title_empty_spam_all_ask : R.string.title_empty_spam_ask)); else throw new IllegalArgumentException("Invalid folder type=" + type); - aargs.putLong("folder", folder); + aargs.putLong("account", account); aargs.putString("type", type); FragmentDialogAsk ask = new FragmentDialogAsk(); @@ -5349,25 +5353,36 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. new SimpleTask() { @Override protected Void onExecute(Context context, Bundle args) { - long fid = args.getLong("folder"); + long aid = args.getLong("account"); String type = args.getString("type"); DB db = DB.getInstance(context); try { db.beginTransaction(); - EntityFolder folder = db.folder().getFolder(fid); - if (folder == null) - return null; + List accounts; + if (account < 0) + accounts = db.account().getSynchronizingAccounts(); + else { + EntityAccount account = db.account().getAccount(aid); + if (account == null) + return null; + accounts = Arrays.asList(account); + } - if (!folder.type.equals(type)) - throw new IllegalStateException("Invalid folder type=" + type); + for (EntityAccount account : accounts) { + EntityFolder folder = db.folder().getFolderByType(account.id, type); + if (folder == null) + continue; - List ids = db.message().getMessageByFolder(folder.id); - for (Long id : ids) { - EntityMessage message = db.message().getMessage(id); - if (message.uid != null || !TextUtils.isEmpty(message.msgid)) - EntityOperation.queue(context, message, EntityOperation.DELETE); + List ids = db.message().getMessageByFolder(folder.id); + for (Long id : ids) { + EntityMessage message = db.message().getMessage(id); + if (message.uid != null || !TextUtils.isEmpty(message.msgid)) { + Log.i("Deleting account=" + account.id + " folder=" + folder.id + " message=" + message.id); + EntityOperation.queue(context, message, EntityOperation.DELETE); + } + } } db.setTransactionSuccessful(); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a2de0afb9f..9c1e43d8db 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -529,6 +529,8 @@ Delete all trashed messages permanently? Delete all spam messages permanently? + Delete all trashed messages of all accounts permanently? + Delete all spam messages of all accounts permanently? Delete operations with an error message? Delete all local contacts? No pending operations