From bce33a421a60407b9de8e663d0d1d03db8ee328d Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 16 Jun 2021 18:14:45 +0200 Subject: [PATCH] Added search options to exclude trash and junk folder --- .../email/BoundaryCallbackMessages.java | 24 ++++++++++++-- .../java/eu/faircode/email/DaoFolder.java | 3 ++ .../java/eu/faircode/email/DaoMessage.java | 3 +- .../faircode/email/FragmentDialogSearch.java | 31 +++++++++++++++++++ .../java/eu/faircode/email/FtsDbHelper.java | 11 ++++++- app/src/main/res/layout/dialog_search.xml | 26 ++++++++++++++-- app/src/main/res/values/strings.xml | 2 ++ 7 files changed, 94 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java b/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java index 21d2c79de2..8a9a03ad6f 100644 --- a/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java +++ b/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java @@ -224,12 +224,30 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback getFoldersByType(String type); + @Query("SELECT folder.* FROM folder" + " JOIN account ON account.id = folder.account" + " WHERE account.synchronize" + diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index 1602a6f742..87098455f3 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -346,11 +346,12 @@ public interface DaoMessage { " AND (:size IS NULL OR total > :size)" + " AND (:after IS NULL OR received > :after)" + " AND (:before IS NULL OR received < :before)" + + " AND NOT message.folder IN (:exclude)" + " GROUP BY message.id" + " ORDER BY matched DESC, received DESC" + " LIMIT :limit OFFSET :offset") List matchMessages( - Long account, Long folder, String find, + Long account, Long folder, long[] exclude, String find, boolean senders, boolean recipients, boolean subject, boolean keywords, boolean message, boolean notes, boolean headers, boolean unseen, boolean flagged, boolean hidden, boolean encrypted, boolean with_attachments, boolean with_notes, int type_count, String[] types, diff --git a/app/src/main/java/eu/faircode/email/FragmentDialogSearch.java b/app/src/main/java/eu/faircode/email/FragmentDialogSearch.java index be0e2c360e..51424ba0d5 100644 --- a/app/src/main/java/eu/faircode/email/FragmentDialogSearch.java +++ b/app/src/main/java/eu/faircode/email/FragmentDialogSearch.java @@ -78,6 +78,8 @@ public class FragmentDialogSearch extends FragmentDialogBase { boolean last_search_keywords = prefs.getBoolean("last_search_keywords", false); boolean last_search_message = prefs.getBoolean("last_search_message", true); boolean last_search_notes = prefs.getBoolean("last_search_notes", true); + boolean last_search_trash = prefs.getBoolean("last_search_trash", true); + boolean last_search_junk = prefs.getBoolean("last_search_junk", true); View dview = LayoutInflater.from(context).inflate(R.layout.dialog_search, null); @@ -110,6 +112,8 @@ public class FragmentDialogSearch extends FragmentDialogBase { final CheckBox cbEncrypted = dview.findViewById(R.id.cbEncrypted); final CheckBox cbAttachments = dview.findViewById(R.id.cbAttachments); final Spinner spMessageSize = dview.findViewById(R.id.spMessageSize); + final CheckBox cbSearchTrash = dview.findViewById(R.id.cbSearchTrash); + final CheckBox cbSearchJunk = dview.findViewById(R.id.cbSearchJunk); final Button btnBefore = dview.findViewById(R.id.btnBefore); final Button btnAfter = dview.findViewById(R.id.btnAfter); final TextView tvBefore = dview.findViewById(R.id.tvBefore); @@ -214,6 +218,8 @@ public class FragmentDialogSearch extends FragmentDialogBase { grpMore.setVisibility(View.GONE); cbHeaders.setVisibility(View.GONE); cbHtml.setVisibility(View.GONE); + cbSearchTrash.setVisibility(View.GONE); + cbSearchJunk.setVisibility(View.GONE); } else { ibMore.setImageLevel(0); grpMore.setVisibility(View.VISIBLE); @@ -221,6 +227,10 @@ public class FragmentDialogSearch extends FragmentDialogBase { cbHeaders.setVisibility(View.VISIBLE); cbHtml.setVisibility(View.VISIBLE); } + if (account < 0) { + cbSearchTrash.setVisibility(View.VISIBLE); + cbSearchJunk.setVisibility(View.VISIBLE); + } } } }; @@ -308,6 +318,20 @@ public class FragmentDialogSearch extends FragmentDialogBase { } }); + cbSearchTrash.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + prefs.edit().putBoolean("last_search_trash", isChecked).apply(); + } + }); + + cbSearchJunk.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + prefs.edit().putBoolean("last_search_junk", isChecked).apply(); + } + }); + btnAfter.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -333,10 +357,14 @@ public class FragmentDialogSearch extends FragmentDialogBase { cbNotes.setChecked(last_search_notes); tvAfter.setText(null); tvBefore.setText(null); + cbSearchTrash.setChecked(last_search_trash); + cbSearchJunk.setChecked(last_search_junk); grpMore.setVisibility(View.GONE); cbHeaders.setVisibility(View.GONE); cbHtml.setVisibility(View.GONE); + cbSearchTrash.setVisibility(View.GONE); + cbSearchJunk.setVisibility(View.GONE); final AlertDialog dialog = new AlertDialog.Builder(context) .setView(dview) @@ -390,6 +418,9 @@ public class FragmentDialogSearch extends FragmentDialogBase { } } + criteria.in_trash = cbSearchTrash.isChecked(); + criteria.in_junk = cbSearchJunk.isChecked(); + Object after = tvAfter.getTag(); Object before = tvBefore.getTag(); diff --git a/app/src/main/java/eu/faircode/email/FtsDbHelper.java b/app/src/main/java/eu/faircode/email/FtsDbHelper.java index 97fda42bfa..c4533878c3 100644 --- a/app/src/main/java/eu/faircode/email/FtsDbHelper.java +++ b/app/src/main/java/eu/faircode/email/FtsDbHelper.java @@ -137,7 +137,7 @@ public class FtsDbHelper extends SQLiteOpenHelper { static List match( SQLiteDatabase db, - Long account, Long folder, + Long account, Long folder, long[] exclude, BoundaryCallbackMessages.SearchCriteria criteria) { List word = new ArrayList<>(); @@ -200,6 +200,15 @@ public class FtsDbHelper extends SQLiteOpenHelper { select += "account = " + account + " AND "; if (folder != null) select += "folder = " + folder + " AND "; + if (exclude.length > 0) { + select += "NOT folder IN ("; + for (int i = 0; i < exclude.length; i++) { + if (i > 0) + select += ", "; + select += exclude[i]; + } + select += ") AND "; + } if (criteria.after != null) select += "time > " + criteria.after + " AND "; if (criteria.before != null) diff --git a/app/src/main/res/layout/dialog_search.xml b/app/src/main/res/layout/dialog_search.xml index e353763def..7298d4f63f 100644 --- a/app/src/main/res/layout/dialog_search.xml +++ b/app/src/main/res/layout/dialog_search.xml @@ -470,6 +470,28 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/spMessageSize" /> + + + +