From 7094edd7498693136fbf68659c5967db63c7157b Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 15 Apr 2020 09:00:06 +0200 Subject: [PATCH] Limit search suggestions to current account/folder --- .../java/eu/faircode/email/DaoMessage.java | 13 +++++-- .../faircode/email/FragmentDialogSearch.java | 37 ++++++++++--------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index 7bdc9e244b..89abd77191 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -475,17 +475,24 @@ public interface DaoMessage { List getSnoozed(Long folder); @Query("SELECT id AS _id, subject AS suggestion FROM message" + - " WHERE subject LIKE :query" + + " WHERE (:account IS NULL OR message.account = :account)" + + " AND (:folder IS NULL OR message.folder = :folder)" + + " AND subject LIKE :query" + " AND NOT message.ui_hide" + " GROUP BY subject" + + " UNION" + + " SELECT id AS _id, sender AS suggestion FROM message" + - " WHERE sender LIKE :query" + + " WHERE (:account IS NULL OR message.account = :account)" + + " AND (:folder IS NULL OR message.folder = :folder)" + + " AND sender LIKE :query" + " AND NOT message.ui_hide" + " GROUP BY sender" + + " ORDER BY sender, subject" + " LIMIT 5") - Cursor getSuggestions(String query); + Cursor getSuggestions(Long account, Long folder, String query); @Query("SELECT language FROM message" + " WHERE (:account IS NULL OR message.account = :account)" + diff --git a/app/src/main/java/eu/faircode/email/FragmentDialogSearch.java b/app/src/main/java/eu/faircode/email/FragmentDialogSearch.java index a514df69fd..2c5b43e881 100644 --- a/app/src/main/java/eu/faircode/email/FragmentDialogSearch.java +++ b/app/src/main/java/eu/faircode/email/FragmentDialogSearch.java @@ -37,6 +37,22 @@ public class FragmentDialogSearch extends FragmentDialogBase { @NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { + final long account = getArguments().getLong("account", -1); + final long folder = getArguments().getLong("folder", -1); + + boolean pro = ActivityBilling.isPro(getContext()); + + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + boolean fts = prefs.getBoolean("fts", false); + boolean filter_seen = prefs.getBoolean("filter_seen", false); + boolean filter_unflagged = prefs.getBoolean("filter_unflagged", false); + boolean last_search_senders = prefs.getBoolean("last_search_senders", true); + boolean last_search_recipients = prefs.getBoolean("last_search_recipients", true); + boolean last_search_subject = prefs.getBoolean("last_search_subject", true); + boolean last_search_keywords = prefs.getBoolean("last_search_keywords", false); + boolean last_search_message = prefs.getBoolean("last_search_message", true); + String last_search = prefs.getString("last_search", null); + View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_search, null); final AutoCompleteTextView etQuery = dview.findViewById(R.id.etQuery); @@ -60,19 +76,6 @@ public class FragmentDialogSearch extends FragmentDialogBase { final TextView tvAfter = dview.findViewById(R.id.tvAfter); final Group grpMore = dview.findViewById(R.id.grpMore); - boolean pro = ActivityBilling.isPro(getContext()); - - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - boolean fts = prefs.getBoolean("fts", false); - boolean filter_seen = prefs.getBoolean("filter_seen", false); - boolean filter_unflagged = prefs.getBoolean("filter_unflagged", false); - boolean last_search_senders = prefs.getBoolean("last_search_senders", true); - boolean last_search_recipients = prefs.getBoolean("last_search_recipients", true); - boolean last_search_subject = prefs.getBoolean("last_search_subject", true); - boolean last_search_keywords = prefs.getBoolean("last_search_keywords", false); - boolean last_search_message = prefs.getBoolean("last_search_message", true); - String last_search = prefs.getString("last_search", null); - final InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); ibInfo.setOnClickListener(new View.OnClickListener() { @@ -102,7 +105,10 @@ public class FragmentDialogSearch extends FragmentDialogBase { String query = "%" + typed + "%"; DB db = DB.getInstance(getContext()); - return db.message().getSuggestions("%" + query + "%"); + return db.message().getSuggestions( + account < 0 ? null : account, + folder < 0 ? null : folder, + "%" + query + "%"); } }); @@ -227,9 +233,6 @@ public class FragmentDialogSearch extends FragmentDialogBase { .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - long account = getArguments().getLong("account", -1); - long folder = getArguments().getLong("folder", -1); - BoundaryCallbackMessages.SearchCriteria criteria = new BoundaryCallbackMessages.SearchCriteria(); criteria.query = etQuery.getText().toString();