diff --git a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/models/playback/controllers/SponsorBlockController.java b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/models/playback/controllers/SponsorBlockController.java index 4f9e943375..bec6438f4e 100644 --- a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/models/playback/controllers/SponsorBlockController.java +++ b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/models/playback/controllers/SponsorBlockController.java @@ -332,6 +332,19 @@ private void setPositionMs(long positionMs) { getPlayer().setPositionMs(Math.min(positionMs, durationMs)); } + private static String formatDurationMs(long ms) { + long seconds = ms / 1000; + long minutes = seconds / 60; + long hours = minutes / 60; + seconds -= minutes * 60; + minutes -= hours * 60; + + if (hours > 0) { + return String.format("%d:%02d:%02d", hours, minutes, seconds); + } + return String.format("%d:%02d", minutes, seconds); + } + /** * @param fullMatch Match only the beginning or the full segment length */ @@ -377,6 +390,9 @@ private void applyActions(List foundSegments) { Integer resId = getSponsorBlockData().getLocalizedRes(lastSegment.getCategory()); String skipMessage = resId != null ? getContext().getString(resId) : lastSegment.getCategory(); + if (getSponsorBlockData().isShowDurationEnabled()) { + skipMessage += " (" + formatDurationMs(lastSegment.getEndMs() - lastSegment.getStartMs()) + ")"; + } int type = getSponsorBlockData().getAction(lastSegment.getCategory()); diff --git a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/settings/SponsorBlockSettingsPresenter.java b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/settings/SponsorBlockSettingsPresenter.java index c49dd3dff0..2f6af3a7fc 100644 --- a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/settings/SponsorBlockSettingsPresenter.java +++ b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/settings/SponsorBlockSettingsPresenter.java @@ -145,6 +145,10 @@ private void appendLinks(AppDialogPresenter settingsPresenter) { private void appendMiscCategory(AppDialogPresenter settingsPresenter) { List options = new ArrayList<>(); + options.add(UiOptionItem.from(getContext().getString(R.string.content_block_show_duration), + optionItem -> mContentBlockData.setShowDurationEnabled(optionItem.isSelected()), + mContentBlockData.isShowDurationEnabled())); + options.add(UiOptionItem.from(getContext().getString(R.string.paid_content_notification), optionItem -> mContentBlockData.setPaidContentNotificationEnabled(optionItem.isSelected()), mContentBlockData.isPaidContentNotificationEnabled())); diff --git a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/prefs/SponsorBlockData.java b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/prefs/SponsorBlockData.java index 185efbaef0..70a844be9d 100644 --- a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/prefs/SponsorBlockData.java +++ b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/prefs/SponsorBlockData.java @@ -34,6 +34,7 @@ public class SponsorBlockData { private boolean mIsDontSkipSegmentAgainEnabled; private boolean mIsPaidContentNotificationEnabled; private long mIgnoredDurationMs; + private boolean mIsShowDurationEnabled; private Map mSegmentLocalizedMapping; private Map mSegmentColorMapping; private Set mAllCategories; @@ -234,6 +235,15 @@ public void setIgnoredDurationMs(long durationMs) { persistState(); } + public boolean isShowDurationEnabled() { + return mIsShowDurationEnabled; + } + + public void setShowDurationEnabled(boolean enabled) { + mIsShowDurationEnabled = enabled; + persistState(); + } + public boolean isAltServerEnabled() { return GlobalPreferences.instance(mAppPrefs.getContext()).isContentBlockAltServerEnabled(); } @@ -257,6 +267,7 @@ private void restoreState() { String excludedChannels = Helpers.parseStr(split, 9); mIsPaidContentNotificationEnabled = Helpers.parseBoolean(split, 10, false); mIgnoredDurationMs = Helpers.parseLong(split, 11, 5_000); + mIsShowDurationEnabled = Helpers.parseBoolean(split, 12, false); if (colorCategories != null) { String[] categoriesArr = Helpers.splitArray(colorCategories); @@ -312,7 +323,8 @@ private void persistState() { mAppPrefs.setData(SPONSOR_BLOCK_DATA, Helpers.mergeData( mIsSponsorBlockEnabled, null, null, null, null, null, actions, colorCategories, mIsDontSkipSegmentAgainEnabled, - excludedChannels, mIsPaidContentNotificationEnabled, mIgnoredDurationMs + excludedChannels, mIsPaidContentNotificationEnabled, mIgnoredDurationMs, + mIsShowDurationEnabled )); } } diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index bdf9d53ac1..4dab39ac86 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -193,9 +193,9 @@ Interaction reminder (subscribe) Unpaid/self promotion Non-music section of clip - Skip segment \"%s\"\? + Skip \"%s\"\? Cancel segment skip - Skipping segment \"%s\"… + Skipping \"%s\"… Notification type Without notification Toast @@ -463,6 +463,7 @@ Popularity Can\'t do this for foreign playlist Error: This action can be applied only for owned playlists + Show duration in skip message Use alternative server Enable this option if SponsorBlock refusing to work by different reasons. Unset stream reminder