mirror of https://github.com/M66B/FairEmail.git
Added special searches
This commit is contained in:
parent
0be109a816
commit
a0c2e41adb
|
@ -190,30 +190,40 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|||
if (find == null)
|
||||
match = true;
|
||||
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 (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<TupleMe
|
|||
Log.i("Boundary server query=" + query);
|
||||
if (query == null)
|
||||
imessages = ifolder.getMessages();
|
||||
else {
|
||||
else if (query.startsWith(context.getString(R.string.title_search_special_prefix) + ":")) {
|
||||
String special = query.split(":")[1];
|
||||
if (context.getString(R.string.title_search_special_unseen).equals(special))
|
||||
imessages = ifolder.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
|
||||
else if (context.getString(R.string.title_search_special_flagged).equals(special))
|
||||
imessages = ifolder.search(new FlagTerm(new Flags(Flags.Flag.FLAGGED), true));
|
||||
else
|
||||
imessages = new Message[0];
|
||||
} else {
|
||||
Object result = ifolder.doCommand(new IMAPFolder.ProtocolCommand() {
|
||||
@Override
|
||||
public Object doCommand(IMAPProtocol protocol) {
|
||||
|
|
|
@ -31,6 +31,7 @@ import android.content.IntentFilter;
|
|||
import android.content.IntentSender;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.database.MatrixCursor;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
|
@ -69,6 +70,7 @@ import android.webkit.WebSettings;
|
|||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageButton;
|
||||
|
@ -2282,42 +2284,62 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
searchView.setQuery(searching, false);
|
||||
}
|
||||
|
||||
AutoCompleteTextView autoCompleteTextView = searchView.findViewById(androidx.appcompat.R.id.search_src_text);
|
||||
autoCompleteTextView.setThreshold(0);
|
||||
|
||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
searching = newText;
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putString("query", newText);
|
||||
if (TextUtils.isEmpty(newText)) {
|
||||
MatrixCursor cursor = new MatrixCursor(new String[]{"_id", "suggestion"});
|
||||
String prefix = getString(R.string.title_search_special_prefix);
|
||||
cursor.addRow(new Object[]{-1, prefix + ":" + getString(R.string.title_search_special_unseen)});
|
||||
cursor.addRow(new Object[]{-2, prefix + ":" + getString(R.string.title_search_special_flagged)});
|
||||
cursor.addRow(new Object[]{-3, prefix + ":" + getString(R.string.title_search_special_snoozed)});
|
||||
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();
|
||||
} else {
|
||||
Bundle args = new Bundle();
|
||||
args.putString("query", newText);
|
||||
|
||||
new SimpleTask<Cursor>() {
|
||||
@Override
|
||||
protected Cursor onExecute(Context context, Bundle args) {
|
||||
String query = args.getString("query");
|
||||
new SimpleTask<Cursor>() {
|
||||
@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;
|
||||
}
|
||||
|
|
|
@ -783,6 +783,11 @@
|
|||
<string name="title_crash_info_remark">Please describe what you were doing when the app crashed:</string>
|
||||
<string name="title_issue_subject" translatable="false">FairEmail %1$s issue</string>
|
||||
|
||||
<string name="title_search_special_prefix">special</string>
|
||||
<string name="title_search_special_unseen">unread</string>
|
||||
<string name="title_search_special_flagged">starred</string>
|
||||
<string name="title_search_special_snoozed">snoozed</string>
|
||||
|
||||
<string-array name="pollIntervalNames">
|
||||
<item>Always</item>
|
||||
<item>Every 15 minutes</item>
|
||||
|
|
Loading…
Reference in New Issue