diff --git a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt
index 42784bc21..46beb38ea 100644
--- a/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt
+++ b/app/src/main/java/com/github/libretube/constants/PreferenceKeys.kt
@@ -97,6 +97,7 @@ object PreferenceKeys {
const val AUTO_FULLSCREEN_SHORTS = "auto_fullscreen_shorts"
const val PLAY_AUTOMATICALLY = "play_automatically"
const val FULLSCREEN_GESTURES = "fullscreen_gestures"
+ const val UNLIMITED_SEARCH_HISTORY = "unlimited_search_history"
/**
* Background mode
diff --git a/app/src/main/java/com/github/libretube/db/DatabaseHelper.kt b/app/src/main/java/com/github/libretube/db/DatabaseHelper.kt
index e91b3988c..a613b4f86 100644
--- a/app/src/main/java/com/github/libretube/db/DatabaseHelper.kt
+++ b/app/src/main/java/com/github/libretube/db/DatabaseHelper.kt
@@ -40,10 +40,14 @@ object DatabaseHelper {
suspend fun addToSearchHistory(searchHistoryItem: SearchHistoryItem) {
Database.searchHistoryDao().insert(searchHistoryItem)
+ if (PreferenceHelper.getBoolean(PreferenceKeys.UNLIMITED_SEARCH_HISTORY, false)) return
+
// delete the first watch history entry if the limit is reached
- val searchHistory = Database.searchHistoryDao().getAll()
- if (searchHistory.size > MAX_SEARCH_HISTORY_SIZE) {
+ val searchHistory = Database.searchHistoryDao().getAll().toMutableList()
+
+ while (searchHistory.size > MAX_SEARCH_HISTORY_SIZE) {
Database.searchHistoryDao().delete(searchHistory.first())
+ searchHistory.removeFirst()
}
}
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 52326713b..f622d1d8f 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -416,6 +416,7 @@
Shows a notification with buttons to control the audio player.
Notification Worker
Shows a notification when new streams are available.
+ Unlimited search history
- %d year ago
diff --git a/app/src/main/res/xml/history_settings.xml b/app/src/main/res/xml/history_settings.xml
index dcdbd05b6..8f41f7d1e 100644
--- a/app/src/main/res/xml/history_settings.xml
+++ b/app/src/main/res/xml/history_settings.xml
@@ -11,6 +11,13 @@
app:key="search_history_toggle"
app:title="@string/search_history" />
+
+