mirror of
https://github.com/yattee/yattee.git
synced 2025-08-05 18:24:02 +00:00
Setting for player sidebar
This commit is contained in:
@@ -2,6 +2,7 @@ import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct PlayerQueueView: View {
|
||||
@Binding var sidebarQueue: Bool
|
||||
@Binding var fullScreen: Bool
|
||||
|
||||
@EnvironmentObject<PlayerModel> private var player
|
||||
@@ -10,7 +11,9 @@ struct PlayerQueueView: View {
|
||||
List {
|
||||
Group {
|
||||
playingNext
|
||||
related
|
||||
if sidebarQueue {
|
||||
related
|
||||
}
|
||||
playedPreviously
|
||||
}
|
||||
#if !os(iOS)
|
||||
@@ -119,7 +122,7 @@ struct PlayerQueueView: View {
|
||||
struct PlayerQueueView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
VStack {
|
||||
PlayerQueueView(fullScreen: .constant(true))
|
||||
PlayerQueueView(sidebarQueue: .constant(true), fullScreen: .constant(true))
|
||||
}
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
|
@@ -58,7 +58,7 @@ struct VideoDetails: View {
|
||||
}
|
||||
.padding(.horizontal)
|
||||
|
||||
if !video.isNil, !sidebarQueue {
|
||||
if !sidebarQueue {
|
||||
pagePicker
|
||||
.padding(.horizontal)
|
||||
}
|
||||
@@ -87,25 +87,19 @@ struct VideoDetails: View {
|
||||
detailsPage
|
||||
}
|
||||
case .queue:
|
||||
PlayerQueueView(fullScreen: $fullScreen)
|
||||
PlayerQueueView(sidebarQueue: $sidebarQueue, fullScreen: $fullScreen)
|
||||
.edgesIgnoringSafeArea(.horizontal)
|
||||
|
||||
case .related:
|
||||
#if os(macOS)
|
||||
EmptyView()
|
||||
#else
|
||||
RelatedView()
|
||||
.edgesIgnoringSafeArea(.horizontal)
|
||||
#endif
|
||||
RelatedView()
|
||||
.edgesIgnoringSafeArea(.horizontal)
|
||||
}
|
||||
}
|
||||
.padding(.top, inNavigationView && fullScreen ? 10 : 0)
|
||||
.onAppear {
|
||||
#if !os(macOS)
|
||||
if video.isNil {
|
||||
currentPage = .queue
|
||||
}
|
||||
#endif
|
||||
if video.isNil {
|
||||
currentPage = .queue
|
||||
}
|
||||
|
||||
guard video != nil, accounts.app.supportsSubscriptions else {
|
||||
subscribed = false
|
||||
@@ -115,15 +109,13 @@ struct VideoDetails: View {
|
||||
subscribed = subscriptions.isSubscribing(video!.channel.id)
|
||||
}
|
||||
.onChange(of: sidebarQueue) { queue in
|
||||
#if !os(macOS)
|
||||
if queue {
|
||||
if currentPage == .queue {
|
||||
currentPage = .details
|
||||
}
|
||||
} else {
|
||||
currentPage = .queue
|
||||
if queue {
|
||||
if currentPage == .queue {
|
||||
currentPage = .details
|
||||
}
|
||||
#endif
|
||||
} else if video.isNil {
|
||||
currentPage = .queue
|
||||
}
|
||||
}
|
||||
.edgesIgnoringSafeArea(.horizontal)
|
||||
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
|
||||
@@ -134,9 +126,7 @@ struct VideoDetails: View {
|
||||
if video != nil {
|
||||
Text(video!.title)
|
||||
.onAppear {
|
||||
#if !os(macOS)
|
||||
currentPage = .details
|
||||
#endif
|
||||
currentPage = .details
|
||||
}
|
||||
|
||||
.font(.title2.bold())
|
||||
@@ -225,11 +215,13 @@ struct VideoDetails: View {
|
||||
|
||||
var pagePicker: some View {
|
||||
Picker("Page", selection: $currentPage) {
|
||||
Text("Details").tag(Page.details)
|
||||
Text("Related").tag(Page.related)
|
||||
if !video.isNil {
|
||||
Text("Details").tag(Page.details)
|
||||
Text("Related").tag(Page.related)
|
||||
}
|
||||
Text("Queue").tag(Page.queue)
|
||||
}
|
||||
|
||||
.labelsHidden()
|
||||
.pickerStyle(.segmented)
|
||||
.onDisappear {
|
||||
currentPage = .details
|
||||
|
@@ -13,34 +13,37 @@ struct VideoPlayerView: View {
|
||||
#endif
|
||||
}
|
||||
|
||||
@State private var playerSize: CGSize = .zero
|
||||
@State private var fullScreen = false
|
||||
|
||||
#if os(iOS)
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
|
||||
@Environment(\.verticalSizeClass) private var verticalSizeClass
|
||||
|
||||
private var idiom: UIUserInterfaceIdiom {
|
||||
UIDevice.current.userInterfaceIdiom
|
||||
}
|
||||
#endif
|
||||
|
||||
@EnvironmentObject<PlayerModel> private var player
|
||||
|
||||
var body: some View {
|
||||
#if os(macOS)
|
||||
HSplitView {
|
||||
content
|
||||
}
|
||||
.frame(idealWidth: 1000, maxWidth: 1100, minHeight: 700)
|
||||
#else
|
||||
HStack(spacing: 0) {
|
||||
content
|
||||
}
|
||||
#if os(iOS)
|
||||
GeometryReader { geometry in
|
||||
#if os(macOS)
|
||||
HSplitView {
|
||||
content
|
||||
}
|
||||
.frame(idealWidth: 1000, maxWidth: 1100, minHeight: 700)
|
||||
#else
|
||||
HStack(spacing: 0) {
|
||||
content
|
||||
}
|
||||
.onAppear {
|
||||
self.playerSize = geometry.size
|
||||
}
|
||||
.onChange(of: geometry.size) { size in
|
||||
self.playerSize = size
|
||||
}
|
||||
.navigationBarHidden(true)
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
var content: some View {
|
||||
@@ -92,7 +95,7 @@ struct VideoPlayerView: View {
|
||||
}
|
||||
|
||||
#else
|
||||
VideoDetails(fullScreen: $fullScreen)
|
||||
VideoDetails(sidebarQueue: sidebarQueueBinding, fullScreen: $fullScreen)
|
||||
#endif
|
||||
}
|
||||
.background()
|
||||
@@ -105,12 +108,14 @@ struct VideoPlayerView: View {
|
||||
#endif
|
||||
#if os(iOS)
|
||||
if sidebarQueue {
|
||||
PlayerQueueView(fullScreen: $fullScreen)
|
||||
PlayerQueueView(sidebarQueue: .constant(true), fullScreen: $fullScreen)
|
||||
.frame(maxWidth: 350)
|
||||
}
|
||||
#elseif os(macOS)
|
||||
PlayerQueueView(fullScreen: $fullScreen)
|
||||
.frame(minWidth: 250)
|
||||
if Defaults[.playerSidebar] != .never {
|
||||
PlayerQueueView(sidebarQueue: sidebarQueueBinding, fullScreen: $fullScreen)
|
||||
.frame(minWidth: 250)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
.onDisappear {
|
||||
@@ -140,18 +145,23 @@ struct VideoPlayerView: View {
|
||||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: geometry.size.width / VideoPlayerView.defaultAspectRatio)
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
var sidebarQueue: Bool {
|
||||
horizontalSizeClass == .regular && idiom == .pad
|
||||
var sidebarQueue: Bool {
|
||||
switch Defaults[.playerSidebar] {
|
||||
case .never:
|
||||
return false
|
||||
case .always:
|
||||
return true
|
||||
case .whenFits:
|
||||
return playerSize.width > 900
|
||||
}
|
||||
}
|
||||
|
||||
var sidebarQueueBinding: Binding<Bool> {
|
||||
Binding(
|
||||
get: { self.sidebarQueue },
|
||||
set: { _ in }
|
||||
)
|
||||
}
|
||||
#endif
|
||||
var sidebarQueueBinding: Binding<Bool> {
|
||||
Binding(
|
||||
get: { sidebarQueue },
|
||||
set: { _ in }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
struct VideoPlayerView_Previews: PreviewProvider {
|
||||
|
Reference in New Issue
Block a user