Skip to content
This repository was archived by the owner on Jan 21, 2024. It is now read-only.

Commit a4b9c8f

Browse files
Merge pull request #150 from slaytostay/preview-category
Implement Preview/Recap Category
2 parents 0aaaf43 + 51c8624 commit a4b9c8f

8 files changed

Lines changed: 53 additions & 0 deletions

File tree

app/src/main/java/org/schabi/newpipe/player/LocalPlayer.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ private void triggerProgressUpdate() {
321321
toastText = context
322322
.getString(R.string.sponsor_block_skip_non_music_toast);
323323
break;
324+
case "preview":
325+
toastText = context
326+
.getString(R.string.sponsor_block_skip_preview_toast);
324327
case "filler":
325328
toastText = context
326329
.getString(R.string.sponsor_block_skip_filler_toast);

app/src/main/java/org/schabi/newpipe/player/Player.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,6 +1839,9 @@ private void triggerProgressUpdate(final boolean isRewind) {
18391839
toastText = context
18401840
.getString(R.string.sponsor_block_skip_non_music_toast);
18411841
break;
1842+
case "preview":
1843+
toastText = context
1844+
.getString(R.string.sponsor_block_skip_preview_toast);
18421845
case "filler":
18431846
toastText = context
18441847
.getString(R.string.sponsor_block_skip_filler_toast);

app/src/main/java/org/schabi/newpipe/settings/SponsorBlockCategoriesSettingsFragment.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro
5858
R.string.sponsor_block_category_non_music_color_key,
5959
R.color.non_music_segment);
6060

61+
setColorPreference(editor,
62+
R.string.sponsor_block_category_preview_color_key,
63+
R.color.preview_segment);
64+
6165
setColorPreference(editor,
6266
R.string.sponsor_block_category_filler_color_key,
6367
R.color.filler_segment);

app/src/main/java/org/schabi/newpipe/util/SponsorBlockUtils.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public static VideoSegment[] getYouTubeVideoSegments(final Context context,
7171
.getString(R.string.sponsor_block_category_self_promo_key), false);
7272
final boolean includeMusicCategory = prefs.getBoolean(context
7373
.getString(R.string.sponsor_block_category_non_music_key), false);
74+
final boolean includePreviewCategory = prefs.getBoolean(context
75+
.getString(R.string.sponsor_block_category_preview_key), false);
7476
final boolean includeFillerCategory = prefs.getBoolean(context
7577
.getString(R.string.sponsor_block_category_filler_key), false);
7678

@@ -94,6 +96,9 @@ public static VideoSegment[] getYouTubeVideoSegments(final Context context,
9496
if (includeMusicCategory) {
9597
categoryParamList.add("music_offtopic");
9698
}
99+
if (includePreviewCategory) {
100+
categoryParamList.add("preview");
101+
97102
if (includeFillerCategory) {
98103
categoryParamList.add("filler");
99104
}
@@ -273,6 +278,14 @@ static Integer parseSegmentCategory(
273278
: Color.parseColor(colorStr);
274279
}
275280
break;
281+
case "preview":
282+
key = context.getString(R.string.sponsor_block_category_preview_key);
283+
if (prefs.getBoolean(key, false)) {
284+
key = context.getString(R.string.sponsor_block_category_preview_color_key);
285+
colorStr = prefs.getString(key, null);
286+
return colorStr == null
287+
? context.getResources().getColor(R.color.preview_segment)
288+
: Color.parseColor(colorStr);
276289
case "filler":
277290
key = context.getString(R.string.sponsor_block_category_filler_key);
278291
if (prefs.getBoolean(key, false)) {

app/src/main/res/values/colors.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,6 @@
8888
<color name="interaction_segment">#cc00ff</color>
8989
<color name="self_promo_segment">#ffff00</color>
9090
<color name="non_music_segment">#ff9900</color>
91+
<color name="preview_segment">#008fd6</color>
9192
<color name="filler_segment">#7300ff</color>
9293
</resources>

app/src/main/res/values/settings_keys.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@
428428
<string name="sponsor_block_category_self_promo_color_key" translatable="false">sponsor_block_category_self_promo_color</string>
429429
<string name="sponsor_block_category_non_music_key" translatable="false">sponsor_block_category_music</string>
430430
<string name="sponsor_block_category_non_music_color_key" translatable="false">sponsor_block_category_music_color</string>
431+
<string name="sponsor_block_category_preview_key" translatable="false">sponsor_block_category_preview</string>
432+
<string name="sponsor_block_category_preview_color_key" translatable="false">sponsor_block_category_preview_color</string>
431433
<string name="sponsor_block_category_filler_key" translatable="false">sponsor_block_category_filler</string>
432434
<string name="sponsor_block_category_filler_color_key" translatable="false">sponsor_block_category_filler_color</string>
433435
<string name="sponsor_block_whitelist_key" translatable="false">sponsor_block_whitelist</string>

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@
163163
<string name="settings_category_sponsor_block_category_self_promo_summary">Similar to "sponsor" except for unpaid or self promotion. This includes sections about merchandise, donations, or information about who they collaborated with.</string>
164164
<string name="settings_category_sponsor_block_category_non_music_title">Music: Non-Music Section</string>
165165
<string name="settings_category_sponsor_block_category_non_music_summary">Only for use in music videos. This includes introductions or outros in music videos.</string>
166+
<string name="settings_category_sponsor_block_category_preview_title">Preview/Recap</string>
167+
<string name="settings_category_sponsor_block_category_preview_summary">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.</string>
166168
<string name="settings_category_sponsor_block_category_filler_title">Filler Tangent/Jokes</string>
167169
<string name="settings_category_sponsor_block_category_filler_summary">This is for tangential scenes added only for filler or humor that are not required to understand the main content of the video.</string>
168170
<string name="background_player_playing_toast">Playing in background</string>
@@ -794,6 +796,7 @@
794796
<string name="sponsor_block_skip_interaction_toast">Skipped interaction reminder</string>
795797
<string name="sponsor_block_skip_self_promo_toast">Skipped unpaid/self promo</string>
796798
<string name="sponsor_block_skip_non_music_toast">Skipped non-music</string>
799+
<string name="sponsor_block_skip_preview_toast">Skipped preview/recap</string>
797800
<string name="sponsor_block_skip_filler_toast">Skipped filler</string>
798801
<string name="sponsor_block_toggle_skipping">Toggle skipping sponsors</string>
799802
<string name="sponsor_block_clear_whitelist_title">Clear Whitelist</string>

app/src/main/res/xml/sponsor_block_category_settings.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,31 @@
147147
android:title="@string/settings_category_sponsor_block_category_color"/>
148148

149149
</PreferenceCategory>
150+
151+
<PreferenceCategory
152+
android:layout="@layout/settings_category_header_layout"
153+
android:title="@string/settings_category_sponsor_block_category_preview_title">
154+
155+
<Preference
156+
app:iconSpaceReserved="false"
157+
android:summary="@string/settings_category_sponsor_block_category_preview_summary"
158+
android:selectable="false"/>
159+
160+
<SwitchPreference
161+
app:iconSpaceReserved="false"
162+
android:defaultValue="false"
163+
android:key="@string/sponsor_block_category_preview_key"
164+
android:title="@string/settings_category_sponsor_block_category_enable_title"/>
165+
166+
<org.schabi.newpipe.settings.custom.EditColorPreference
167+
app:iconSpaceReserved="false"
168+
android:dependency="@string/sponsor_block_category_preview_key"
169+
android:defaultValue="@color/preview_segment"
170+
android:key="@string/sponsor_block_category_preview_color_key"
171+
android:title="@string/settings_category_sponsor_block_category_color"/>
150172

173+
</PreferenceCategory>
174+
151175
<PreferenceCategory
152176
android:layout="@layout/settings_category_header_layout"
153177
android:title="@string/settings_category_sponsor_block_category_filler_title">

0 commit comments

Comments
 (0)