From 5313e4ead047b34c4c4992239e01b70db427869d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20F=C3=B6rster?= Date: Thu, 5 Sep 2024 15:06:59 +0200 Subject: [PATCH] player controls: add background opacity selection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Toni Förster --- .../Exporters/ControlsSettingsGroupExporter.swift | 1 + .../Importers/ControlsSettingsGroupImporter.swift | 4 ++++ Shared/Defaults.swift | 1 + Shared/Player/Controls/PlayerControls.swift | 4 ++++ Shared/Settings/PlayerControlsSettings.swift | 12 ++++++++++++ 5 files changed, 22 insertions(+) diff --git a/Model/Import Export Settings/Exporters/ControlsSettingsGroupExporter.swift b/Model/Import Export Settings/Exporters/ControlsSettingsGroupExporter.swift index 9654b6e8..d3bb4cc4 100644 --- a/Model/Import Export Settings/Exporters/ControlsSettingsGroupExporter.swift +++ b/Model/Import Export Settings/Exporters/ControlsSettingsGroupExporter.swift @@ -10,6 +10,7 @@ final class ConstrolsSettingsGroupExporter: SettingsGroupExporter { "seekGestureSpeed": Defaults[.seekGestureSpeed], "playerControlsLayout": Defaults[.playerControlsLayout].rawValue, "fullScreenPlayerControlsLayout": Defaults[.fullScreenPlayerControlsLayout].rawValue, + "playerControlsBackgroundOpacity": Defaults[.playerControlsBackgroundOpacity], "systemControlsCommands": Defaults[.systemControlsCommands].rawValue, "buttonBackwardSeekDuration": Defaults[.buttonBackwardSeekDuration], "buttonForwardSeekDuration": Defaults[.buttonForwardSeekDuration], diff --git a/Model/Import Export Settings/Importers/ControlsSettingsGroupImporter.swift b/Model/Import Export Settings/Importers/ControlsSettingsGroupImporter.swift index a3359cca..fd528b23 100644 --- a/Model/Import Export Settings/Importers/ControlsSettingsGroupImporter.swift +++ b/Model/Import Export Settings/Importers/ControlsSettingsGroupImporter.swift @@ -33,6 +33,10 @@ struct ConstrolsSettingsGroupImporter { Defaults[.fullScreenPlayerControlsLayout] = fullScreenPlayerControlsLayout } + if let playerControlsBackgroundOpacity = json["playerControlsBackgroundOpacity"].double { + Defaults[.playerControlsBackgroundOpacity] = playerControlsBackgroundOpacity + } + if let systemControlsCommandsString = json["systemControlsCommands"].string, let systemControlsCommands = SystemControlsCommands(rawValue: systemControlsCommandsString) { diff --git a/Shared/Defaults.swift b/Shared/Defaults.swift index 52a80787..f817bcba 100644 --- a/Shared/Defaults.swift +++ b/Shared/Defaults.swift @@ -134,6 +134,7 @@ extension Defaults.Keys { static let playerControlsLayout = Key("playerControlsLayout", default: playerControlsLayoutDefault) static let fullScreenPlayerControlsLayout = Key("fullScreenPlayerControlsLayout", default: fullScreenPlayerControlsLayoutDefault) + static let playerControlsBackgroundOpacity = Key("playerControlsBackgroundOpacity", default: 0.2) static let systemControlsCommands = Key("systemControlsCommands", default: .restartAndAdvanceToNext) diff --git a/Shared/Player/Controls/PlayerControls.swift b/Shared/Player/Controls/PlayerControls.swift index c8bfeae1..1fe060b0 100644 --- a/Shared/Player/Controls/PlayerControls.swift +++ b/Shared/Player/Controls/PlayerControls.swift @@ -29,6 +29,7 @@ struct PlayerControls: View { @Default(.playerControlsLayout) private var regularPlayerControlsLayout @Default(.fullScreenPlayerControlsLayout) private var fullScreenPlayerControlsLayout + @Default(.playerControlsBackgroundOpacity) private var playerControlsBackgroundOpacity @Default(.buttonBackwardSeekDuration) private var buttonBackwardSeekDuration @Default(.buttonForwardSeekDuration) private var buttonForwardSeekDuration @@ -270,6 +271,9 @@ struct PlayerControls: View { } } else if player.videoForDisplay == nil { Color.black + } else if model.presentingControls { + Color.black.opacity(playerControlsBackgroundOpacity) + .edgesIgnoringSafeArea(.all) } } } diff --git a/Shared/Settings/PlayerControlsSettings.swift b/Shared/Settings/PlayerControlsSettings.swift index 9d14edb5..9cf3be65 100644 --- a/Shared/Settings/PlayerControlsSettings.swift +++ b/Shared/Settings/PlayerControlsSettings.swift @@ -38,6 +38,7 @@ struct PlayerControlsSettings: View { @Default(.playerControlsAdvanceToNextEnabled) private var playerControlsAdvanceToNextEnabled @Default(.playerControlsPlaybackModeEnabled) private var playerControlsPlaybackModeEnabled @Default(.playerControlsMusicModeEnabled) private var playerControlsMusicModeEnabled + @Default(.playerControlsBackgroundOpacity) private var playerControlsBackgroundOpacity private var player = PlayerModel.shared @@ -76,6 +77,8 @@ struct PlayerControlsSettings: View { playerControlsLayoutPicker SettingsHeader(text: "Fullscreen size".localized(), secondary: true) fullScreenPlayerControlsLayoutPicker + SettingsHeader(text: "Background opacity".localized(), secondary: true) + playerControlsBackgroundOpacityPicker } #endif @@ -202,6 +205,15 @@ struct PlayerControlsSettings: View { .modifier(SettingsPickerModifier()) } + private var playerControlsBackgroundOpacityPicker: some View { + Picker("Background opacity", selection: $playerControlsBackgroundOpacity) { + ForEach(Array(stride(from: 0.0, through: 1.0, by: 0.1)), id: \.self) { value in + Text("\(Int(value * 100))%").tag(value) + } + } + .modifier(SettingsPickerModifier()) + } + @ViewBuilder private var seekingSection: some View { seekingDurationSetting("System controls", $systemControlsSeekDuration) .foregroundColor(systemControlsCommands == .restartAndAdvanceToNext ? .secondary : .primary)