diff --git a/app/src/main/java/com/github/libretube/preferences/PreferenceHelper.kt b/app/src/main/java/com/github/libretube/preferences/PreferenceHelper.kt index 4403eba5a..3b7c69c27 100644 --- a/app/src/main/java/com/github/libretube/preferences/PreferenceHelper.kt +++ b/app/src/main/java/com/github/libretube/preferences/PreferenceHelper.kt @@ -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() } diff --git a/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt b/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt index 15ec07613..74f110a6d 100644 --- a/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt +++ b/app/src/main/java/com/github/libretube/preferences/PreferenceKeys.kt @@ -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 */ diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index e399c1838..b5b54c098 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -649,6 +649,7 @@ 1.25x 1.5x 2x + 3x 4x @@ -659,6 +660,7 @@ 1.25 1.5 2 + 3 4 @@ -808,4 +810,22 @@ metered + + 20 + 50 + 100 + 150 + 200 + @string/unlimited + + + + 20 + 50 + 100 + 150 + 200 + unlimited + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9ffccc20d..25d950e58 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -294,4 +294,6 @@ Export Subscriptions Skip buttons Show buttons to skip to the next or previous video. + Maximum history size + Unlimited diff --git a/app/src/main/res/xml/history_settings.xml b/app/src/main/res/xml/history_settings.xml index ec13f6005..642b227d3 100644 --- a/app/src/main/res/xml/history_settings.xml +++ b/app/src/main/res/xml/history_settings.xml @@ -27,6 +27,15 @@ app:key="watch_history_toggle" app:title="@string/watch_history" /> + +