2021-11-06 01:27:22 +05:30
|
|
|
import Defaults
|
2021-10-06 01:50:09 +05:30
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct PlayerQueueView: View {
|
2022-06-18 18:09:49 +05:30
|
|
|
var sidebarQueue: Bool
|
2022-06-25 22:03:35 +05:30
|
|
|
@Binding var fullScreen: Bool
|
2021-10-06 01:50:09 +05:30
|
|
|
|
2021-12-27 02:44:46 +05:30
|
|
|
@FetchRequest(sortDescriptors: [.init(key: "watchedAt", ascending: false)])
|
|
|
|
var watches: FetchedResults<Watch>
|
|
|
|
|
2022-11-25 02:06:05 +05:30
|
|
|
@ObservedObject private var player = PlayerModel.shared
|
2021-10-06 01:50:09 +05:30
|
|
|
|
2021-11-06 01:27:22 +05:30
|
|
|
@Default(.saveHistory) private var saveHistory
|
|
|
|
|
2021-10-06 01:50:09 +05:30
|
|
|
var body: some View {
|
|
|
|
List {
|
2021-10-23 15:43:05 +05:30
|
|
|
Group {
|
2022-07-11 23:14:49 +05:30
|
|
|
if player.playbackMode == .related {
|
|
|
|
autoplaying
|
|
|
|
}
|
2021-10-23 15:43:05 +05:30
|
|
|
playingNext
|
2022-09-02 04:35:41 +05:30
|
|
|
if sidebarQueue {
|
2021-11-04 04:30:17 +05:30
|
|
|
related
|
|
|
|
}
|
2021-10-23 15:43:05 +05:30
|
|
|
}
|
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())
|
2021-10-23 15:43:05 +05:30
|
|
|
#endif
|
2022-11-14 02:22:29 +05:30
|
|
|
Color.clear.padding(.bottom, 50)
|
|
|
|
.listRowBackground(Color.clear)
|
2022-11-19 02:57:13 +05:30
|
|
|
.backport
|
|
|
|
.listRowSeparator(false)
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
|
|
|
#if os(macOS)
|
2021-11-08 21:59:35 +05:30
|
|
|
.listStyle(.inset)
|
2021-10-06 01:50:09 +05:30
|
|
|
#elseif os(iOS)
|
2021-11-08 21:59:35 +05:30
|
|
|
.listStyle(.grouped)
|
2022-07-10 23:21:46 +05:30
|
|
|
.backport
|
|
|
|
.scrollContentBackground(false)
|
2021-10-06 01:50:09 +05:30
|
|
|
#else
|
2021-11-08 21:59:35 +05:30
|
|
|
.listStyle(.plain)
|
2021-10-06 01:50:09 +05:30
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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")
|
|
|
|
Spacer()
|
|
|
|
Button {
|
|
|
|
player.setRelatedAutoplayItem()
|
|
|
|
} label: {
|
|
|
|
Label("Find Other", systemImage: "arrow.triangle.2.circlepath.circle")
|
|
|
|
.labelStyle(.iconOnly)
|
|
|
|
}
|
|
|
|
.disabled(player.currentItem.isNil)
|
|
|
|
.buttonStyle(.plain)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-06 01:50:09 +05:30
|
|
|
var playingNext: some View {
|
2022-07-11 23:14:49 +05:30
|
|
|
Section(header: Text("Queue")) {
|
2021-10-06 01:50:09 +05:30
|
|
|
if player.queue.isEmpty {
|
2022-07-11 23:14:49 +05:30
|
|
|
Text("Queue is empty")
|
2021-10-06 01:50:09 +05:30
|
|
|
.foregroundColor(.secondary)
|
|
|
|
}
|
|
|
|
|
|
|
|
ForEach(player.queue) { item in
|
2022-06-25 22:03:35 +05:30
|
|
|
PlayerQueueRow(item: item, fullScreen: $fullScreen)
|
|
|
|
.onAppear {
|
|
|
|
player.loadQueueVideoDetails(item)
|
|
|
|
}
|
2021-10-06 01:50:09 +05:30
|
|
|
.contextMenu {
|
2021-12-27 02:44:46 +05:30
|
|
|
removeButton(item)
|
|
|
|
removeAllButton()
|
2022-08-14 22:31:22 +05:30
|
|
|
|
|
|
|
if let video = item.video {
|
|
|
|
VideoContextMenuView(video: video)
|
|
|
|
}
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-27 02:44:46 +05:30
|
|
|
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
|
|
|
|
PlayerQueueRow(item: PlayerQueueItem(video), fullScreen: $fullScreen)
|
|
|
|
.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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-27 02:44:46 +05:30
|
|
|
private func removeButton(_ item: PlayerQueueItem) -> some View {
|
2021-12-01 16:52:19 +05:30
|
|
|
Button {
|
2021-12-27 02:44:46 +05:30
|
|
|
player.remove(item)
|
2021-12-01 16:52:19 +05:30
|
|
|
} label: {
|
2022-08-14 22:31:22 +05:30
|
|
|
Label("Remove from the queue", systemImage: "trash")
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-27 02:44:46 +05:30
|
|
|
private func removeAllButton() -> some View {
|
2021-12-01 16:52:19 +05:30
|
|
|
Button {
|
2021-12-27 02:44:46 +05:30
|
|
|
player.removeQueueItems()
|
2021-12-01 16:52:19 +05:30
|
|
|
} label: {
|
2022-08-14 22:31:22 +05:30
|
|
|
Label("Clear the queue", systemImage: "trash.fill")
|
2021-12-27 02:44:46 +05:30
|
|
|
}
|
2021-11-28 20:07:55 +05:30
|
|
|
}
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
struct PlayerQueueView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
VStack {
|
2022-06-25 22:03:35 +05:30
|
|
|
PlayerQueueView(sidebarQueue: true, fullScreen: .constant(true))
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
|
|
|
.injectFixtureEnvironmentObjects()
|
|
|
|
}
|
|
|
|
}
|