Added search for messages with attachment

This commit is contained in:
M66B 2020-02-24 17:43:52 +01:00
parent e7209b9cd3
commit 2fc758ef0b
5 changed files with 13 additions and 5 deletions

View File

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

View File

@ -274,11 +274,12 @@ public interface DaoMessage {
" 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 (:encrypted IS NULL OR ui_encrypt > 0)" +
" AND (:attachments IS NULL OR attachments > 0)" +
" ORDER BY received DESC" +
" LIMIT :limit OFFSET :offset")
List<TupleMatch> matchMessages(
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);
@Query("SELECT id" +

View File

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

View File

@ -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[]{-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[]{-6, prefix + ":" + getContext().getString(R.string.title_search_special_attachments)});
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
getContext(),
R.layout.search_suggestion,

View File

@ -1127,6 +1127,7 @@
<string name="title_search_special_flagged">starred</string>
<string name="title_search_special_snoozed">hidden</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_list">Message list</string>