Delete junk or all rules

pull/184/head
M66B 4 years ago
parent 924ee857da
commit 2ecbb4f86f

@ -73,4 +73,7 @@ public interface DaoRule {
@Query("DELETE FROM rule WHERE id = :id")
void deleteRule(long id);
@Query("DELETE FROM rule WHERE folder = :folder")
void deleteRules(long folder);
}

@ -229,25 +229,30 @@ public class FragmentRules extends FragmentBase {
@Override
public void onPrepareOptionsMenu(@NonNull Menu menu) {
super.onPrepareOptionsMenu(menu);
menu.findItem(R.id.menu_clear_spam).setVisible(!EntityFolder.JUNK.equals(type));
menu.findItem(R.id.menu_delete_junk).setVisible(!EntityFolder.JUNK.equals(type));
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_clear_spam:
onMenuClearSpam();
case R.id.menu_delete_all:
onMenuDelete(true);
return true;
case R.id.menu_delete_junk:
onMenuDelete(false);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void onMenuClearSpam() {
private void onMenuDelete(boolean all) {
Bundle aargs = new Bundle();
aargs.putString("question", getString(R.string.title_rules_clear_confirm));
aargs.putString("question", getString(all
? R.string.title_rules_delete_all_confirm
: R.string.title_rules_delete_junk_confirm));
aargs.putLong("folder", folder);
aargs.putBoolean("all", all);
FragmentDialogAsk ask = new FragmentDialogAsk();
ask.setArguments(aargs);
@ -279,8 +284,15 @@ public class FragmentRules extends FragmentBase {
@Override
protected Void onExecute(Context context, Bundle args) throws Throwable {
long fid = args.getLong("folder");
boolean all = args.getBoolean("all");
DB db = DB.getInstance(context);
if (all) {
db.rule().deleteRules(fid);
return null;
}
EntityFolder folder = db.folder().getFolder(fid);
if (folder == null)
return null;
@ -295,8 +307,9 @@ public class FragmentRules extends FragmentBase {
for (EntityRule rule : rules) {
JSONObject jaction = new JSONObject(rule.action);
if (jaction.optInt("type", -1) == TYPE_MOVE &&
jaction.optInt("target", -1) == junk.id)
int type = jaction.optInt("type", -1);
long target = jaction.optLong("target", -1);
if (type == TYPE_MOVE && target == junk.id)
db.rule().deleteRule(rule.id);
}

@ -9,7 +9,12 @@
app:showAsAction="collapseActionView|always" />
<item
android:id="@+id/menu_clear_spam"
android:title="@string/title_rules_clear"
android:id="@+id/menu_delete_all"
android:title="@string/title_rules_delete_all"
app:showAsAction="never" />
<item
android:id="@+id/menu_delete_junk"
android:title="@string/title_rules_delete_junk"
app:showAsAction="never" />
</menu>

@ -1374,8 +1374,10 @@
<string name="title_auto_scroll">Auto scroll</string>
<string name="title_log_clear">Clear</string>
<string name="title_rules_search_hint">Search name or condition</string>
<string name="title_rules_clear">Clear spam rules</string>
<string name="title_rules_clear_confirm">Delete all rules moving messages to the spam folder?</string>
<string name="title_rules_delete_all">Delete all rules</string>
<string name="title_rules_delete_junk">Delete spam rules</string>
<string name="title_rules_delete_all_confirm">Delete all rules?</string>
<string name="title_rules_delete_junk_confirm">Delete all rules moving messages to the spam folder?</string>
<string name="title_debug_info">Debug info</string>
<string name="title_debug_info_remark">Please describe the problem and indicate the time of the problem:</string>
<string name="title_crash_info_remark">Please describe what you were doing when the app crashed:</string>

Loading…
Cancel
Save