From 7641024bc9ab4a15ede54913e00fb6d80ba381a9 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 18 Sep 2023 09:13:33 +0200 Subject: [PATCH] fix: default SponsorBlock categories are not being respected --- .../github/libretube/helpers/PlayerHelper.kt | 22 +++++++++++++++---- .../main/res/xml/sponsorblock_settings.xml | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt index 4b33a6cbb..6924bc7bf 100644 --- a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt @@ -47,6 +47,15 @@ object PlayerHelper { const val SPONSOR_HIGHLIGHT_CATEGORY = "poi_highlight" const val ROLE_FLAG_AUTO_GEN_SUBTITLE = C.ROLE_FLAG_SUPPLEMENTARY + /** + * A list of all categories that are not disabled by default + * Also update `sponsorblock_settings.xml` when modifying this! + */ + private val sbDefaultValues = mapOf( + "sponsor" to SbSkipOptions.AUTOMATIC, + "selfpromo" to SbSkipOptions.AUTOMATIC + ) + /** * Create a base64 encoded DASH stream manifest */ @@ -221,7 +230,7 @@ object PlayerHelper { .roundToInt() .toLong() * 1000 - val playbackSpeed: Float + private val playbackSpeed: Float get() = PreferenceHelper.getString( PreferenceKeys.PLAYBACK_SPEED, "1" @@ -456,11 +465,16 @@ object PlayerHelper { for (category in LibreTubeApp.instance.resources.getStringArray( R.array.sponsorBlockSegments )) { - val state = PreferenceHelper.getString(category + "_category", "off").uppercase() - if (SbSkipOptions.valueOf(state) != SbSkipOptions.OFF) { - categories[category] = SbSkipOptions.valueOf(state) + val defaultCategoryValue = sbDefaultValues.getOrDefault(category, SbSkipOptions.OFF) + val skipOption = PreferenceHelper + .getString("${category}_category", defaultCategoryValue.name) + .let { SbSkipOptions.valueOf(it.uppercase()) } + + if (skipOption != SbSkipOptions.OFF) { + categories[category] = skipOption } } + // Add the highlights category to display in the chapters if (sponsorBlockHighlights) categories[SPONSOR_HIGHLIGHT_CATEGORY] = SbSkipOptions.OFF return categories diff --git a/app/src/main/res/xml/sponsorblock_settings.xml b/app/src/main/res/xml/sponsorblock_settings.xml index c38745eda..393a05ce0 100644 --- a/app/src/main/res/xml/sponsorblock_settings.xml +++ b/app/src/main/res/xml/sponsorblock_settings.xml @@ -50,6 +50,8 @@ + +