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 {
|
2021-11-03 23:00:17 +00:00
|
|
|
@Binding var sidebarQueue: Bool
|
2021-10-05 20:20:09 +00:00
|
|
|
@Binding var fullScreen: Bool
|
|
|
|
|
|
|
|
@EnvironmentObject<PlayerModel> private var player
|
|
|
|
|
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 {
|
|
|
|
playingNext
|
2021-11-03 23:00:17 +00:00
|
|
|
if sidebarQueue {
|
|
|
|
related
|
|
|
|
}
|
2021-11-05 19:57:22 +00:00
|
|
|
if saveHistory {
|
|
|
|
playedPreviously
|
|
|
|
}
|
2021-10-23 10:13:05 +00:00
|
|
|
}
|
2021-11-02 23:02:02 +00:00
|
|
|
#if !os(iOS)
|
2021-11-08 16:29:35 +00:00
|
|
|
.padding(.vertical, 5)
|
|
|
|
.listRowInsets(EdgeInsets())
|
2021-10-23 10:13:05 +00:00
|
|
|
#endif
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if os(macOS)
|
2021-11-08 16:29:35 +00:00
|
|
|
.listStyle(.inset)
|
2021-10-05 20:20:09 +00:00
|
|
|
#elseif os(iOS)
|
2021-11-08 16:29:35 +00:00
|
|
|
.listStyle(.grouped)
|
2021-10-05 20:20:09 +00:00
|
|
|
#else
|
2021-11-08 16:29:35 +00:00
|
|
|
.listStyle(.plain)
|
2021-10-05 20:20:09 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
var playingNext: some View {
|
|
|
|
Section(header: Text("Playing Next")) {
|
|
|
|
if player.queue.isEmpty {
|
|
|
|
Text("Playback queue is empty")
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
}
|
|
|
|
|
|
|
|
ForEach(player.queue) { item in
|
2021-12-01 11:22:19 +00:00
|
|
|
PlayerQueueRow(item: item, fullScreen: $fullScreen)
|
2021-10-05 20:20:09 +00:00
|
|
|
.contextMenu {
|
|
|
|
removeButton(item, history: false)
|
|
|
|
removeAllButton(history: false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var playedPreviously: some View {
|
2021-10-23 10:13:05 +00:00
|
|
|
Group {
|
|
|
|
if !player.history.isEmpty {
|
|
|
|
Section(header: Text("Played Previously")) {
|
|
|
|
ForEach(player.history) { item in
|
2021-12-01 11:22:19 +00:00
|
|
|
PlayerQueueRow(item: item, history: true, fullScreen: $fullScreen)
|
2021-10-23 10:13:05 +00:00
|
|
|
.contextMenu {
|
|
|
|
removeButton(item, history: true)
|
|
|
|
removeAllButton(history: true)
|
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
2021-10-23 10:13:05 +00:00
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-02 23:02:02 +00:00
|
|
|
private var related: some View {
|
|
|
|
Group {
|
|
|
|
if !player.currentVideo.isNil, !player.currentVideo!.related.isEmpty {
|
|
|
|
Section(header: Text("Related")) {
|
|
|
|
ForEach(player.currentVideo!.related) { video in
|
|
|
|
PlayerQueueRow(item: PlayerQueueItem(video), fullScreen: $fullScreen)
|
|
|
|
.contextMenu {
|
2021-12-19 17:18:33 +00:00
|
|
|
Button {
|
2021-11-02 23:02:02 +00:00
|
|
|
player.playNext(video)
|
2021-12-19 17:18:33 +00:00
|
|
|
} label: {
|
|
|
|
Label("Play Next", systemImage: "text.insert")
|
2021-11-02 23:02:02 +00:00
|
|
|
}
|
2021-12-19 17:18:33 +00:00
|
|
|
|
|
|
|
Button {
|
2021-11-02 23:02:02 +00:00
|
|
|
player.enqueueVideo(video)
|
2021-12-19 17:18:33 +00:00
|
|
|
} label: {
|
|
|
|
Label("Play Last", systemImage: "text.append")
|
2021-11-02 23:02:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func removeButton(_ item: PlayerQueueItem, history: Bool) -> some View {
|
2021-12-01 11:22:19 +00:00
|
|
|
Button {
|
|
|
|
removeButtonAction(item, history: history)
|
|
|
|
} label: {
|
|
|
|
Label("Remove", systemImage: "trash")
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-28 14:37:55 +00:00
|
|
|
private func removeButtonAction(_ item: PlayerQueueItem, history: Bool) {
|
|
|
|
_ = history ? player.removeHistory(item) : player.remove(item)
|
|
|
|
}
|
|
|
|
|
2021-11-02 23:02:02 +00:00
|
|
|
private func removeAllButton(history: Bool) -> some View {
|
2021-12-01 11:22:19 +00:00
|
|
|
Button {
|
|
|
|
removeAllButtonAction(history: history)
|
|
|
|
} label: {
|
|
|
|
Label("Remove All", systemImage: "trash.fill")
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-28 14:37:55 +00:00
|
|
|
|
|
|
|
private func removeAllButtonAction(history: Bool) {
|
|
|
|
_ = history ? player.removeHistoryItems() : player.removeQueueItems()
|
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct PlayerQueueView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
VStack {
|
2021-11-03 23:00:17 +00:00
|
|
|
PlayerQueueView(sidebarQueue: .constant(true), fullScreen: .constant(true))
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
.injectFixtureEnvironmentObjects()
|
|
|
|
}
|
|
|
|
}
|