Added search for messages with attachment

pull/174/head
M66B 6 years ago
parent e7209b9cd3
commit 2fc758ef0b

@ -171,6 +171,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
Boolean flagged = null; Boolean flagged = null;
Boolean snoozed = null; Boolean snoozed = null;
Boolean encrypted = null; Boolean encrypted = null;
Boolean attachments = null;
String find = (TextUtils.isEmpty(query) ? null : query.toLowerCase()); String find = (TextUtils.isEmpty(query) ? null : query.toLowerCase());
if (find != null && find.startsWith(context.getString(R.string.title_search_special_prefix) + ":")) { if (find != null && find.startsWith(context.getString(R.string.title_search_special_prefix) + ":")) {
String special = find.split(":")[1]; String special = find.split(":")[1];
@ -182,6 +183,8 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
snoozed = true; snoozed = true;
else if (context.getString(R.string.title_search_special_encrypted).equals(special)) else if (context.getString(R.string.title_search_special_encrypted).equals(special))
encrypted = true; encrypted = true;
else if (context.getString(R.string.title_search_special_attachments).equals(special))
attachments = true;
} }
int found = 0; int found = 0;
@ -189,7 +192,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean fts = prefs.getBoolean("fts", false); boolean fts = prefs.getBoolean("fts", false);
boolean pro = ActivityBilling.isPro(context); boolean pro = ActivityBilling.isPro(context);
if (fts && pro && seen == null && flagged == null && snoozed == null && encrypted == null) { if (fts && pro && seen == null && flagged == null && snoozed == null && encrypted == null && attachments == null) {
if (state.ids == null) { if (state.ids == null) {
SQLiteDatabase sdb = FtsDbHelper.getInstance(context); SQLiteDatabase sdb = FtsDbHelper.getInstance(context);
state.ids = FtsDbHelper.match(sdb, account, folder, query); state.ids = FtsDbHelper.match(sdb, account, folder, query);
@ -220,7 +223,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
state.matches = db.message().matchMessages( state.matches = db.message().matchMessages(
account, folder, account, folder,
"%" + find + "%", "%" + find + "%",
seen, flagged, snoozed, encrypted, seen, flagged, snoozed, encrypted, attachments,
SEARCH_LIMIT, state.offset); SEARCH_LIMIT, state.offset);
Log.i("Boundary device folder=" + folder + Log.i("Boundary device folder=" + folder +
" query=" + query + " query=" + query +
@ -228,6 +231,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
" flagged=" + flagged + " flagged=" + flagged +
" snoozed=" + snoozed + " snoozed=" + snoozed +
" encrypted=" + encrypted + " encrypted=" + encrypted +
" attachments=" + attachments +
" offset=" + state.offset + " offset=" + state.offset +
" size=" + state.matches.size()); " size=" + state.matches.size());
state.offset += Math.min(state.matches.size(), SEARCH_LIMIT); state.offset += Math.min(state.matches.size(), SEARCH_LIMIT);
@ -242,7 +246,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
TupleMatch match = state.matches.get(i); TupleMatch match = state.matches.get(i);
if (find == null || seen != null || flagged != null || snoozed != null || encrypted != null) if (find == null || seen != null || flagged != null || snoozed != null || encrypted != null || attachments!=null)
match.matched = true; match.matched = true;
else { else {
if (match.matched == null || !match.matched) if (match.matched == null || !match.matched)

@ -274,11 +274,12 @@ public interface DaoMessage {
" AND (:flagged IS NULL OR ui_flagged = :flagged)" + " AND (:flagged IS NULL OR ui_flagged = :flagged)" +
" AND (:hidden IS NULL OR (CASE WHEN ui_snoozed IS NULL THEN 0 ELSE 1 END) = :hidden)" + " AND (:hidden IS NULL OR (CASE WHEN ui_snoozed IS NULL THEN 0 ELSE 1 END) = :hidden)" +
" AND (:encrypted IS NULL OR ui_encrypt > 0)" + " AND (:encrypted IS NULL OR ui_encrypt > 0)" +
" AND (:attachments IS NULL OR attachments > 0)" +
" ORDER BY received DESC" + " ORDER BY received DESC" +
" LIMIT :limit OFFSET :offset") " LIMIT :limit OFFSET :offset")
List<TupleMatch> matchMessages( List<TupleMatch> matchMessages(
Long account, Long folder, String find, Long account, Long folder, String find,
Boolean seen, Boolean flagged, Boolean hidden, Boolean encrypted, Boolean seen, Boolean flagged, Boolean hidden, Boolean encrypted, Boolean attachments,
int limit, int offset); int limit, int offset);
@Query("SELECT id" + @Query("SELECT id" +

@ -1115,7 +1115,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
if (query != null && query.startsWith(getString(R.string.title_search_special_prefix) + ":")) { if (query != null && query.startsWith(getString(R.string.title_search_special_prefix) + ":")) {
String special = query.split(":")[1]; String special = query.split(":")[1];
if (getString(R.string.title_search_special_snoozed).equals(special) || if (getString(R.string.title_search_special_snoozed).equals(special) ||
getString(R.string.title_search_special_encrypted).equals(special)) getString(R.string.title_search_special_encrypted).equals(special) ||
getString(R.string.title_search_special_attachments).equals(special))
fabSearch.hide(); fabSearch.hide();
else else
fabSearch.show(); fabSearch.show();

@ -64,6 +64,7 @@ public class SearchViewEx extends SearchView {
cursor.addRow(new Object[]{-3, prefix + ":" + getContext().getString(R.string.title_search_special_flagged)}); cursor.addRow(new Object[]{-3, prefix + ":" + getContext().getString(R.string.title_search_special_flagged)});
cursor.addRow(new Object[]{-4, prefix + ":" + getContext().getString(R.string.title_search_special_snoozed)}); cursor.addRow(new Object[]{-4, prefix + ":" + getContext().getString(R.string.title_search_special_snoozed)});
cursor.addRow(new Object[]{-5, prefix + ":" + getContext().getString(R.string.title_search_special_encrypted)}); cursor.addRow(new Object[]{-5, prefix + ":" + getContext().getString(R.string.title_search_special_encrypted)});
cursor.addRow(new Object[]{-6, prefix + ":" + getContext().getString(R.string.title_search_special_attachments)});
SimpleCursorAdapter adapter = new SimpleCursorAdapter( SimpleCursorAdapter adapter = new SimpleCursorAdapter(
getContext(), getContext(),
R.layout.search_suggestion, R.layout.search_suggestion,

@ -1127,6 +1127,7 @@
<string name="title_search_special_flagged">starred</string> <string name="title_search_special_flagged">starred</string>
<string name="title_search_special_snoozed">hidden</string> <string name="title_search_special_snoozed">hidden</string>
<string name="title_search_special_encrypted">encrypted</string> <string name="title_search_special_encrypted">encrypted</string>
<string name="title_search_special_attachments">attachments</string>
<string name="title_widget_title_count">New message count</string> <string name="title_widget_title_count">New message count</string>
<string name="title_widget_title_list">Message list</string> <string name="title_widget_title_list">Message list</string>

Loading…
Cancel
Save