Skip to content

Commit 32d2abc

Browse files
committed
feat(sponsorblock): add "hook" category
ajayyy/SponsorBlock@f4d2558
1 parent 089672b commit 32d2abc

File tree

7 files changed

+69
-3
lines changed

7 files changed

+69
-3
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro
4242
findPreference(getString(R.string.sponsor_block_category_non_music_key));
4343
final SwitchPreference previewCategoryPreference =
4444
findPreference(getString(R.string.sponsor_block_category_preview_key));
45+
final SwitchPreference hookCategoryPreference =
46+
findPreference(getString(R.string.sponsor_block_category_hook_key));
4547
final SwitchPreference fillerCategoryPreference =
4648
findPreference(getString(R.string.sponsor_block_category_filler_key));
4749

@@ -53,6 +55,7 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro
5355
selfPromoCategoryPreference.setChecked(true);
5456
nonMusicCategoryPreference.setChecked(true);
5557
previewCategoryPreference.setChecked(true);
58+
hookCategoryPreference.setChecked(true);
5659
fillerCategoryPreference.setChecked(true);
5760

5861
return true;
@@ -77,6 +80,8 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro
7780
findPreference(getString(R.string.sponsor_block_category_non_music_key));
7881
final SwitchPreference previewCategoryPreference =
7982
findPreference(getString(R.string.sponsor_block_category_preview_key));
83+
final SwitchPreference hookCategoryPreference =
84+
findPreference(getString(R.string.sponsor_block_category_hook_key));
8085
final SwitchPreference fillerCategoryPreference =
8186
findPreference(getString(R.string.sponsor_block_category_filler_key));
8287

@@ -88,6 +93,7 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro
8893
selfPromoCategoryPreference.setChecked(false);
8994
nonMusicCategoryPreference.setChecked(false);
9095
previewCategoryPreference.setChecked(false);
96+
hookCategoryPreference.setChecked(false);
9197
fillerCategoryPreference.setChecked(false);
9298

9399
return true;
@@ -128,6 +134,9 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro
128134
setColorPreference(editor,
129135
R.string.sponsor_block_category_preview_color_key,
130136
R.color.preview_segment);
137+
setColorPreference(editor,
138+
R.string.sponsor_block_category_hook_color_key,
139+
R.color.hook_segment);
131140
setColorPreference(editor,
132141
R.string.sponsor_block_category_filler_color_key,
133142
R.color.filler_segment);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,9 @@ private static String capitalizeIfAllUppercase(final String text) {
423423
result.includePreviewCategory =
424424
prefs.getBoolean(context
425425
.getString(R.string.sponsor_block_category_preview_key), false);
426+
result.includeHookCategory =
427+
prefs.getBoolean(context
428+
.getString(R.string.sponsor_block_category_hook_key), false);
426429
result.includeFillerCategory =
427430
prefs.getBoolean(context
428431
.getString(R.string.sponsor_block_category_filler_key), false);

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ public static Integer convertCategoryToColor(
8484
? context.getResources().getColor(R.color.preview_segment)
8585
: Color.parseColor(colorStr);
8686
}
87+
case HOOK -> {
88+
key = context.getString(R.string.sponsor_block_category_hook_color_key);
89+
colorStr = prefs.getString(key, null);
90+
return colorStr == null
91+
? context.getResources().getColor(R.color.hook_segment)
92+
: Color.parseColor(colorStr);
93+
}
8794
case FILLER -> {
8895
key = context.getString(R.string.sponsor_block_category_filler_color_key);
8996
colorStr = prefs.getString(key, null);
@@ -156,6 +163,8 @@ public static String convertCategoryToFriendlyName(final Context context,
156163
R.string.sponsor_block_category_non_music);
157164
case PREVIEW -> context.getString(
158165
R.string.sponsor_block_category_preview);
166+
case HOOK -> context.getString(
167+
R.string.sponsor_block_category_hook);
159168
case FILLER -> context.getString(
160169
R.string.sponsor_block_category_filler);
161170
case PENDING -> context.getString(
@@ -181,6 +190,8 @@ public static String convertCategoryToSkipMessage(final Context context,
181190
.getString(R.string.sponsor_block_skip_non_music_toast);
182191
case PREVIEW -> context
183192
.getString(R.string.sponsor_block_skip_preview_toast);
193+
case HOOK -> context
194+
.getString(R.string.sponsor_block_skip_hook_toast);
184195
case FILLER -> context
185196
.getString(R.string.sponsor_block_skip_filler_toast);
186197
case PENDING -> context

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
<color name="self_promo_segment">#ffff00</color>
9494
<color name="non_music_segment">#ff9900</color>
9595
<color name="preview_segment">#008fd6</color>
96+
<color name="hook_segment">#395699</color>
9697
<color name="filler_segment">#7300ff</color>
9798
<color name="pending_segment">#ffffff</color>
9899

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@
265265
<item>5</item>
266266
<item>10</item>
267267
</string-array>
268-
268+
269269
<string name="middle_gesture_area_width_key">middle_gesture_area_width</string>
270270
<string name="default_middle_gesture_area_width_value">.3333</string>
271271
<string-array name="middle_gesture_area_width_description_list">
@@ -1594,6 +1594,9 @@
15941594
<string name="sponsor_block_category_preview_key" translatable="false">sponsor_block_category_preview</string>
15951595
<string name="sponsor_block_category_preview_mode_key" translatable="false">sponsor_block_category_preview_mode</string>
15961596
<string name="sponsor_block_category_preview_color_key" translatable="false">sponsor_block_category_preview_color</string>
1597+
<string name="sponsor_block_category_hook_key" translatable="false">sponsor_block_category_hook</string>
1598+
<string name="sponsor_block_category_hook_mode_key" translatable="false">sponsor_block_category_hook_mode</string>
1599+
<string name="sponsor_block_category_hook_color_key" translatable="false">sponsor_block_category_hook_color</string>
15971600
<string name="sponsor_block_category_filler_key" translatable="false">sponsor_block_category_filler</string>
15981601
<string name="sponsor_block_category_filler_mode_key" translatable="false">sponsor_block_category_filler_mode</string>
15991602
<string name="sponsor_block_category_filler_color_key" translatable="false">sponsor_block_category_filler_color</string>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,8 @@
892892
<string name="sponsor_block_category_self_promo">Unpaid/Self Promotion</string>
893893
<string name="sponsor_block_category_non_music">Music: Non-Music Section</string>
894894
<string name="sponsor_block_category_preview">Preview/Recap</string>
895-
<string name="sponsor_block_category_filler">Filler Tangent/Jokes</string>
895+
<string name="sponsor_block_category_hook">Hook/Greetings</string>
896+
<string name="sponsor_block_category_filler">Tangent/Jokes</string>
896897
<string name="sponsor_block_category_pending">Pending</string>
897898
<string name="sponsor_block_home_page_title">View Website</string>
898899
<string name="sponsor_block_home_page_summary">View the official SponsorBlock website.</string>
@@ -916,6 +917,7 @@
916917
<string name="sponsor_block_skip_self_promo_toast">Skipped unpaid/self promo</string>
917918
<string name="sponsor_block_skip_non_music_toast">Skipped non-music</string>
918919
<string name="sponsor_block_skip_preview_toast">Skipped preview/recap</string>
920+
<string name="sponsor_block_skip_hook_toast">Skipped hook</string>
919921
<string name="sponsor_block_skip_filler_toast">Skipped filler</string>
920922
<string name="sponsor_block_skip_pending_toast">Skipped pending segment</string>
921923
<string name="sponsor_block_toggle_skipping">Toggle skipping sponsors</string>
@@ -963,6 +965,7 @@
963965
<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>
964966
<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>
965967
<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>
968+
<string name="settings_category_sponsor_block_category_hook_summary">For narrative hooks that tease upcoming moments in a video, plus dedicated greetings and goodbyes.</string>
966969
<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>
967970
<string name="settings_category_sponsor_block_category_pending_summary">Represents a new segment ready to be submitted.</string>
968971
<string name="submit">Submit</string>

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,42 @@
291291

292292
</PreferenceCategory>
293293

294+
<PreferenceCategory
295+
android:layout="@layout/settings_category_header_layout"
296+
android:title="@string/sponsor_block_category_hook">
297+
298+
<Preference
299+
app:iconSpaceReserved="false"
300+
android:summary="@string/settings_category_sponsor_block_category_hook_summary"
301+
android:selectable="false"/>
302+
303+
<SwitchPreference
304+
app:iconSpaceReserved="false"
305+
android:defaultValue="true"
306+
android:key="@string/sponsor_block_category_hook_key"
307+
android:title="@string/settings_category_sponsor_block_category_enable_title"/>
308+
309+
<ListPreference
310+
app:iconSpaceReserved="false"
311+
app:singleLineTitle="false"
312+
app:useSimpleSummaryProvider="true"
313+
android:dependency="@string/sponsor_block_category_hook_key"
314+
android:defaultValue="@string/sponsor_block_skip_mode_enabled"
315+
android:entries="@array/sponsor_block_category_sponsor_modes_key"
316+
android:entryValues="@array/sponsor_block_category_sponsor_modes_key"
317+
android:key="@string/sponsor_block_category_hook_mode_key"
318+
android:title="@string/settings_category_sponsor_block_category_enable_mode_title"
319+
/>
320+
321+
<org.schabi.newpipe.settings.custom.EditColorPreference
322+
app:iconSpaceReserved="false"
323+
android:dependency="@string/sponsor_block_category_hook_key"
324+
android:defaultValue="@color/hook_segment"
325+
android:key="@string/sponsor_block_category_hook_color_key"
326+
android:title="@string/settings_category_sponsor_block_category_color"/>
327+
328+
</PreferenceCategory>
329+
294330
<PreferenceCategory
295331
android:layout="@layout/settings_category_header_layout"
296332
android:title="@string/sponsor_block_category_filler">
@@ -343,4 +379,4 @@
343379
android:title="@string/settings_category_sponsor_block_category_color"/>
344380

345381
</PreferenceCategory>
346-
</PreferenceScreen>
382+
</PreferenceScreen>

0 commit comments

Comments
 (0)