1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-15 14:50:32 +05:30
yattee/Shared/Player/Video Details/PlayerQueueView.swift

130 lines
3.8 KiB
Swift
Raw Normal View History

2021-11-06 01:27:22 +05:30
import Defaults
import Foundation
import SwiftUI
struct PlayerQueueView: View {
var sidebarQueue: Bool
@FetchRequest(sortDescriptors: [.init(key: "watchedAt", ascending: false)])
var watches: FetchedResults<Watch>
@ObservedObject private var player = PlayerModel.shared
2021-11-06 01:27:22 +05:30
@Default(.saveHistory) private var saveHistory
var body: some View {
Group {
Group {
2022-07-11 23:14:49 +05:30
if player.playbackMode == .related {
autoplaying
}
playingNext
2022-09-02 04:35:41 +05:30
if sidebarQueue {
2021-11-04 04:30:17 +05:30
related
}
}
2022-07-10 23:21:46 +05:30
.listRowBackground(Color.clear)
2021-11-03 04:32:02 +05:30
#if !os(iOS)
2022-07-10 23:21:46 +05:30
.padding(.vertical, 5)
.listRowInsets(EdgeInsets())
#endif
2022-11-14 02:22:29 +05:30
Color.clear.padding(.bottom, 50)
.listRowBackground(Color.clear)
2023-07-01 22:08:11 +05:30
#if os(iOS)
.listRowSeparator(.hidden)
#endif
}
2022-12-13 06:20:26 +05:30
.environment(\.inNavigationView, false)
}
2022-07-11 23:14:49 +05:30
@ViewBuilder var autoplaying: some View {
Section(header: autoplayingHeader) {
if let item = player.autoplayItem {
PlayerQueueRow(item: item, autoplay: true)
} else {
Group {
if player.currentItem.isNil {
Text("Not Playing")
} else {
Text("Finding something to play...")
}
}
.foregroundColor(.secondary)
}
}
}
var autoplayingHeader: some View {
HStack {
Text("Autoplaying Next")
.foregroundColor(.secondary)
.font(.caption)
2022-07-11 23:14:49 +05:30
Spacer()
Button {
player.setRelatedAutoplayItem()
} label: {
Label("Find Other", systemImage: "arrow.triangle.2.circlepath.circle")
.labelStyle(.iconOnly)
}
.disabled(player.currentItem.isNil)
.buttonStyle(.plain)
}
}
var playingNext: some View {
Section(header: queueHeader) {
if player.queue.isEmpty {
2022-07-11 23:14:49 +05:30
Text("Queue is empty")
.foregroundColor(.secondary)
}
ForEach(player.queue) { item in
2022-12-14 00:45:22 +05:30
PlayerQueueRow(item: item)
.contextMenu {
2022-08-14 22:31:22 +05:30
if let video = item.video {
VideoContextMenuView(video: video)
2022-12-19 15:18:30 +05:30
.environment(\.inQueueListing, true)
2022-08-14 22:31:22 +05:30
}
}
}
}
}
var queueHeader: some View {
Text("Queue".localized())
#if !os(macOS)
.foregroundColor(.secondary)
.font(.caption)
.frame(maxWidth: .infinity, alignment: .leading)
#endif
}
private var visibleWatches: [Watch] {
watches.filter { $0.videoID != player.currentVideo?.videoID }
}
2022-08-25 22:39:55 +05:30
@ViewBuilder private var related: some View {
if let related = player.currentVideo?.related, !related.isEmpty {
Section(header: Text("Related")) {
ForEach(related) { video in
2022-12-14 00:45:22 +05:30
PlayerQueueRow(item: PlayerQueueItem(video))
2022-08-25 22:39:55 +05:30
.contextMenu {
VideoContextMenuView(video: video)
}
.id(video.videoID)
2021-11-03 04:32:02 +05:30
}
}
2022-08-25 22:39:55 +05:30
.transaction { t in t.disablesAnimations = true }
2021-11-03 04:32:02 +05:30
}
}
}
struct PlayerQueueView_Previews: PreviewProvider {
static var previews: some View {
VStack {
2022-12-19 04:39:54 +05:30
PlayerQueueView(sidebarQueue: true)
}
.injectFixtureEnvironmentObjects()
}
}