Revert "idk tf is this 😭"

This reverts commit 5fc30927a7.
This commit is contained in:
Francesco 2025-05-17 17:25:22 +02:00
parent 15a9a36c00
commit 935dc2792b
3 changed files with 57 additions and 56 deletions

View file

@ -70,8 +70,7 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
var subtitleForegroundColor: String = "white"
var subtitleBackgroundEnabled: Bool = true
var subtitleFontSize: Double = 20.0
var subtitleOutlineWidth: Double = 1.0
var subtitleOutlineColor: String = "black"
var subtitleShadowRadius: Double = 1.0
var subtitlesLoader = VTTSubtitlesLoader()
var subtitleStackView: UIStackView!
var subtitleLabels: [UILabel] = []
@ -1353,33 +1352,10 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
: .clear
subtitleLabel.layer.cornerRadius = 5
subtitleLabel.clipsToBounds = true
if subtitleOutlineWidth > 0 {
let textColor = subtitleUIColor()
let outlineColor = outlineUIColor()
let strokeTextAttributes = [
NSAttributedString.Key.strokeColor: outlineColor,
NSAttributedString.Key.foregroundColor: textColor,
NSAttributedString.Key.strokeWidth: -CGFloat(subtitleOutlineWidth),
NSAttributedString.Key.font: UIFont.systemFont(ofSize: CGFloat(subtitleFontSize), weight: .bold)
] as [NSAttributedString.Key : Any]
if let text = subtitleLabel.text {
subtitleLabel.attributedText = NSAttributedString(string: text, attributes: strokeTextAttributes)
}
}
}
}
private func outlineUIColor() -> UIColor {
switch subtitleOutlineColor {
case "black": return .black
case "white": return .white
case "yellow": return .yellow
case "green": return .green
case "blue": return .blue
case "red": return .red
default: return .black
subtitleLabel.layer.shadowColor = UIColor.black.cgColor
subtitleLabel.layer.shadowRadius = CGFloat(subtitleShadowRadius)
subtitleLabel.layer.shadowOpacity = 1.0
subtitleLabel.layer.shadowOffset = .zero
}
}
@ -1753,16 +1729,19 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
UIView.animate(withDuration: 0.25) {
self.blackCoverView.alpha = self.isDimmed ? 1.0 : 0.4
// fade all controls (and lock button) in or out
for v in self.controlsToHide { v.alpha = self.isDimmed ? 0 : 1 }
self.dimButton.alpha = self.isDimmed ? 0 : 1
self.lockButton.alpha = self.isDimmed ? 0 : 1
// switch subtitle constraints just like toggleControls()
self.subtitleBottomToSafeAreaConstraint?.isActive = !self.isControlsVisible
self.subtitleBottomToSliderConstraint?.isActive = self.isControlsVisible
self.view.layoutIfNeeded()
}
// slide the dim-icon over
dimButtonToSlider.isActive = !isDimmed
dimButtonToRight.isActive = isDimmed
}
@ -2115,6 +2094,30 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
]
let fontSizeMenu = UIMenu(title: "Font Size", children: fontSizeActions)
let shadowActions = [
UIAction(title: "None") { _ in
SubtitleSettingsManager.shared.update { settings in settings.shadowRadius = 0 }
self.loadSubtitleSettings()
self.updateSubtitleLabelAppearance()
},
UIAction(title: "Low") { _ in
SubtitleSettingsManager.shared.update { settings in settings.shadowRadius = 1 }
self.loadSubtitleSettings()
self.updateSubtitleLabelAppearance()
},
UIAction(title: "Medium") { _ in
SubtitleSettingsManager.shared.update { settings in settings.shadowRadius = 3 }
self.loadSubtitleSettings()
self.updateSubtitleLabelAppearance()
},
UIAction(title: "High") { _ in
SubtitleSettingsManager.shared.update { settings in settings.shadowRadius = 6 }
self.loadSubtitleSettings()
self.updateSubtitleLabelAppearance()
}
]
let shadowMenu = UIMenu(title: "Shadow Intensity", children: shadowActions)
let backgroundActions = [
UIAction(title: "Toggle") { _ in
SubtitleSettingsManager.shared.update { settings in settings.backgroundEnabled.toggle() }
@ -2174,7 +2177,7 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
let delayMenu = UIMenu(title: "Subtitle Delay", children: delayActions + [resetDelayAction])
let subtitleOptionsMenu = UIMenu(title: "Subtitle Options", children: [
subtitlesToggleAction, colorMenu, fontSizeMenu, backgroundMenu, paddingMenu, delayMenu
subtitlesToggleAction, colorMenu, fontSizeMenu, shadowMenu, backgroundMenu, paddingMenu, delayMenu
])
menuElements = [subtitleOptionsMenu]
@ -2253,8 +2256,7 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele
let settings = SubtitleSettingsManager.shared.settings
self.subtitleForegroundColor = settings.foregroundColor
self.subtitleFontSize = settings.fontSize
self.subtitleOutlineColor = settings.outlineColor
self.subtitleOutlineWidth = settings.outlineWidth
self.subtitleShadowRadius = settings.shadowRadius
self.subtitleBackgroundEnabled = settings.backgroundEnabled
self.subtitleBottomPadding = settings.bottomPadding
self.subtitleDelay = settings.subtitleDelay

View file

@ -10,8 +10,7 @@ import UIKit
struct SubtitleSettings: Codable {
var foregroundColor: String = "white"
var fontSize: Double = 20.0
var outlineWidth: Double = 1.0
var outlineColor: String = "white"
var shadowRadius: Double = 1.0
var backgroundEnabled: Bool = true
var bottomPadding: CGFloat = 20.0
var subtitleDelay: Double = 0.0

View file

@ -126,13 +126,13 @@ struct SettingsViewPlayer: View {
struct SubtitleSettingsSection: View {
@State private var foregroundColor: String = SubtitleSettingsManager.shared.settings.foregroundColor
@State private var fontSize: Double = SubtitleSettingsManager.shared.settings.fontSize
@State private var outlineWidth: Double = SubtitleSettingsManager.shared.settings.outlineWidth
@State private var outlineColor: String = SubtitleSettingsManager.shared.settings.outlineColor
@State private var shadowRadius: Double = SubtitleSettingsManager.shared.settings.shadowRadius
@State private var backgroundEnabled: Bool = SubtitleSettingsManager.shared.settings.backgroundEnabled
@State private var bottomPadding: CGFloat = SubtitleSettingsManager.shared.settings.bottomPadding
@State private var subtitleDelay: Double = SubtitleSettingsManager.shared.settings.subtitleDelay
private let colors = ["white", "yellow", "green", "blue", "red", "purple"]
private let shadowOptions = [0, 1, 3, 6]
var body: some View {
Section(header: Text("Subtitle Settings")) {
@ -153,6 +153,23 @@ struct SubtitleSettingsSection: View {
}
}
HStack {
Text("Shadow")
Spacer()
Menu("\(Int(shadowRadius))") {
ForEach(shadowOptions, id: \.self) { option in
Button(action: {
shadowRadius = Double(option)
SubtitleSettingsManager.shared.update { settings in
settings.shadowRadius = Double(option)
}
}) {
Text("\(option)")
}
}
}
}
Toggle("Background Enabled", isOn: $backgroundEnabled)
.tint(.accentColor)
.onChange(of: backgroundEnabled) { newValue in
@ -172,23 +189,6 @@ struct SubtitleSettingsSection: View {
}
}
HStack {
Text("Outline Color")
Spacer()
Menu(outlineColor) {
ForEach(colors, id: \.self) { color in
Button(action: {
outlineColor = color
SubtitleSettingsManager.shared.update { settings in
settings.outlineColor = color
}
}) {
Text(color.capitalized)
}
}
}
}
HStack {
Text("Bottom Padding:")
Spacer()