From f1627e758b54ea7c51f1104e097145059b991a35 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 8 Sep 2020 14:47:32 +0200 Subject: [PATCH] Clear rules with transaction --- .../java/eu/faircode/email/FragmentRules.java | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentRules.java b/app/src/main/java/eu/faircode/email/FragmentRules.java index 7425c03ea0..f3107b0126 100644 --- a/app/src/main/java/eu/faircode/email/FragmentRules.java +++ b/app/src/main/java/eu/faircode/email/FragmentRules.java @@ -456,30 +456,36 @@ public class FragmentRules extends FragmentBase { boolean all = args.getBoolean("all"); DB db = DB.getInstance(context); + try { + db.beginTransaction(); - if (all) { - db.rule().deleteRules(fid); - return null; - } + if (all) + db.rule().deleteRules(fid); + else { + EntityFolder folder = db.folder().getFolder(fid); + if (folder == null) + return null; - EntityFolder folder = db.folder().getFolder(fid); - if (folder == null) - return null; + EntityFolder junk = db.folder().getFolderByType(folder.account, EntityFolder.JUNK); + if (junk == null) + return null; - EntityFolder junk = db.folder().getFolderByType(folder.account, EntityFolder.JUNK); - if (junk == null) - return null; + List rules = db.rule().getRules(fid); + if (rules == null) + return null; - List rules = db.rule().getRules(fid); - if (rules == null) - return null; + for (EntityRule rule : rules) { + JSONObject jaction = new JSONObject(rule.action); + int type = jaction.optInt("type", -1); + long target = jaction.optLong("target", -1); + if (type == TYPE_MOVE && target == junk.id) + db.rule().deleteRule(rule.id); + } + } - for (EntityRule rule : rules) { - JSONObject jaction = new JSONObject(rule.action); - int type = jaction.optInt("type", -1); - long target = jaction.optLong("target", -1); - if (type == TYPE_MOVE && target == junk.id) - db.rule().deleteRule(rule.id); + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); } return null;