From 06422d74f73a95d8d7f48e012c86ed494b3497fd Mon Sep 17 00:00:00 2001 From: Muonis Date: Sun, 27 Feb 2022 20:42:08 +0100 Subject: [PATCH] Implement Preview/Recap Category Implements part of #99 and #111 Uses the default SponsorBlock color for the category --- .../schabi/newpipe/player/LocalPlayer.java | 4 ++++ .../org/schabi/newpipe/player/Player.java | 4 ++++ ...ponsorBlockCategoriesSettingsFragment.java | 4 ++++ .../newpipe/util/SponsorBlockUtils.java | 15 ++++++++++++ app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/settings_keys.xml | 2 ++ app/src/main/res/values/strings.xml | 3 +++ .../xml/sponsor_block_category_settings.xml | 24 +++++++++++++++++++ 8 files changed, 57 insertions(+) diff --git a/app/src/main/java/org/schabi/newpipe/player/LocalPlayer.java b/app/src/main/java/org/schabi/newpipe/player/LocalPlayer.java index d8208e44f..644788e69 100644 --- a/app/src/main/java/org/schabi/newpipe/player/LocalPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/LocalPlayer.java @@ -322,6 +322,10 @@ public class LocalPlayer implements EventListener { toastText = context .getString(R.string.sponsor_block_skip_non_music_toast); break; + case "preview": + toastText = context + .getString(R.string.sponsor_block_skip_preview_toast); + break; } Toast.makeText(context, toastText, Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/org/schabi/newpipe/player/Player.java b/app/src/main/java/org/schabi/newpipe/player/Player.java index 8fcb80df1..6e02a62a3 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -1823,6 +1823,10 @@ public final class Player implements toastText = context .getString(R.string.sponsor_block_skip_non_music_toast); break; + case "preview": + toastText = context + .getString(R.string.sponsor_block_skip_preview_toast); + break; } Toast.makeText(context, toastText, Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/org/schabi/newpipe/settings/SponsorBlockCategoriesSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SponsorBlockCategoriesSettingsFragment.java index d261c2899..7247d5335 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SponsorBlockCategoriesSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SponsorBlockCategoriesSettingsFragment.java @@ -58,6 +58,10 @@ public class SponsorBlockCategoriesSettingsFragment extends BasePreferenceFragme R.string.sponsor_block_category_non_music_color_key, R.color.non_music_segment); + setColorPreference(editor, + R.string.sponsor_block_category_preview_color_key, + R.color.preview_segment); + editor.apply(); Toast.makeText(p.getContext(), R.string.sponsor_block_reset_colors_toast, diff --git a/app/src/main/java/org/schabi/newpipe/util/SponsorBlockUtils.java b/app/src/main/java/org/schabi/newpipe/util/SponsorBlockUtils.java index cf9e715d0..a6015597a 100644 --- a/app/src/main/java/org/schabi/newpipe/util/SponsorBlockUtils.java +++ b/app/src/main/java/org/schabi/newpipe/util/SponsorBlockUtils.java @@ -71,6 +71,8 @@ public final class SponsorBlockUtils { .getString(R.string.sponsor_block_category_self_promo_key), false); final boolean includeMusicCategory = prefs.getBoolean(context .getString(R.string.sponsor_block_category_non_music_key), false); + final boolean includePreviewCategory = prefs.getBoolean(context + .getString(R.string.sponsor_block_category_preview_key), false); final ArrayList categoryParamList = new ArrayList<>(); @@ -92,6 +94,9 @@ public final class SponsorBlockUtils { if (includeMusicCategory) { categoryParamList.add("music_offtopic"); } + if (includePreviewCategory) { + categoryParamList.add("preview"); + } if (categoryParamList.size() == 0) { return null; @@ -268,6 +273,16 @@ public final class SponsorBlockUtils { : Color.parseColor(colorStr); } break; + case "preview": + key = context.getString(R.string.sponsor_block_category_preview_key); + if (prefs.getBoolean(key, false)) { + key = context.getString(R.string.sponsor_block_category_preview_color_key); + colorStr = prefs.getString(key, null); + return colorStr == null + ? context.getResources().getColor(R.color.preview_segment) + : Color.parseColor(colorStr); + } + break; } return null; diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index e1d5bb011..a92009bcd 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -87,4 +87,5 @@ #cc00ff #ffff00 #ff9900 + #008fd6 diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 979b6c5d7..ed7257d5a 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -411,6 +411,8 @@ sponsor_block_category_self_promo_color sponsor_block_category_music sponsor_block_category_music_color + sponsor_block_category_preview + sponsor_block_category_preview_color sponsor_block_whitelist sponsor_block_clear_whitelist diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8a8b79e24..6597cfb4a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -160,6 +160,8 @@ Similar to "sponsor" except for unpaid or self promotion. This includes sections about merchandise, donations, or information about who they collaborated with. Music: Non-Music Section Only for use in music videos. This includes introductions or outros in music videos. + Preview/Recap + Quick recap of previous episodes, or a preview of what\'s coming up later in the current video. Meant for edited together clips, not for spoken summaries. Playing in background Playing in popup mode Content @@ -759,6 +761,7 @@ Skipped interaction reminder Skipped unpaid/self promo Skipped non-music + Skipped preview/recap Toggle skipping sponsors Clear Whitelist Clear the list of uploaders SponsorBlock will ignore. diff --git a/app/src/main/res/xml/sponsor_block_category_settings.xml b/app/src/main/res/xml/sponsor_block_category_settings.xml index e066a1a50..f97a2f8ce 100644 --- a/app/src/main/res/xml/sponsor_block_category_settings.xml +++ b/app/src/main/res/xml/sponsor_block_category_settings.xml @@ -148,6 +148,30 @@ + + + + + + + + + +