diff --git a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java
index 25788a153..7939f4acc 100644
--- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java
+++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java
@@ -717,18 +717,47 @@ public abstract class BasePlayer implements
);
if (mPrefs.getBoolean(context.getString(R.string.sponsorblock_enable_key), false)) {
- int skipTo = getSponsorEndTimeFromProgress(currentProgress);
-
- if (skipTo == 0) {
+ VideoSegment segment = getSkippableSegment(currentProgress);
+ if (segment == null) {
return;
}
+ int skipTo = (int) Math.ceil((segment.endTime));
+
seekTo(skipTo);
if (mPrefs.getBoolean(
context.getString(R.string.sponsorblock_notifications_key), false)) {
- String toastText = context.getString(R.string.sponsorblock_skipped_segment);
- Toast.makeText(context, toastText, Toast.LENGTH_SHORT).show();
+ String toastText = "";
+
+ switch (segment.category) {
+ case "sponsor":
+ toastText = context
+ .getString(R.string.sponsorblock_skip_sponsor_message);
+ break;
+ case "intro":
+ toastText = context
+ .getString(R.string.sponsorblock_skip_intro_message);
+ break;
+ case "outro":
+ toastText = context
+ .getString(R.string.sponsorblock_skip_outro_message);
+ break;
+ case "interaction":
+ toastText = context
+ .getString(R.string.sponsorblock_skip_interaction_message);
+ break;
+ case "selfpromo":
+ toastText = context
+ .getString(R.string.sponsorblock_skip_self_promo_message);
+ break;
+ case "music_offtopic":
+ toastText = context
+ .getString(R.string.sponsorblock_skip_non_music_message);
+ break;
+ }
+
+ Toast.makeText(context, toastText, Toast.LENGTH_LONG).show();
}
if (DEBUG) {
@@ -738,9 +767,9 @@ public abstract class BasePlayer implements
}
}
- private int getSponsorEndTimeFromProgress(final int progress) {
+ public VideoSegment getSkippableSegment(final int progress) {
if (videoSegments == null) {
- return 0;
+ return null;
}
for (VideoSegment segment : videoSegments) {
@@ -752,10 +781,10 @@ public abstract class BasePlayer implements
continue;
}
- return (int) Math.ceil((segment.endTime));
+ return segment;
}
- return 0;
+ return null;
}
private Disposable getProgressReactor() {
@@ -1160,7 +1189,7 @@ public abstract class BasePlayer implements
boolean includeMusicCategory =
mPrefs.getBoolean(
context.getString(
- R.string.sponsorblock_category_music_key),
+ R.string.sponsorblock_category_non_music_key),
false);
videoSegments = new SponsorBlockApiTask(apiUrl)
diff --git a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java
index 44839cdb5..31a0725bf 100644
--- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java
+++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java
@@ -620,10 +620,10 @@ public abstract class VideoPlayer extends BasePlayer
super.onPrepared(playWhenReady);
- markSponsorTimes();
+ markSegments();
}
- private void markSponsorTimes() {
+ private void markSegments() {
VideoSegment[] segments = getVideoSegments();
if (segments == null || segments.length == 0) {
@@ -710,12 +710,12 @@ public abstract class VideoPlayer extends BasePlayer
}
break;
case "music_offtopic":
- key = context.getString(R.string.sponsorblock_category_music_key);
+ key = context.getString(R.string.sponsorblock_category_non_music_key);
if (mPrefs.getBoolean(key, false)) {
- key = context.getString(R.string.sponsorblock_category_music_color_key);
+ key = context.getString(R.string.sponsorblock_category_non_music_color_key);
colorStr = mPrefs.getString(key, null);
return colorStr == null
- ? context.getResources().getColor(R.color.music_offtopic_segment)
+ ? context.getResources().getColor(R.color.non_music_segment)
: Color.parseColor(colorStr);
}
break;
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 d66fe5b4b..5b2bf8698 100644
--- a/app/src/main/java/org/schabi/newpipe/settings/SponsorBlockCategoriesSettingsFragment.java
+++ b/app/src/main/java/org/schabi/newpipe/settings/SponsorBlockCategoriesSettingsFragment.java
@@ -1,12 +1,77 @@
package org.schabi.newpipe.settings;
+import android.content.Context;
+import android.content.SharedPreferences;
import android.os.Bundle;
+import androidx.annotation.ColorRes;
+import androidx.annotation.Nullable;
+import androidx.annotation.StringRes;
+import androidx.preference.Preference;
+
import org.schabi.newpipe.R;
+import org.schabi.newpipe.settings.custom.EditColorPreference;
public class SponsorBlockCategoriesSettingsFragment extends BasePreferenceFragment {
+ @Override
+ public void onCreate(@Nullable final Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
@Override
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
addPreferencesFromResource(R.xml.sponsor_block_category_settings);
+
+ Preference resetPreferenceView =
+ findPreference(getString(R.string.sponsorblock_category_reset_key));
+ if (resetPreferenceView != null) {
+ resetPreferenceView.setOnPreferenceClickListener(preference -> {
+ Context context = getContext();
+
+ if (context != null) {
+ SharedPreferences.Editor editor =
+ getPreferenceManager()
+ .getSharedPreferences()
+ .edit();
+
+ setColorPreference(editor,
+ R.string.sponsorblock_category_sponsor_color_key,
+ R.color.sponsor_segment);
+
+ setColorPreference(editor,
+ R.string.sponsorblock_category_intro_color_key,
+ R.color.intro_segment);
+
+ setColorPreference(editor,
+ R.string.sponsorblock_category_outro_color_key,
+ R.color.outro_segment);
+
+ setColorPreference(editor,
+ R.string.sponsorblock_category_interaction_color_key,
+ R.color.interaction_segment);
+
+ setColorPreference(editor,
+ R.string.sponsorblock_category_self_promo_color_key,
+ R.color.self_promo_segment);
+
+ setColorPreference(editor,
+ R.string.sponsorblock_category_non_music_color_key,
+ R.color.non_music_segment);
+
+ editor.apply();
+ }
+
+ return true;
+ });
+ }
+ }
+
+ private void setColorPreference(final SharedPreferences.Editor editor,
+ @StringRes final int resId,
+ @ColorRes final int colorId) {
+ String colorStr = "#" + Integer.toHexString(getResources().getColor(colorId));
+ editor.putString(getString(resId), colorStr);
+ EditColorPreference colorPreference = findPreference(getString(resId));
+ colorPreference.setText(colorStr);
}
}
diff --git a/app/src/main/java/org/schabi/newpipe/settings/custom/EditColorPreference.java b/app/src/main/java/org/schabi/newpipe/settings/custom/EditColorPreference.java
new file mode 100644
index 000000000..bf629d0fc
--- /dev/null
+++ b/app/src/main/java/org/schabi/newpipe/settings/custom/EditColorPreference.java
@@ -0,0 +1,81 @@
+package org.schabi.newpipe.settings.custom;
+
+import android.content.Context;
+import android.graphics.Color;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.Toast;
+
+import androidx.preference.EditTextPreference;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceViewHolder;
+
+import org.schabi.newpipe.R;
+
+public class EditColorPreference extends EditTextPreference
+ implements Preference.OnPreferenceChangeListener {
+ private PreferenceViewHolder viewHolder;
+
+ public EditColorPreference(final Context context, final AttributeSet attrs,
+ final int defStyleAttr, final int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ init();
+ }
+
+ public EditColorPreference(final Context context, final AttributeSet attrs,
+ final int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ init();
+ }
+
+ public EditColorPreference(final Context context, final AttributeSet attrs) {
+ super(context, attrs);
+ init();
+ }
+
+ public EditColorPreference(final Context context) {
+ super(context);
+ init();
+ }
+
+ private void init() {
+ setWidgetLayoutResource(R.layout.preference_edit_color);
+ setOnPreferenceChangeListener(this);
+ }
+
+ @Override
+ public void onBindViewHolder(final PreferenceViewHolder holder) {
+ super.onBindViewHolder(holder);
+
+ viewHolder = holder;
+
+ String colorStr =
+ getPreferenceManager()
+ .getSharedPreferences()
+ .getString(getKey(), null);
+
+ if (colorStr == null) {
+ return;
+ }
+
+ int color = Color.parseColor(colorStr);
+
+ View view = viewHolder.findViewById(R.id.segment_color_view);
+ view.setBackgroundColor(color);
+ }
+
+ @Override
+ public boolean onPreferenceChange(final Preference preference, final Object newValue) {
+ try {
+ int color = Color.parseColor((String) newValue);
+
+ View view = viewHolder.findViewById(R.id.segment_color_view);
+ view.setBackgroundColor(color);
+
+ return true;
+ } catch (Exception e) {
+ Toast.makeText(getContext(), "Invalid color", Toast.LENGTH_SHORT).show();
+ return false;
+ }
+ }
+}
diff --git a/app/src/main/res/layout/preference_edit_color.xml b/app/src/main/res/layout/preference_edit_color.xml
new file mode 100644
index 000000000..65e36abd7
--- /dev/null
+++ b/app/src/main/res/layout/preference_edit_color.xml
@@ -0,0 +1,6 @@
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index a4ad7a13b..72158b9b6 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -89,5 +89,5 @@
#0202ed
#cc00ff
#ffff00
- #ff9900
+ #ff9900
diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml
index 87e1dc1c7..c80e40a7c 100644
--- a/app/src/main/res/values/settings_keys.xml
+++ b/app/src/main/res/values/settings_keys.xml
@@ -245,6 +245,7 @@
sponsorblock_notifications
sponsorblock_privacy
sponsorblock_categories
+ sponsorblock_category_reset
sponsorblock_category_sponsor
sponsorblock_category_sponsor_color
sponsorblock_category_intro
@@ -255,8 +256,8 @@
sponsorblock_category_interaction_color
sponsorblock_category_self_promo
sponsorblock_category_self_promo_color
- sponsorblock_category_music
- sponsorblock_category_music_color
+ sponsorblock_category_music
+ sponsorblock_category_music_color
file_rename_charset
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 056fdae6d..444f47c4b 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -135,7 +135,8 @@
SponsorBlock (beta, third party service)
SponsorBlock Categories
Customize which video segments to skip, along with their color markings on the seek bar.
- Enable
+ Reset Colors
+ Enable
Seek Bar Color
Sponsor
Paid promotion, paid referrals and direct advertisements. Not for self-promotion or free shoutouts to causes/creators/websites/products they like.
@@ -147,8 +148,8 @@
When there is a short reminder to like, subscribe or follow them in the middle of content. If it is long or about something specific, it should be under self promotion instead.
Unpaid/Self Promotion
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.
+ Music: Non-Music Section
+ Only for use in music videos. This includes introductions or outros in music videos.
Playing in background
Playing in popup mode
Queued on background player
@@ -633,7 +634,6 @@
Videos that have been watched before and after being added to the playlist will be removed.\nAre you sure? This cannot be undone!
Yes, and partially watched videos
Due to ExoPlayer constraints the seek duration was set to %d seconds
- Segment skipped
- %d second
@@ -699,4 +699,10 @@
https://sponsor.ajay.app/
https://sponsor.ajay.app/api/
https://gist.github.com/ajayyy/aa9f8ded2b573d4f73a3ffa0ef74f796
+ Skipped sponsor
+ Skipped intermission/intro segment
+ Skipped endcards/credits segment
+ Skipped interaction reminder segment
+ Skipped unpaid/self promo segment
+ Skipped non-music segment
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 677cb98d0..73e7dfec0 100644
--- a/app/src/main/res/xml/sponsor_block_category_settings.xml
+++ b/app/src/main/res/xml/sponsor_block_category_settings.xml
@@ -4,6 +4,11 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:title="@string/settings_category_sponsorblock_categories_title">
+
+
@@ -17,9 +22,9 @@
app:iconSpaceReserved="false"
android:defaultValue="true"
android:key="@string/sponsorblock_category_sponsor_key"
- android:title="@string/settings_category_sponsorblock_category_enable"/>
+ android:title="@string/settings_category_sponsorblock_category_enable_title"/>
-
+ android:title="@string/settings_category_sponsorblock_category_enable_title"/>
-
+ android:title="@string/settings_category_sponsorblock_category_enable_title"/>
-
+ android:title="@string/settings_category_sponsorblock_category_enable_title"/>
-
+ android:title="@string/settings_category_sponsorblock_category_enable_title"/>
-
+ android:title="@string/settings_category_sponsorblock_category_non_music_title">
+ android:key="@string/sponsorblock_category_non_music_key"
+ android:title="@string/settings_category_sponsorblock_category_enable_title"/>
-