Merge pull request #3640 from Bnyro/master

Unlimited search history preference
This commit is contained in:
Bnyro 2023-04-27 09:16:15 +02:00 committed by GitHub
commit 3cd1829194
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 2 deletions

View File

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

View File

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

View File

@ -416,6 +416,7 @@
<string name="background_channel_description">Shows a notification with buttons to control the audio player.</string>
<string name="push_channel_name">Notification Worker</string>
<string name="push_channel_description">Shows a notification when new streams are available.</string>
<string name="unlimited_search_history">Unlimited search history</string>
<!-- Relative time formatting strings (remove when setting the minSdk to 24) -->
<plurals name="years_ago">
<item quantity="one">%d year ago</item>

View File

@ -11,6 +11,13 @@
app:key="search_history_toggle"
app:title="@string/search_history" />
<SwitchPreferenceCompat
android:dependency="search_history_toggle"
android:defaultValue="false"
android:icon="@drawable/ic_search"
app:key="unlimited_search_history"
app:title="@string/unlimited_search_history" />
<Preference
android:icon="@drawable/ic_trash"
app:key="clear_search_history"