From 905e79fc8b51d7d1983c4d20ddd1a8dc0dcaa9f9 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 23 Mar 2022 10:05:58 +0100 Subject: [PATCH] Clear contacts by type --- .../java/eu/faircode/email/DaoContact.java | 5 ++--- .../eu/faircode/email/FragmentContacts.java | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DaoContact.java b/app/src/main/java/eu/faircode/email/DaoContact.java index 9a40185051..8fc7a5c4b1 100644 --- a/app/src/main/java/eu/faircode/email/DaoContact.java +++ b/app/src/main/java/eu/faircode/email/DaoContact.java @@ -103,7 +103,6 @@ public interface DaoContact { int deleteContacts(long before); @Query("DELETE FROM contact" + - " WHERE (type = " + EntityContact.TYPE_TO + - " OR type = " + EntityContact.TYPE_FROM + ")") - int clearContacts(); + " WHERE type IN (:types)") + int clearContacts(int[] types); } diff --git a/app/src/main/java/eu/faircode/email/FragmentContacts.java b/app/src/main/java/eu/faircode/email/FragmentContacts.java index d7f5eab5b7..783b3cb033 100644 --- a/app/src/main/java/eu/faircode/email/FragmentContacts.java +++ b/app/src/main/java/eu/faircode/email/FragmentContacts.java @@ -205,6 +205,8 @@ public class FragmentContacts extends FragmentBase { public void onPrepareOptionsMenu(@NonNull Menu menu) { super.onPrepareOptionsMenu(menu); menu.findItem(R.id.menu_junk).setChecked(junk); + menu.findItem(R.id.menu_import).setVisible(!junk); + menu.findItem(R.id.menu_export).setVisible(!junk); } @Override @@ -253,7 +255,12 @@ public class FragmentContacts extends FragmentBase { } private void onMenuDeleteAll() { - new FragmentDelete().show(getParentFragmentManager(), "contacts:delete"); + Bundle args = new Bundle(); + args.putBoolean("junk", junk); + + FragmentDelete fragment = new FragmentDelete(); + fragment.setArguments(args); + fragment.show(getParentFragmentManager(), "contacts:delete"); } @Override @@ -482,8 +489,13 @@ public class FragmentContacts extends FragmentBase { new SimpleTask() { @Override protected Void onExecute(Context context, Bundle args) { + boolean junk = (args != null && args.getBoolean("junk")); + int[] types = (junk + ? new int[]{EntityContact.TYPE_JUNK, EntityContact.TYPE_NO_JUNK} + : new int[]{EntityContact.TYPE_FROM, EntityContact.TYPE_TO}); + DB db = DB.getInstance(context); - int count = db.contact().clearContacts(); + int count = db.contact().clearContacts(types); Log.i("Cleared contacts=" + count); return null; } @@ -492,7 +504,7 @@ public class FragmentContacts extends FragmentBase { protected void onException(Bundle args, Throwable ex) { Log.unexpectedError(getParentFragmentManager(), ex); } - }.execute(getContext(), getActivity(), new Bundle(), "contacts:delete"); + }.execute(getContext(), getActivity(), getArguments(), "contacts:delete"); } }) .setNegativeButton(android.R.string.cancel, null)