From ae65acdd16ec751512c08a9fa35822b39ed2a931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20F=C3=B6rster?= Date: Tue, 23 Apr 2024 22:08:08 +0200 Subject: [PATCH] Interface tweaks for SponsorBlock during playback Show/Hide categories in timeline. Show/Hide notice after skip. Show adjusted or actual total time. --- Model/SeekModel.swift | 4 ++-- Shared/Defaults.swift | 3 +++ Shared/Player/Controls/OSD/Seek.swift | 3 +++ Shared/Player/Controls/TimelineView.swift | 26 +++++++++++++--------- Shared/Settings/SponsorBlockSettings.swift | 10 +++++++++ 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/Model/SeekModel.swift b/Model/SeekModel.swift index 888cff0b..613da00e 100644 --- a/Model/SeekModel.swift +++ b/Model/SeekModel.swift @@ -71,13 +71,13 @@ final class SeekModel: ObservableObject { func showOSD() { guard !presentingOSD else { return } - withAnimation(.easeIn(duration: 0.1)) { self.presentingOSD = true } + presentingOSD = true } func hideOSD() { guard presentingOSD else { return } - withAnimation(.easeIn(duration: 0.1)) { self.presentingOSD = false } + presentingOSD = false } func hideOSDWithDelay() { diff --git a/Shared/Defaults.swift b/Shared/Defaults.swift index 160a5b6e..4e8499e8 100644 --- a/Shared/Defaults.swift +++ b/Shared/Defaults.swift @@ -244,6 +244,9 @@ extension Defaults.Keys { static let sponsorBlockInstance = Key("sponsorBlockInstance", default: "https://sponsor.ajay.app") static let sponsorBlockCategories = Key>("sponsorBlockCategories", default: Set(SponsorBlockAPI.categories)) static let sponsorBlockColors = Key<[String: String]>("sponsorBlockColors", default: SponsorBlockColors.dictionary) + static let sponsorBlockShowTimeWithSkipsRemoved = Key("sponsorBlockShowTimeWithSkipsRemoved", default: false) + static let sponsorBlockShowCategoriesInTimeline = Key("sponsorBlockShowCategoriesInTimeline", default: true) + static let sponsorBlockShowNoticeAfterSkip = Key("sponsorBlockShowNoticeAfterSkip", default: true) // MARK: GROUP - Locations diff --git a/Shared/Player/Controls/OSD/Seek.swift b/Shared/Player/Controls/OSD/Seek.swift index 3f102621..f729a9a0 100644 --- a/Shared/Player/Controls/OSD/Seek.swift +++ b/Shared/Player/Controls/OSD/Seek.swift @@ -14,6 +14,7 @@ struct Seek: View { @Default(.playerControlsLayout) private var regularPlayerControlsLayout @Default(.fullScreenPlayerControlsLayout) private var fullScreenPlayerControlsLayout @Default(.sponsorBlockColors) private var sponsorBlockColors + @Default(.sponsorBlockShowNoticeAfterSkip) private var showNoticeAfterSkip private func getColor(for category: String) -> Color { if let hexString = sponsorBlockColors[category], let rgbValue = Int(hexString.dropFirst(), radix: 16) { @@ -36,6 +37,7 @@ struct Seek: View { #endif } .opacity(visible || YatteeApp.isForPreviews ? 1 : 0) + .animation(.easeIn) } var content: some View { @@ -130,6 +132,7 @@ struct Seek: View { var visible: Bool { guard !(model.lastSeekTime.isNil && !model.isSeeking) else { return false } if let type = model.lastSeekType, !type.presentable { return false } + if !showNoticeAfterSkip { if case .segmentSkip? = model.lastSeekType { return false }} return !controls.presentingControls && !controls.presentingOverlays && model.presentingOSD } diff --git a/Shared/Player/Controls/TimelineView.swift b/Shared/Player/Controls/TimelineView.swift index 84508ccf..81be7876 100644 --- a/Shared/Player/Controls/TimelineView.swift +++ b/Shared/Player/Controls/TimelineView.swift @@ -52,6 +52,8 @@ struct TimelineView: View { @Default(.playerControlsLayout) private var regularPlayerControlsLayout @Default(.fullScreenPlayerControlsLayout) private var fullScreenPlayerControlsLayout @Default(.sponsorBlockColors) private var sponsorBlockColors + @Default(.sponsorBlockShowTimeWithSkipsRemoved) private var showTimeWithSkipsRemoved + @Default(.sponsorBlockShowCategoriesInTimeline) private var showCategoriesInTimeline var playerControlsLayout: PlayerControlsLayout { player.playingFullScreen ? fullScreenPlayerControlsLayout : regularPlayerControlsLayout @@ -84,13 +86,15 @@ struct TimelineView: View { Group { VStack(spacing: 3) { if dragging { - if let segment = projectedSegment, - let description = SponsorBlockAPI.categoryDescription(segment.category) - { - Text(description) - .font(.system(size: playerControlsLayout.segmentFontSize)) - .fixedSize() - .foregroundColor(getColor(for: segment.category)) + if showCategoriesInTimeline { + if let segment = projectedSegment, + let description = SponsorBlockAPI.categoryDescription(segment.category) + { + Text(description) + .font(.system(size: playerControlsLayout.segmentFontSize)) + .fixedSize() + .foregroundColor(getColor(for: segment.category)) + } } if let chapter = projectedChapter { Text(chapter.title) @@ -156,8 +160,10 @@ struct TimelineView: View { .frame(width: (dragging ? projectedValue : current) * oneUnitWidth) .zIndex(1) - segmentsLayers - .zIndex(2) + if showCategoriesInTimeline { + segmentsLayers + .zIndex(2) + } } .clipShape(RoundedRectangle(cornerRadius: cornerRadius)) @@ -247,7 +253,7 @@ struct TimelineView: View { } } } else { - Text(dragging ? playerTime.durationPlaybackTime : playerTime.withoutSegmentsPlaybackTime) + Text(dragging || !showTimeWithSkipsRemoved ? playerTime.durationPlaybackTime : playerTime.withoutSegmentsPlaybackTime) .clipShape(RoundedRectangle(cornerRadius: 3)) .frame(minWidth: 35) } diff --git a/Shared/Settings/SponsorBlockSettings.swift b/Shared/Settings/SponsorBlockSettings.swift index f51a887a..e285d5e1 100644 --- a/Shared/Settings/SponsorBlockSettings.swift +++ b/Shared/Settings/SponsorBlockSettings.swift @@ -8,6 +8,9 @@ struct SponsorBlockSettings: View { @Default(.sponsorBlockInstance) private var sponsorBlockInstance @Default(.sponsorBlockCategories) private var sponsorBlockCategories @Default(.sponsorBlockColors) private var sponsorBlockColors + @Default(.sponsorBlockShowTimeWithSkipsRemoved) private var showTimeWithSkipsRemoved + @Default(.sponsorBlockShowCategoriesInTimeline) private var showCategoriesInTimeline + @Default(.sponsorBlockShowNoticeAfterSkip) private var showNoticeAfterSkip var body: some View { Group { @@ -42,6 +45,13 @@ struct SponsorBlockSettings: View { .keyboardType(.URL) #endif } + + Section(header: Text("Playback")) { + Toggle("Categories in timeline", isOn: $showCategoriesInTimeline) + Toggle("Post-skip notice", isOn: $showNoticeAfterSkip) + Toggle("Adjusted total time", isOn: $showTimeWithSkipsRemoved) + } + Section(header: SettingsHeader(text: "Categories to Skip".localized())) { categoryRows }