Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unlimited search history preference #3640

Merged
merged 1 commit into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/com/github/libretube/db/DatabaseHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/xml/history_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down