This commit is contained in:
LisoUseInAIKyrios 2025-05-10 12:21:00 +04:00
parent 9ca2e88101
commit 44bcb31844

View file

@ -20,8 +20,10 @@ import android.widget.Toolbar;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import java.util.ArrayDeque;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Deque;
import java.util.List; import java.util.List;
import app.revanced.extension.shared.Logger; import app.revanced.extension.shared.Logger;
@ -45,7 +47,7 @@ public class SearchViewController {
private final Activity activity; private final Activity activity;
private boolean isSearchActive; private boolean isSearchActive;
private final CharSequence originalTitle; private final CharSequence originalTitle;
private final List<String> searchHistory; private final Deque<String> searchHistory;
private final AutoCompleteTextView autoCompleteTextView; private final AutoCompleteTextView autoCompleteTextView;
private final boolean showSettingsSearchHistory; private final boolean showSettingsSearchHistory;
@ -86,7 +88,7 @@ public class SearchViewController {
this.toolbar = toolbar; this.toolbar = toolbar;
this.originalTitle = toolbar.getTitle(); this.originalTitle = toolbar.getTitle();
this.showSettingsSearchHistory = Settings.SETTINGS_SEARCH_HISTORY.get(); this.showSettingsSearchHistory = Settings.SETTINGS_SEARCH_HISTORY.get();
this.searchHistory = new ArrayList<>(); this.searchHistory = new ArrayDeque<>(MAX_HISTORY_SIZE);
StringSetting searchEntries = Settings.SETTINGS_SEARCH_ENTRIES; StringSetting searchEntries = Settings.SETTINGS_SEARCH_ENTRIES;
if (!showSettingsSearchHistory) { if (!showSettingsSearchHistory) {
// Clear old saved history if the user turns off the feature. // Clear old saved history if the user turns off the feature.
@ -208,7 +210,7 @@ public class SearchViewController {
*/ */
private void setupSearchHistory() { private void setupSearchHistory() {
if (autoCompleteTextView != null) { if (autoCompleteTextView != null) {
SearchHistoryAdapter adapter = new SearchHistoryAdapter(activity, searchHistory); SearchHistoryAdapter adapter = new SearchHistoryAdapter(activity, new ArrayList<>(searchHistory));
autoCompleteTextView.setAdapter(adapter); autoCompleteTextView.setAdapter(adapter);
autoCompleteTextView.setThreshold(1); // Initial threshold for empty input. autoCompleteTextView.setThreshold(1); // Initial threshold for empty input.
autoCompleteTextView.setLongClickable(true); autoCompleteTextView.setLongClickable(true);
@ -231,13 +233,12 @@ public class SearchViewController {
return; return;
} }
searchHistory.remove(query); // Remove if already exists to update position. searchHistory.remove(query); // Remove if already exists to update position.
searchHistory.add(0, query); // Add to the most recent. searchHistory.addFirst(query); // Add to the most recent.
// Remove extra old entries. // Remove extra old entries.
while (searchHistory.size() > MAX_HISTORY_SIZE) { while (searchHistory.size() > MAX_HISTORY_SIZE) {
final int lastIndex = searchHistory.size() - 1; String last = searchHistory.removeLast();
Logger.printDebug(() -> "Removing search history query: " + searchHistory.get(lastIndex)); Logger.printDebug(() -> "Removing search history query: " + last);
searchHistory.remove(lastIndex);
} }
saveSearchHistory(); saveSearchHistory();