|
|
@ -1,6 +1,7 @@
|
|
|
|
package eu.faircode.email;
|
|
|
|
package eu.faircode.email;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.database.MatrixCursor;
|
|
|
|
import android.database.MatrixCursor;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Bundle;
|
|
|
@ -13,6 +14,7 @@ import android.widget.Toast;
|
|
|
|
import androidx.appcompat.widget.SearchView;
|
|
|
|
import androidx.appcompat.widget.SearchView;
|
|
|
|
import androidx.cursoradapter.widget.SimpleCursorAdapter;
|
|
|
|
import androidx.cursoradapter.widget.SimpleCursorAdapter;
|
|
|
|
import androidx.lifecycle.LifecycleOwner;
|
|
|
|
import androidx.lifecycle.LifecycleOwner;
|
|
|
|
|
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
|
|
|
|
|
|
|
|
public class SearchViewEx extends SearchView {
|
|
|
|
public class SearchViewEx extends SearchView {
|
|
|
|
private String _searching = null;
|
|
|
|
private String _searching = null;
|
|
|
@ -31,7 +33,6 @@ public class SearchViewEx extends SearchView {
|
|
|
|
|
|
|
|
|
|
|
|
void setup(LifecycleOwner owner, MenuItem menuSearch, String searching, ISearch intf) {
|
|
|
|
void setup(LifecycleOwner owner, MenuItem menuSearch, String searching, ISearch intf) {
|
|
|
|
_searching = searching;
|
|
|
|
_searching = searching;
|
|
|
|
Log.i("SearchView searching=" + _searching);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setQueryHint(getContext().getString(R.string.title_search));
|
|
|
|
setQueryHint(getContext().getString(R.string.title_search));
|
|
|
|
|
|
|
|
|
|
|
@ -43,6 +44,8 @@ public class SearchViewEx extends SearchView {
|
|
|
|
AutoCompleteTextView autoCompleteTextView = findViewById(androidx.appcompat.R.id.search_src_text);
|
|
|
|
AutoCompleteTextView autoCompleteTextView = findViewById(androidx.appcompat.R.id.search_src_text);
|
|
|
|
autoCompleteTextView.setThreshold(0);
|
|
|
|
autoCompleteTextView.setThreshold(0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
|
|
|
|
|
|
|
|
|
|
|
setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
|
|
|
setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean onQueryTextChange(String newText) {
|
|
|
|
public boolean onQueryTextChange(String newText) {
|
|
|
@ -51,10 +54,15 @@ public class SearchViewEx extends SearchView {
|
|
|
|
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(newText)) {
|
|
|
|
if (TextUtils.isEmpty(newText)) {
|
|
|
|
MatrixCursor cursor = new MatrixCursor(new String[]{"_id", "suggestion"});
|
|
|
|
MatrixCursor cursor = new MatrixCursor(new String[]{"_id", "suggestion"});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String last_search = prefs.getString("last_search", null);
|
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(last_search))
|
|
|
|
|
|
|
|
cursor.addRow(new Object[]{-1, last_search});
|
|
|
|
|
|
|
|
|
|
|
|
String prefix = getContext().getString(R.string.title_search_special_prefix);
|
|
|
|
String prefix = getContext().getString(R.string.title_search_special_prefix);
|
|
|
|
cursor.addRow(new Object[]{-1, prefix + ":" + getContext().getString(R.string.title_search_special_unseen)});
|
|
|
|
cursor.addRow(new Object[]{-2, prefix + ":" + getContext().getString(R.string.title_search_special_unseen)});
|
|
|
|
cursor.addRow(new Object[]{-2, 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[]{-3, prefix + ":" + getContext().getString(R.string.title_search_special_snoozed)});
|
|
|
|
cursor.addRow(new Object[]{-4, prefix + ":" + getContext().getString(R.string.title_search_special_snoozed)});
|
|
|
|
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
|
|
|
|
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
|
|
|
|
getContext(),
|
|
|
|
getContext(),
|
|
|
|
R.layout.search_suggestion,
|
|
|
|
R.layout.search_suggestion,
|
|
|
@ -104,9 +112,10 @@ public class SearchViewEx extends SearchView {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean onQueryTextSubmit(String query) {
|
|
|
|
public boolean onQueryTextSubmit(String query) {
|
|
|
|
_searching = null;
|
|
|
|
_searching = null;
|
|
|
|
intf.onSave(_searching);
|
|
|
|
intf.onSave(query);
|
|
|
|
menuSearch.collapseActionView();
|
|
|
|
menuSearch.collapseActionView();
|
|
|
|
intf.onSearch(query);
|
|
|
|
intf.onSearch(query);
|
|
|
|
|
|
|
|
prefs.edit().putString("last_search", query).apply();
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|