Added special searches

pull/159/head
M66B 5 years ago
parent 0be109a816
commit a0c2e41adb

@ -190,6 +190,15 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
if (find == null) if (find == null)
match = true; match = true;
else { else {
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) if (message.from != null && message.from.length > 0)
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);
@ -217,6 +226,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
} }
} }
} }
}
if (match) { if (match) {
found++; found++;
@ -281,7 +291,15 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
Log.i("Boundary server query=" + query); Log.i("Boundary server query=" + query);
if (query == null) if (query == null)
imessages = ifolder.getMessages(); 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() { Object result = ifolder.doCommand(new IMAPFolder.ProtocolCommand() {
@Override @Override
public Object doCommand(IMAPProtocol protocol) { public Object doCommand(IMAPProtocol protocol) {

@ -31,6 +31,7 @@ import android.content.IntentFilter;
import android.content.IntentSender; import android.content.IntentSender;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.Cursor; import android.database.Cursor;
import android.database.MatrixCursor;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
@ -69,6 +70,7 @@ import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.ImageButton; import android.widget.ImageButton;
@ -2282,11 +2284,30 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
searchView.setQuery(searching, false); searchView.setQuery(searching, false);
} }
AutoCompleteTextView autoCompleteTextView = searchView.findViewById(androidx.appcompat.R.id.search_src_text);
autoCompleteTextView.setThreshold(0);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override @Override
public boolean onQueryTextChange(String newText) { public boolean onQueryTextChange(String newText) {
searching = newText; searching = 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(); Bundle args = new Bundle();
args.putString("query", newText); args.putString("query", newText);
@ -2318,6 +2339,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
Helper.unexpectedError(getFragmentManager(), ex); Helper.unexpectedError(getFragmentManager(), ex);
} }
}.execute(FragmentMessages.this, args, "messages:suggestions"); }.execute(FragmentMessages.this, args, "messages:suggestions");
}
return true; 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_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_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"> <string-array name="pollIntervalNames">
<item>Always</item> <item>Always</item>
<item>Every 15 minutes</item> <item>Every 15 minutes</item>

Loading…
Cancel
Save