1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-01-18 13:21:02 +00:00

Search locally for keywords too

This commit is contained in:
M66B 2019-07-24 12:00:47 +02:00
parent 13896fc72a
commit 1ac7f26dae

View file

@ -22,6 +22,7 @@ package eu.faircode.email;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Handler; import android.os.Handler;
import android.text.TextUtils;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.paging.PagedList; import androidx.paging.PagedList;
@ -177,6 +178,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
try { try {
db.beginTransaction(); db.beginTransaction();
String find = (TextUtils.isEmpty(query) ? null : query.toLowerCase());
for (int i = index; i < messages.size() && found < pageSize && !destroyed; i++) { for (int i = index; i < messages.size() && found < pageSize && !destroyed; i++) {
index = i + 1; index = i + 1;
@ -185,31 +187,35 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
continue; continue;
boolean match = false; boolean match = false;
if (query == null) if (find == null)
match = true; match = true;
else { else {
String find = query.toLowerCase(); if (message.from != null && message.from.length > 0)
String body = null;
if (message.content)
try {
body = Helper.readText(message.getFile(context));
} catch (IOException ex) {
Log.e(ex);
}
if (message.from != null)
for (int j = 0; j < message.from.length && !match; j++) for (int j = 0; j < message.from.length && !match; j++)
match = message.from[j].toString().toLowerCase().contains(find); match = message.from[j].toString().toLowerCase().contains(find);
if (message.to != null) if (!match && message.to != null && message.to.length > 0)
for (int j = 0; j < message.to.length && !match; j++) for (int j = 0; j < message.to.length && !match; j++)
match = message.to[j].toString().toLowerCase().contains(find); match = message.to[j].toString().toLowerCase().contains(find);
if (message.subject != null && !match) if (!match && message.subject != null)
match = message.subject.toLowerCase().contains(find); match = message.subject.toLowerCase().contains(find);
if (!match && message.content) if (!match && message.keywords != null && message.keywords.length > 0)
match = body.toLowerCase().contains(find); 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) { if (match) {