2021-11-05 19:57:22 +00:00
|
|
|
import Defaults
|
2021-10-05 20:20:09 +00:00
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct PlayerQueueView: View {
|
2022-06-18 12:39:49 +00:00
|
|
|
var sidebarQueue: Bool
|
2021-10-05 20:20:09 +00:00
|
|
|
|
2021-12-26 21:14:46 +00:00
|
|
|
@FetchRequest(sortDescriptors: [.init(key: "watchedAt", ascending: false)])
|
|
|
|
var watches: FetchedResults<Watch>
|
|
|
|
|
2022-11-24 20:36:05 +00:00
|
|
|
@ObservedObject private var player = PlayerModel.shared
|
2021-10-05 20:20:09 +00:00
|
|
|
|
2021-11-05 19:57:22 +00:00
|
|
|
@Default(.saveHistory) private var saveHistory
|
|
|
|
|
2021-10-05 20:20:09 +00:00
|
|
|
var body: some View {
|
|
|
|
List {
|
2021-10-23 10:13:05 +00:00
|
|
|
Group {
|
2022-07-11 17:44:49 +00:00
|
|
|
if player.playbackMode == .related {
|
|
|
|
autoplaying
|
|
|
|
}
|
2021-10-23 10:13:05 +00:00
|
|
|
playingNext
|
2022-09-01 23:05:41 +00:00
|
|
|
if sidebarQueue {
|
2021-11-03 23:00:17 +00:00
|
|
|
related
|
|
|
|
}
|
2021-10-23 10:13:05 +00:00
|
|
|
}
|
2022-07-10 17:51:46 +00:00
|
|
|
.listRowBackground(Color.clear)
|
2021-11-02 23:02:02 +00:00
|
|
|
#if !os(iOS)
|
2022-07-10 17:51:46 +00:00
|
|
|
.padding(.vertical, 5)
|
|
|
|
.listRowInsets(EdgeInsets())
|
2021-10-23 10:13:05 +00:00
|
|
|
#endif
|
2022-11-13 20:52:29 +00:00
|
|
|
Color.clear.padding(.bottom, 50)
|
|
|
|
.listRowBackground(Color.clear)
|
2022-11-18 21:27:13 +00:00
|
|
|
.backport
|
|
|
|
.listRowSeparator(false)
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
2022-12-13 00:50:26 +00:00
|
|
|
.environment(\.inNavigationView, false)
|
2021-10-05 20:20:09 +00:00
|
|
|
#if os(macOS)
|
2022-12-13 00:50:26 +00:00
|
|
|
.listStyle(.inset)
|
2021-10-05 20:20:09 +00:00
|
|
|
#elseif os(iOS)
|
2022-12-13 00:50:26 +00:00
|
|
|
.listStyle(.grouped)
|
|
|
|
.backport
|
|
|
|
.scrollContentBackground(false)
|
2021-10-05 20:20:09 +00:00
|
|
|
#else
|
2022-12-13 00:50:26 +00:00
|
|
|
.listStyle(.plain)
|
2021-10-05 20:20:09 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:44:49 +00:00
|
|
|
@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")
|
|
|
|
Spacer()
|
|
|
|
Button {
|
|
|
|
player.setRelatedAutoplayItem()
|
|
|
|
} label: {
|
|
|
|
Label("Find Other", systemImage: "arrow.triangle.2.circlepath.circle")
|
|
|
|
.labelStyle(.iconOnly)
|
|
|
|
}
|
|
|
|
.disabled(player.currentItem.isNil)
|
|
|
|
.buttonStyle(.plain)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-05 20:20:09 +00:00
|
|
|
var playingNext: some View {
|
2022-07-11 17:44:49 +00:00
|
|
|
Section(header: Text("Queue")) {
|
2021-10-05 20:20:09 +00:00
|
|
|
if player.queue.isEmpty {
|
2022-07-11 17:44:49 +00:00
|
|
|
Text("Queue is empty")
|
2021-10-05 20:20:09 +00:00
|
|
|
.foregroundColor(.secondary)
|
|
|
|
}
|
|
|
|
|
|
|
|
ForEach(player.queue) { item in
|
2022-12-13 19:15:22 +00:00
|
|
|
PlayerQueueRow(item: item)
|
2021-10-05 20:20:09 +00:00
|
|
|
.contextMenu {
|
2022-08-14 17:01:22 +00:00
|
|
|
if let video = item.video {
|
|
|
|
VideoContextMenuView(video: video)
|
2022-12-19 09:48:30 +00:00
|
|
|
.environment(\.inQueueListing, true)
|
2022-08-14 17:01:22 +00:00
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-26 21:14:46 +00:00
|
|
|
private var visibleWatches: [Watch] {
|
|
|
|
watches.filter { $0.videoID != player.currentVideo?.videoID }
|
|
|
|
}
|
|
|
|
|
2022-08-25 17:09:55 +00:00
|
|
|
@ViewBuilder private var related: some View {
|
|
|
|
if let related = player.currentVideo?.related, !related.isEmpty {
|
|
|
|
Section(header: Text("Related")) {
|
|
|
|
ForEach(related) { video in
|
2022-12-13 19:15:22 +00:00
|
|
|
PlayerQueueRow(item: PlayerQueueItem(video))
|
2022-08-25 17:09:55 +00:00
|
|
|
.contextMenu {
|
|
|
|
VideoContextMenuView(video: video)
|
|
|
|
}
|
|
|
|
.id(video.videoID)
|
2021-11-02 23:02:02 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-25 17:09:55 +00:00
|
|
|
.transaction { t in t.disablesAnimations = true }
|
2021-11-02 23:02:02 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct PlayerQueueView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
VStack {
|
2022-12-18 23:09:54 +00:00
|
|
|
PlayerQueueView(sidebarQueue: true)
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
.injectFixtureEnvironmentObjects()
|
|
|
|
}
|
|
|
|
}
|