max history size

This commit is contained in:
Bnyro 2022-08-09 14:49:34 +02:00
parent e78e7daf0a
commit a859ae101d
5 changed files with 42 additions and 0 deletions

View File

@ -142,6 +142,12 @@ object PreferenceHelper {
watchHistory += watchHistoryItem
// remove oldest item when the watch history is longer than the pref
val maxWatchHistorySize = getString(PreferenceKeys.WATCH_HISTORY_SIZE, "unlimited")
if (maxWatchHistorySize != "unlimited" && watchHistory.size > maxWatchHistorySize.toInt()) {
watchHistory.removeAt(0)
}
val json = mapper.writeValueAsString(watchHistory)
editor.putString("watch_history", json).apply()
}

View File

@ -83,6 +83,11 @@ object PreferenceKeys {
const val CLEAR_WATCH_POSITIONS = "clear_watch_positions"
const val SHARE_WITH_TIME_CODE = "share_with_time_code"
/**
* History
*/
const val WATCH_HISTORY_SIZE = "watch_history_size"
/**
* Error logs
*/

View File

@ -649,6 +649,7 @@
<item>1.25x</item>
<item>1.5x</item>
<item>2x</item>
<item>3x</item>
<item>4x</item>
</string-array>
<string-array name="playbackSpeedValues">
@ -659,6 +660,7 @@
<item>1.25</item>
<item>1.5</item>
<item>2</item>
<item>3</item>
<item>4</item>
</string-array>
@ -808,4 +810,22 @@
<item>metered</item>
</string-array>
<string-array name="historySize">
<item>20</item>
<item>50</item>
<item>100</item>
<item>150</item>
<item>200</item>
<item>@string/unlimited</item>
</string-array>
<string-array name="historySizeValues">
<item>20</item>
<item>50</item>
<item>100</item>
<item>150</item>
<item>200</item>
<item>unlimited</item>
</string-array>
</resources>

View File

@ -294,4 +294,6 @@
<string name="export_subscriptions">Export Subscriptions</string>
<string name="skip_buttons">Skip buttons</string>
<string name="skip_buttons_summary">Show buttons to skip to the next or previous video.</string>
<string name="history_size">Maximum history size</string>
<string name="unlimited">Unlimited</string>
</resources>

View File

@ -27,6 +27,15 @@
app:key="watch_history_toggle"
app:title="@string/watch_history" />
<ListPreference
android:defaultValue="unlimited"
android:entries="@array/historySize"
android:entryValues="@array/historySizeValues"
android:icon="@drawable/ic_list"
app:key="watch_history_size"
app:title="@string/history_size"
app:useSimpleSummaryProvider="true" />
<Preference
android:icon="@drawable/ic_trash"
app:key="clear_watch_history"