Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -377,6 +390,9 @@ private void applyActions(List<SponsorSegment> 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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ private void appendLinks(AppDialogPresenter settingsPresenter) {
private void appendMiscCategory(AppDialogPresenter settingsPresenter) {
List<OptionItem> 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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class SponsorBlockData {
private boolean mIsDontSkipSegmentAgainEnabled;
private boolean mIsPaidContentNotificationEnabled;
private long mIgnoredDurationMs;
private boolean mIsShowDurationEnabled;
private Map<String, Integer> mSegmentLocalizedMapping;
private Map<String, Integer> mSegmentColorMapping;
private Set<String> mAllCategories;
Expand Down Expand Up @@ -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();
}
Expand All @@ -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);
Expand Down Expand Up @@ -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
));
}
}
5 changes: 3 additions & 2 deletions common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@
<string name="content_block_interaction">Interaction reminder (subscribe)</string>
<string name="content_block_self_promo">Unpaid/self promotion</string>
<string name="content_block_music_off_topic">Non-music section of clip</string>
<string name="confirm_segment_skip">Skip segment \"%s\"\?</string>
<string name="confirm_segment_skip">Skip \"%s\"\?</string>
<string name="cancel_segment_skip">Cancel segment skip</string>
<string name="msg_skipping_segment">Skipping segment \"%s\"…</string>
<string name="msg_skipping_segment">Skipping \"%s\"…</string>
<string name="content_block_notification_type">Notification type</string>
<string name="content_block_notify_none">Without notification</string>
<string name="content_block_notify_toast">Toast</string>
Expand Down Expand Up @@ -463,6 +463,7 @@
<string name="playlist_order_popularity">Popularity</string>
<string name="cant_do_this_for_foreign_playlist">Can\'t do this for foreign playlist</string>
<string name="owned_playlist_warning">Error: This action can be applied only for owned playlists</string>
<string name="content_block_show_duration">Show duration in skip message</string>
<string name="content_block_alt_server">Use alternative server</string>
<string name="content_block_alt_server_desc">Enable this option if SponsorBlock refusing to work by different reasons.</string>
<string name="unset_stream_reminder">Unset stream reminder</string>
Expand Down