From a0c2e41adb389d533f530117fdc4e748b97702cb Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 24 Jul 2019 18:46:39 +0200 Subject: [PATCH] Added special searches --- .../email/BoundaryCallbackMessages.java | 60 ++++++++++----- .../eu/faircode/email/FragmentMessages.java | 76 ++++++++++++------- app/src/main/res/values/strings.xml | 5 ++ 3 files changed, 93 insertions(+), 48 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java b/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java index d691057db5..7968e7b5d6 100644 --- a/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java +++ b/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java @@ -190,30 +190,40 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback 0) - for (int j = 0; j < message.from.length && !match; j++) - match = message.from[j].toString().toLowerCase().contains(find); + if (find.startsWith(context.getString(R.string.title_search_special_prefix) + ":")) { + String special = find.split(":")[1]; + if (context.getString(R.string.title_search_special_unseen).equals(special)) + match = !message.ui_seen; + else if (context.getString(R.string.title_search_special_flagged).equals(special)) + match = message.ui_flagged; + else if (context.getString(R.string.title_search_special_snoozed).equals(special)) + match = (message.ui_snoozed != null); + } else { + if (message.from != null && message.from.length > 0) + for (int j = 0; j < message.from.length && !match; j++) + match = message.from[j].toString().toLowerCase().contains(find); - if (!match && message.to != null && message.to.length > 0) - for (int j = 0; j < message.to.length && !match; j++) - match = message.to[j].toString().toLowerCase().contains(find); + if (!match && message.to != null && message.to.length > 0) + for (int j = 0; j < message.to.length && !match; j++) + match = message.to[j].toString().toLowerCase().contains(find); - if (!match && message.subject != null) - match = message.subject.toLowerCase().contains(find); + if (!match && message.subject != null) + match = message.subject.toLowerCase().contains(find); - if (!match && message.keywords != null && message.keywords.length > 0) - for (String keyword : message.keywords) - if (keyword.toLowerCase().contains(find)) { - match = true; - break; + if (!match && message.keywords != null && message.keywords.length > 0) + for (String keyword : message.keywords) + if (keyword.toLowerCase().contains(find)) { + match = true; + break; + } + + if (!match && message.content) { + try { + String body = Helper.readText(message.getFile(context)); + match = body.toLowerCase().contains(find); + } catch (IOException ex) { + Log.e(ex); } - - if (!match && message.content) { - try { - String body = Helper.readText(message.getFile(context)); - match = body.toLowerCase().contains(find); - } catch (IOException ex) { - Log.e(ex); } } } @@ -281,7 +291,15 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback() { - @Override - protected Cursor onExecute(Context context, Bundle args) { - String query = args.getString("query"); + new SimpleTask() { + @Override + protected Cursor onExecute(Context context, Bundle args) { + String query = args.getString("query"); - DB db = DB.getInstance(context); - return db.message().getSuggestions("%" + query + "%"); - } + DB db = DB.getInstance(context); + return db.message().getSuggestions("%" + query + "%"); + } - @Override - protected void onExecuted(Bundle args, Cursor cursor) { - Log.i("Suggestions=" + cursor.getCount()); - SimpleCursorAdapter adapter = new SimpleCursorAdapter( - getContext(), - R.layout.search_suggestion, - cursor, - new String[]{"suggestion"}, - new int[]{android.R.id.text1}, - 0); - searchView.setSuggestionsAdapter(adapter); - adapter.notifyDataSetChanged(); - } + @Override + protected void onExecuted(Bundle args, Cursor cursor) { + Log.i("Suggestions=" + cursor.getCount()); + SimpleCursorAdapter adapter = new SimpleCursorAdapter( + getContext(), + R.layout.search_suggestion, + cursor, + new String[]{"suggestion"}, + new int[]{android.R.id.text1}, + 0); + searchView.setSuggestionsAdapter(adapter); + adapter.notifyDataSetChanged(); + } - @Override - protected void onException(Bundle args, Throwable ex) { - Helper.unexpectedError(getFragmentManager(), ex); - } - }.execute(FragmentMessages.this, args, "messages:suggestions"); + @Override + protected void onException(Bundle args, Throwable ex) { + Helper.unexpectedError(getFragmentManager(), ex); + } + }.execute(FragmentMessages.this, args, "messages:suggestions"); + } return true; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 252803ec8e..c0736a8092 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -783,6 +783,11 @@ Please describe what you were doing when the app crashed: FairEmail %1$s issue + special + unread + starred + snoozed + Always Every 15 minutes