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>
|
|
|
|
|
|
|
|
@EnvironmentObject<AccountsModel> private var accounts
|
2021-10-06 01:50:09 +05:30
|
|
|
@EnvironmentObject<PlayerModel> private var player
|
|
|
|
|
2021-11-06 01:27:22 +05:30
|
|
|
@Default(.saveHistory) private var saveHistory
|
2022-01-03 01:06:18 +05:30
|
|
|
@Default(.showHistoryInPlayer) private var showHistoryInPlayer
|
2021-11-06 01:27:22 +05:30
|
|
|
|
2021-10-06 01:50:09 +05:30
|
|
|
var body: some View {
|
|
|
|
List {
|
2021-10-23 15:43:05 +05:30
|
|
|
Group {
|
|
|
|
playingNext
|
2021-11-04 04:30:17 +05:30
|
|
|
if sidebarQueue {
|
|
|
|
related
|
|
|
|
}
|
2022-01-03 01:06:18 +05:30
|
|
|
if saveHistory, showHistoryInPlayer {
|
2021-11-06 01:27:22 +05:30
|
|
|
playedPreviously
|
|
|
|
}
|
2021-10-23 15:43:05 +05:30
|
|
|
}
|
2021-11-03 04:32:02 +05:30
|
|
|
#if !os(iOS)
|
2021-11-08 21:59:35 +05:30
|
|
|
.padding(.vertical, 5)
|
|
|
|
.listRowInsets(EdgeInsets())
|
2021-10-23 15:43:05 +05:30
|
|
|
#endif
|
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)
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
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()
|
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 }
|
|
|
|
}
|
|
|
|
|
2021-10-06 01:50:09 +05:30
|
|
|
var playedPreviously: some View {
|
2021-10-23 15:43:05 +05:30
|
|
|
Group {
|
2021-12-27 02:44:46 +05:30
|
|
|
if !visibleWatches.isEmpty {
|
2021-10-23 15:43:05 +05:30
|
|
|
Section(header: Text("Played Previously")) {
|
2021-12-27 02:44:46 +05:30
|
|
|
ForEach(visibleWatches, id: \.videoID) { watch in
|
|
|
|
PlayerQueueRow(
|
|
|
|
item: PlayerQueueItem.from(watch, video: player.historyVideo(watch.videoID)),
|
|
|
|
history: true,
|
2022-06-25 22:03:35 +05:30
|
|
|
fullScreen: $fullScreen
|
2021-12-27 02:44:46 +05:30
|
|
|
)
|
|
|
|
.onAppear {
|
|
|
|
player.loadHistoryVideoDetails(watch.videoID)
|
|
|
|
}
|
|
|
|
.contextMenu {
|
|
|
|
removeHistoryButton(watch)
|
|
|
|
}
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
2021-10-23 15:43:05 +05:30
|
|
|
}
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-03 04:32:02 +05:30
|
|
|
private var related: some View {
|
|
|
|
Group {
|
|
|
|
if !player.currentVideo.isNil, !player.currentVideo!.related.isEmpty {
|
|
|
|
Section(header: Text("Related")) {
|
|
|
|
ForEach(player.currentVideo!.related) { video in
|
2022-06-25 22:03:35 +05:30
|
|
|
PlayerQueueRow(item: PlayerQueueItem(video), fullScreen: $fullScreen)
|
2021-11-03 04:32:02 +05:30
|
|
|
.contextMenu {
|
2021-12-19 22:48:33 +05:30
|
|
|
Button {
|
2021-11-03 04:32:02 +05:30
|
|
|
player.playNext(video)
|
2021-12-19 22:48:33 +05:30
|
|
|
} label: {
|
|
|
|
Label("Play Next", systemImage: "text.insert")
|
2021-11-03 04:32:02 +05:30
|
|
|
}
|
2021-12-19 22:48:33 +05:30
|
|
|
|
|
|
|
Button {
|
2021-11-03 04:32:02 +05:30
|
|
|
player.enqueueVideo(video)
|
2021-12-19 22:48:33 +05:30
|
|
|
} label: {
|
|
|
|
Label("Play Last", systemImage: "text.append")
|
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: {
|
|
|
|
Label("Remove", 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: {
|
|
|
|
Label("Remove All", systemImage: "trash.fill")
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
|
|
|
}
|
2021-11-28 20:07:55 +05:30
|
|
|
|
2021-12-27 02:44:46 +05:30
|
|
|
private func removeHistoryButton(_ watch: Watch) -> some View {
|
|
|
|
Button {
|
|
|
|
player.removeWatch(watch)
|
|
|
|
} label: {
|
|
|
|
Label("Remove", systemImage: "trash")
|
|
|
|
}
|
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()
|
|
|
|
}
|
|
|
|
}
|