mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-06 00:53:26 +02:00
Remember last three searches
This commit is contained in:
@@ -465,6 +465,11 @@ public class ApplicationEx extends Application
|
||||
Log.e(ex);
|
||||
}
|
||||
}
|
||||
} else if (version < 1556) {
|
||||
if (prefs.contains("last_search")) {
|
||||
editor.putString("last_search1", prefs.getString("last_search", null));
|
||||
editor.remove("last_search");
|
||||
}
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !BuildConfig.DEBUG)
|
||||
|
||||
@@ -53,6 +53,7 @@ import androidx.cursoradapter.widget.SimpleCursorAdapter;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
@@ -74,11 +75,15 @@ public class FragmentDialogSearch extends FragmentDialogBase {
|
||||
boolean last_search_keywords = prefs.getBoolean("last_search_keywords", false);
|
||||
boolean last_search_message = prefs.getBoolean("last_search_message", true);
|
||||
boolean last_search_notes = prefs.getBoolean("last_search_notes", true);
|
||||
String last_search = prefs.getString("last_search", null);
|
||||
|
||||
View dview = LayoutInflater.from(context).inflate(R.layout.dialog_search, null);
|
||||
|
||||
final AutoCompleteTextView etQuery = dview.findViewById(R.id.etQuery);
|
||||
final TextView tvSearch1 = dview.findViewById(R.id.tvSearch1);
|
||||
final TextView tvSearch2 = dview.findViewById(R.id.tvSearch2);
|
||||
final TextView tvSearch3 = dview.findViewById(R.id.tvSearch3);
|
||||
final ImageButton ibResetSearches = dview.findViewById(R.id.ibResetSearches);
|
||||
|
||||
final ImageButton ibInfo = dview.findViewById(R.id.ibInfo);
|
||||
final ImageButton ibFlagged = dview.findViewById(R.id.ibFlagged);
|
||||
final ImageButton ibUnseen = dview.findViewById(R.id.ibUnseen);
|
||||
@@ -150,6 +155,41 @@ public class FragmentDialogSearch extends FragmentDialogBase {
|
||||
|
||||
etQuery.setAdapter(adapter);
|
||||
|
||||
View.OnClickListener onSearch = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
etQuery.setText(((TextView) v).getText());
|
||||
((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE).performClick();
|
||||
}
|
||||
};
|
||||
|
||||
boolean hasSearches = false;
|
||||
TextView[] views = new TextView[]{tvSearch1, tvSearch2, tvSearch3};
|
||||
for (int i = 1; i <= 3; i++) {
|
||||
boolean has = prefs.contains("last_search" + i);
|
||||
if (has) {
|
||||
hasSearches = true;
|
||||
String search = prefs.getString("last_search" + i, null);
|
||||
views[i - 1].setText(search);
|
||||
views[i - 1].setOnClickListener(onSearch);
|
||||
}
|
||||
views[i - 1].setVisibility(has ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
ibResetSearches.setVisibility(hasSearches ? View.VISIBLE : View.GONE);
|
||||
|
||||
ibResetSearches.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
for (int i = 1; i <= 3; i++) {
|
||||
editor.remove("last_search" + i);
|
||||
views[i - 1].setVisibility(View.GONE);
|
||||
}
|
||||
editor.apply();
|
||||
ibResetSearches.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
View.OnClickListener onMore = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@@ -274,11 +314,6 @@ public class FragmentDialogSearch extends FragmentDialogBase {
|
||||
|
||||
grpMore.setVisibility(View.GONE);
|
||||
|
||||
if (!TextUtils.isEmpty(last_search)) {
|
||||
etQuery.setText(last_search);
|
||||
etQuery.setSelection(0, last_search.length());
|
||||
}
|
||||
|
||||
etQuery.requestFocus();
|
||||
if (imm != null)
|
||||
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
|
||||
@@ -291,7 +326,23 @@ public class FragmentDialogSearch extends FragmentDialogBase {
|
||||
BoundaryCallbackMessages.SearchCriteria criteria = new BoundaryCallbackMessages.SearchCriteria();
|
||||
|
||||
criteria.query = etQuery.getText().toString();
|
||||
prefs.edit().putString("last_search", criteria.query).apply();
|
||||
|
||||
if (!TextUtils.isEmpty(criteria.query)) {
|
||||
List<String> searches = new ArrayList<>();
|
||||
for (int i = 1; i <= 3; i++)
|
||||
if (prefs.contains("last_search" + i)) {
|
||||
String search = prefs.getString("last_search" + i, null);
|
||||
searches.add(search);
|
||||
}
|
||||
|
||||
if (!searches.contains(criteria.query))
|
||||
searches.add(0, criteria.query);
|
||||
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
for (int i = 1; i <= Math.min(3, searches.size()); i++)
|
||||
editor.putString("last_search" + i, searches.get(i - 1));
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(criteria.query))
|
||||
criteria.query = null;
|
||||
|
||||
@@ -152,7 +152,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
"print_html_confirmed", "print_html_header", "print_html_images",
|
||||
"reformatted_hint",
|
||||
"selected_folders", "move_1_confirmed", "move_n_confirmed",
|
||||
"last_search_senders", "last_search_recipients", "last_search_subject", "last_search_keywords", "last_search_message", "last_search",
|
||||
"last_search_senders", "last_search_recipients", "last_search_subject", "last_search_keywords", "last_search_message",
|
||||
"identities_asked", "identities_primary_hint",
|
||||
"raw_asked", "all_read_asked",
|
||||
"cc_bcc", "inline_image_hint", "compose_reference", "send_dialog",
|
||||
|
||||
Reference in New Issue
Block a user