From f5e509c0916d38182443e1743b3eaec0a94798c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20F=C3=B6rster?= Date: Tue, 20 Aug 2024 20:38:18 +0200 Subject: [PATCH] Allow hiding comments --- .../Exporters/PlayerSettingsGroupExporter.swift | 2 ++ .../Importers/PlayerSettingsGroupImporter.swift | 3 +++ Shared/Defaults.swift | 1 + Shared/Player/Video Details/VideoDetails.swift | 13 +++++++++---- Shared/Settings/PlayerSettings.swift | 8 +++++++- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Model/Import Export Settings/Exporters/PlayerSettingsGroupExporter.swift b/Model/Import Export Settings/Exporters/PlayerSettingsGroupExporter.swift index 8c2abf95..bdf3e3eb 100644 --- a/Model/Import Export Settings/Exporters/PlayerSettingsGroupExporter.swift +++ b/Model/Import Export Settings/Exporters/PlayerSettingsGroupExporter.swift @@ -36,6 +36,8 @@ final class PlayerSettingsGroupExporter: SettingsGroupExporter { export["pauseOnEnteringBackground"].bool = Defaults[.pauseOnEnteringBackground] #endif + export["showComments"].bool = Defaults[.showComments] + #if !os(tvOS) export["showScrollToTopInComments"].bool = Defaults[.showScrollToTopInComments] #endif diff --git a/Model/Import Export Settings/Importers/PlayerSettingsGroupImporter.swift b/Model/Import Export Settings/Importers/PlayerSettingsGroupImporter.swift index 3f9375fe..5333dc4b 100644 --- a/Model/Import Export Settings/Importers/PlayerSettingsGroupImporter.swift +++ b/Model/Import Export Settings/Importers/PlayerSettingsGroupImporter.swift @@ -83,6 +83,9 @@ struct PlayerSettingsGroupImporter { } #endif + if let showComments = json["showComments"].bool { + Defaults[.showComments] = showComments + } #if !os(tvOS) if let showScrollToTopInComments = json["showScrollToTopInComments"].bool { Defaults[.showScrollToTopInComments] = showScrollToTopInComments diff --git a/Shared/Defaults.swift b/Shared/Defaults.swift index f7b7415f..cd65e962 100644 --- a/Shared/Defaults.swift +++ b/Shared/Defaults.swift @@ -85,6 +85,7 @@ extension Defaults.Keys { static let playerSidebar = Key("playerSidebar", default: .defaultValue) static let showKeywords = Key("showKeywords", default: false) + static let showComments = Key("showComments", default: true) #if !os(tvOS) static let showScrollToTopInComments = Key("showScrollToTopInComments", default: true) #endif diff --git a/Shared/Player/Video Details/VideoDetails.swift b/Shared/Player/Video Details/VideoDetails.swift index 2656ee2d..c00be36c 100644 --- a/Shared/Player/Video Details/VideoDetails.swift +++ b/Shared/Player/Video Details/VideoDetails.swift @@ -189,6 +189,7 @@ struct VideoDetails: View { @Default(.showChapterThumbnails) private var showChapterThumbnails @Default(.showChapterThumbnailsOnlyWhenDifferent) private var showChapterThumbnailsOnlyWhenDifferent @Default(.showRelated) private var showRelated + @Default(.showComments) private var showComments #if !os(tvOS) @Default(.showScrollToTopInComments) private var showScrollToTopInComments #endif @@ -284,6 +285,8 @@ struct VideoDetails: View { switch page { case .queue: return !sidebarQueue && player.isAdvanceToNextItemAvailable + case .comments: + return showComments default: return !video.isLocal } @@ -362,10 +365,12 @@ struct VideoDetails: View { PlayerQueueView(sidebarQueue: false) .padding(.horizontal) case .comments: - CommentsView() - .onAppear { - comments.loadIfNeeded() - } + if showComments { + CommentsView() + .onAppear { + comments.loadIfNeeded() + } + } } } .padding(.bottom, 60) diff --git a/Shared/Settings/PlayerSettings.swift b/Shared/Settings/PlayerSettings.swift index 9c1aefdc..8df0232e 100644 --- a/Shared/Settings/PlayerSettings.swift +++ b/Shared/Settings/PlayerSettings.swift @@ -8,6 +8,7 @@ struct PlayerSettings: View { @Default(.playerSidebar) private var playerSidebar @Default(.showKeywords) private var showKeywords + @Default(.showComments) private var showComments #if !os(tvOS) @Default(.showScrollToTopInComments) private var showScrollToTopInComments @Default(.collapsedLinesDescription) private var collapsedLinesDescription @@ -175,6 +176,7 @@ struct PlayerSettings: View { if !accounts.isEmpty { keywordsToggle + commentsToggle #if !os(tvOS) showScrollToTopInCommentsToggle #endif @@ -250,9 +252,13 @@ struct PlayerSettings: View { .modifier(SettingsPickerModifier()) } + private var commentsToggle: some View { + Toggle("Show comments", isOn: $showComments) + } + #if !os(tvOS) private var showScrollToTopInCommentsToggle: some View { - Toggle("Show scroll to top button in comments", isOn: $showScrollToTopInComments) + Toggle("Show scroll to top button in comments", isOn: $showScrollToTopInComments).disabled(!showComments) } #endif