Remember last three searches

This commit is contained in:
M66B 2021-04-17 11:04:04 +02:00
parent cd047a7a07
commit 770dee6184
4 changed files with 128 additions and 11 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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",

View File

@ -123,17 +123,78 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/ibFlow" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvSearch1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="middle"
android:padding="6dp"
android:singleLine="true"
android:text="search1"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorLink"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@+id/tvSearch2"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etQuery" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvSearch2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="middle"
android:padding="6dp"
android:singleLine="true"
android:text="search2"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorLink"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@+id/tvSearch3"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toEndOf="@id/tvSearch1"
app:layout_constraintTop_toBottomOf="@id/etQuery" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvSearch3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="middle"
android:padding="6dp"
android:singleLine="true"
android:text="search3"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorLink"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@+id/ibResetSearches"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toEndOf="@id/tvSearch2"
app:layout_constraintTop_toBottomOf="@id/etQuery" />
<ImageButton
android:id="@+id/ibResetSearches"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:padding="3dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/etQuery"
app:srcCompat="@drawable/twotone_cancel_24" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvHint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginTop="6dp"
android:text="@string/title_search_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etQuery" />
app:layout_constraintTop_toBottomOf="@id/tvSearch1" />
<ImageButton
android:id="@+id/ibMore"
@ -436,4 +497,4 @@
tvAnd,cbUnseen,cbFlagged,cbHidden,cbEncrypted,cbAttachments,
btnAfter,btnBefore,tvBefore,tvAfter" />
</androidx.constraintlayout.widget.ConstraintLayout>
</eu.faircode.email.ScrollViewEx>
</eu.faircode.email.ScrollViewEx>