Model improvements

This commit is contained in:
Arkadiusz Fal
2022-09-02 01:05:31 +02:00
parent 7b48041165
commit f607e6e276
23 changed files with 194 additions and 270 deletions

View File

@@ -16,15 +16,7 @@ struct Buffering: View {
@Default(.fullScreenPlayerControlsLayout) private var fullScreenPlayerControlsLayout
var playerControlsLayout: PlayerControlsLayout {
fullScreenLayout ? fullScreenPlayerControlsLayout : regularPlayerControlsLayout
}
var fullScreenLayout: Bool {
#if os(iOS)
player.playingFullScreen || verticalSizeClass == .compact
#else
player.playingFullScreen
#endif
player.playingFullScreen ? fullScreenPlayerControlsLayout : regularPlayerControlsLayout
}
var body: some View {

View File

@@ -1,16 +1,11 @@
import SwiftUI
struct NetworkState: View {
@EnvironmentObject<PlayerModel> private var player
@EnvironmentObject<NetworkStateModel> private var model
var body: some View {
Buffering(state: model.fullStateText)
.opacity(visible ? 1 : 0)
}
var visible: Bool {
player.isPlaying && ((player.activeBackend == .mpv && model.pausedForCache) || player.isSeeking)
.opacity(model.osdVisible ? 1 : 0)
}
}

View File

@@ -15,68 +15,77 @@ struct Seek: View {
@Default(.fullScreenPlayerControlsLayout) private var fullScreenPlayerControlsLayout
var body: some View {
Button(action: model.restoreTime) {
VStack(spacing: playerControlsLayout.osdSpacing) {
ProgressBar(value: model.progress)
.frame(maxHeight: playerControlsLayout.osdProgressBarHeight)
Group {
#if os(tvOS)
content
.shadow(radius: 3)
#else
Button(action: model.restoreTime) { content }
.buttonStyle(.plain)
#endif
}
.opacity(visible || YatteeApp.isForPreviews ? 1 : 0)
}
timeline
var content: some View {
VStack(spacing: playerControlsLayout.osdSpacing) {
ProgressBar(value: model.progress)
.frame(maxHeight: playerControlsLayout.osdProgressBarHeight)
if model.isSeeking {
timeline
if model.isSeeking {
Divider()
gestureSeekTime
.foregroundColor(.secondary)
.font(.system(size: playerControlsLayout.chapterFontSize).monospacedDigit())
.frame(height: playerControlsLayout.chapterFontSize + 5)
if let chapter = projectedChapter {
Divider()
gestureSeekTime
.foregroundColor(.secondary)
.font(.system(size: playerControlsLayout.chapterFontSize).monospacedDigit())
.frame(height: playerControlsLayout.chapterFontSize + 5)
if let chapter = projectedChapter {
Text(chapter.title)
.multilineTextAlignment(.center)
.font(.system(size: playerControlsLayout.chapterFontSize))
.fixedSize(horizontal: false, vertical: true)
}
if let segment = projectedSegment {
Text(SponsorBlockAPI.categoryDescription(segment.category) ?? "Sponsor")
.font(.system(size: playerControlsLayout.segmentFontSize))
.foregroundColor(Color("AppRedColor"))
}
} else {
#if !os(tvOS)
if !model.restoreSeekTime.isNil {
Divider()
Text(chapter.title)
.multilineTextAlignment(.center)
.font(.system(size: playerControlsLayout.chapterFontSize))
.fixedSize(horizontal: false, vertical: true)
Label(model.restoreSeekPlaybackTime, systemImage: "arrow.counterclockwise")
.foregroundColor(.secondary)
.font(.system(size: playerControlsLayout.chapterFontSize).monospacedDigit())
.frame(height: playerControlsLayout.chapterFontSize + 5)
}
if let segment = projectedSegment {
Text(SponsorBlockAPI.categoryDescription(segment.category) ?? "Sponsor")
#endif
Group {
switch model.lastSeekType {
case let .segmentSkip(category):
Divider()
Text(SponsorBlockAPI.categoryDescription(category) ?? "Sponsor")
.font(.system(size: playerControlsLayout.segmentFontSize))
.foregroundColor(Color("AppRedColor"))
}
} else {
#if !os(tvOS)
if !model.restoreSeekTime.isNil {
Divider()
Label(model.restoreSeekPlaybackTime, systemImage: "arrow.counterclockwise")
.foregroundColor(.secondary)
.font(.system(size: playerControlsLayout.chapterFontSize).monospacedDigit())
.frame(height: playerControlsLayout.chapterFontSize + 5)
}
#endif
Group {
switch model.lastSeekType {
case let .segmentSkip(category):
Divider()
Text(SponsorBlockAPI.categoryDescription(category) ?? "Sponsor")
.font(.system(size: playerControlsLayout.segmentFontSize))
.foregroundColor(Color("AppRedColor"))
default:
EmptyView()
}
default:
EmptyView()
}
}
}
.frame(maxWidth: playerControlsLayout.seekOSDWidth)
#if os(tvOS)
.padding(30)
#else
.padding(2)
.modifier(ControlBackgroundModifier())
.clipShape(RoundedRectangle(cornerRadius: 3))
#endif
.foregroundColor(.primary)
}
.buttonStyle(.plain)
.opacity(visible || YatteeApp.isForPreviews ? 1 : 0)
.frame(maxWidth: playerControlsLayout.seekOSDWidth)
#if os(tvOS)
.padding(30)
#else
.padding(2)
.modifier(ControlBackgroundModifier())
.clipShape(RoundedRectangle(cornerRadius: 3))
#endif
.foregroundColor(.primary)
}
var timeline: some View {
@@ -121,16 +130,7 @@ struct Seek: View {
}
var playerControlsLayout: PlayerControlsLayout {
fullScreenLayout ? fullScreenPlayerControlsLayout : regularPlayerControlsLayout
}
var fullScreenLayout: Bool {
guard let player = model.player else { return false }
#if os(iOS)
return player.playingFullScreen || verticalSizeClass == .compact
#else
return player.playingFullScreen
#endif
(model.player?.playingFullScreen ?? false) ? fullScreenPlayerControlsLayout : regularPlayerControlsLayout
}
}

View File

@@ -10,7 +10,7 @@ struct PlayerControls: View {
private var player: PlayerModel!
private var thumbnails: ThumbnailsModel!
@EnvironmentObject<PlayerControlsModel> private var model
@ObservedObject private var model = PlayerControlsModel.shared
#if os(iOS)
@Environment(\.verticalSizeClass) private var verticalSizeClass
@@ -34,8 +34,10 @@ struct PlayerControls: View {
@Default(.playerControlsLayout) private var regularPlayerControlsLayout
@Default(.fullScreenPlayerControlsLayout) private var fullScreenPlayerControlsLayout
private let controlsOverlayModel = ControlOverlaysModel.shared
var playerControlsLayout: PlayerControlsLayout {
fullScreenLayout ? fullScreenPlayerControlsLayout : regularPlayerControlsLayout
player.playingFullScreen ? fullScreenPlayerControlsLayout : regularPlayerControlsLayout
}
init(player: PlayerModel, thumbnails: ThumbnailsModel) {
@@ -90,7 +92,7 @@ struct PlayerControls: View {
buttonsBar
HStack {
if !player.currentVideo.isNil, fullScreenLayout {
if !player.currentVideo.isNil, player.playingFullScreen {
Button {
withAnimation(Self.animation) {
model.presentingDetailsOverlay = true
@@ -160,7 +162,8 @@ struct PlayerControls: View {
.offset(y: -playerControlsLayout.timelineHeight - 5)
#endif
}
}.opacity(model.presentingControls && !model.presentingOverlays ? 1 : 0)
}
.opacity(model.presentingControls ? 1 : 0)
}
}
.frame(maxWidth: .infinity)
@@ -193,7 +196,7 @@ struct PlayerControls: View {
guard player.presentingPlayer else { return }
if value == "swipe down", !model.presentingControls, !model.presentingOverlays {
withAnimation(Self.animation) {
model.presentingControlsOverlay = true
controlsOverlayModel.presenting = false
}
} else {
model.show()
@@ -302,19 +305,19 @@ struct PlayerControls: View {
var fullscreenButton: some View {
button(
"Fullscreen",
systemImage: fullScreenLayout ? "arrow.down.right.and.arrow.up.left" : "arrow.up.left.and.arrow.down.right"
systemImage: player.playingFullScreen ? "arrow.down.right.and.arrow.up.left" : "arrow.up.left.and.arrow.down.right"
) {
player.toggleFullscreen(fullScreenLayout)
player.toggleFullscreen(player.playingFullScreen)
}
#if !os(tvOS)
.keyboardShortcut(fullScreenLayout ? .cancelAction : .defaultAction)
.keyboardShortcut(player.playingFullScreen ? .cancelAction : .defaultAction)
#endif
}
private var settingsButton: some View {
button("settings", systemImage: "gearshape") {
withAnimation(Self.animation) {
model.presentingControlsOverlay.toggle()
controlsOverlayModel.toggle()
}
}
#if os(tvOS)
@@ -492,14 +495,6 @@ struct PlayerControls: View {
.modifier(ControlBackgroundModifier(enabled: useBackground))
.clipShape(RoundedRectangle(cornerRadius: cornerRadius))
}
var fullScreenLayout: Bool {
#if os(iOS)
player.playingFullScreen || verticalSizeClass == .compact
#else
player.playingFullScreen
#endif
}
}
struct PlayerControls_Previews: PreviewProvider {

View File

@@ -47,16 +47,16 @@ struct TVControls: UIViewRepresentable {
func updateUIView(_: UIView, context _: Context) {}
func makeCoordinator() -> TVControls.Coordinator {
Coordinator(controlsArea, model: model)
Coordinator(controlsArea)
}
final class Coordinator: NSObject {
private let view: UIView
private let model: PlayerControlsModel
init(_ view: UIView, model: PlayerControlsModel) {
init(_ view: UIView) {
self.view = view
self.model = model
model = .shared
super.init()
}

View File

@@ -53,15 +53,7 @@ struct TimelineView: View {
@Default(.fullScreenPlayerControlsLayout) private var fullScreenPlayerControlsLayout
var playerControlsLayout: PlayerControlsLayout {
fullScreenLayout ? fullScreenPlayerControlsLayout : regularPlayerControlsLayout
}
var fullScreenLayout: Bool {
#if os(iOS)
player.playingFullScreen || verticalSizeClass == .compact
#else
player.playingFullScreen
#endif
player.playingFullScreen ? fullScreenPlayerControlsLayout : regularPlayerControlsLayout
}
var chapters: [Chapter] {