2022-12-18 04:38:30 +05:30
|
|
|
import Defaults
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct WatchNextView: View {
|
|
|
|
@ObservedObject private var model = WatchNextViewModel.shared
|
|
|
|
@ObservedObject private var player = PlayerModel.shared
|
|
|
|
|
|
|
|
@Default(.saveHistory) private var saveHistory
|
|
|
|
|
|
|
|
@Environment(\.colorScheme) private var colorScheme
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
Group {
|
|
|
|
#if os(iOS)
|
|
|
|
NavigationView {
|
|
|
|
watchNext
|
2022-12-19 00:09:03 +05:30
|
|
|
.toolbar {
|
|
|
|
ToolbarItem(placement: .principal) {
|
|
|
|
watchNextMenu
|
|
|
|
}
|
|
|
|
}
|
2022-12-18 04:38:30 +05:30
|
|
|
}
|
|
|
|
#else
|
|
|
|
VStack {
|
|
|
|
HStack {
|
2022-12-19 00:09:03 +05:30
|
|
|
hideCloseButton
|
|
|
|
.labelStyle(.iconOnly)
|
|
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
|
|
|
|
watchNextMenu
|
|
|
|
.frame(maxWidth: .infinity)
|
|
|
|
|
2022-12-18 04:38:30 +05:30
|
|
|
Spacer()
|
2022-12-19 00:09:03 +05:30
|
|
|
|
|
|
|
HStack {
|
|
|
|
if model.isRestartable {
|
|
|
|
reopenButton
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.frame(maxWidth: .infinity, alignment: .trailing)
|
2022-12-18 04:38:30 +05:30
|
|
|
}
|
2022-12-19 00:09:03 +05:30
|
|
|
#if os(macOS)
|
2022-12-18 04:38:30 +05:30
|
|
|
.padding()
|
2022-12-19 00:09:03 +05:30
|
|
|
#endif
|
2022-12-18 04:38:30 +05:30
|
|
|
watchNext
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#if os(tvOS)
|
|
|
|
.background(Color.background(scheme: colorScheme))
|
|
|
|
#else
|
|
|
|
.background(Color.background)
|
|
|
|
#endif
|
2022-12-19 00:09:03 +05:30
|
|
|
.opacity(model.isPresenting ? 1 : 0)
|
2022-12-18 04:38:30 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
var watchNext: some View {
|
|
|
|
ScrollView {
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
if model.isAutoplaying,
|
2022-12-19 00:09:03 +05:30
|
|
|
let item = model.nextFromTheQueue
|
2022-12-18 04:38:30 +05:30
|
|
|
{
|
|
|
|
HStack {
|
2022-12-19 00:09:03 +05:30
|
|
|
Text("Playing Next in \(Int(model.countdown.rounded()))...")
|
|
|
|
.font(.headline.monospacedDigit())
|
2022-12-18 04:38:30 +05:30
|
|
|
Spacer()
|
|
|
|
|
|
|
|
Button {
|
2022-12-19 00:09:03 +05:30
|
|
|
model.keepFromAutoplaying()
|
2022-12-18 04:38:30 +05:30
|
|
|
} label: {
|
2022-12-19 00:09:03 +05:30
|
|
|
Label("Cancel", systemImage: "pause.fill")
|
|
|
|
#if os(iOS)
|
|
|
|
.imageScale(.large)
|
|
|
|
.padding([.vertical, .leading])
|
|
|
|
.font(.headline.bold())
|
|
|
|
#endif
|
2022-12-18 04:38:30 +05:30
|
|
|
}
|
|
|
|
}
|
2022-12-19 00:09:03 +05:30
|
|
|
#if os(tvOS)
|
|
|
|
.padding(.top, 10)
|
|
|
|
#endif
|
2022-12-18 04:38:30 +05:30
|
|
|
|
|
|
|
PlayerQueueRow(item: item)
|
|
|
|
}
|
2022-12-19 00:09:03 +05:30
|
|
|
|
2022-12-18 04:38:30 +05:30
|
|
|
moreVideos
|
2022-12-19 00:09:03 +05:30
|
|
|
.padding(.top, 15)
|
2022-12-18 04:38:30 +05:30
|
|
|
}
|
|
|
|
.padding(.horizontal)
|
|
|
|
}
|
2022-12-18 17:41:06 +05:30
|
|
|
#if os(iOS)
|
2022-12-18 04:38:30 +05:30
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
2022-12-18 17:41:06 +05:30
|
|
|
#endif
|
2022-12-18 04:38:30 +05:30
|
|
|
#if !os(macOS)
|
2022-12-19 00:09:03 +05:30
|
|
|
.navigationTitle(model.page.title)
|
|
|
|
.toolbar {
|
|
|
|
ToolbarItem(placement: .cancellationAction) {
|
|
|
|
hideCloseButton
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolbarItem(placement: .primaryAction) {
|
|
|
|
reopenButton
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2022-12-18 04:38:30 +05:30
|
|
|
|
2022-12-19 00:09:03 +05:30
|
|
|
var watchNextMenu: some View {
|
|
|
|
#if os(tvOS)
|
|
|
|
Button {
|
|
|
|
model.page = model.page.next()
|
|
|
|
} label: {
|
|
|
|
menuLabel
|
|
|
|
}
|
|
|
|
#elseif os(macOS)
|
|
|
|
pagePicker
|
|
|
|
.modifier(SettingsPickerModifier())
|
|
|
|
#if os(macOS)
|
|
|
|
.frame(maxWidth: 150)
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
Menu {
|
|
|
|
pagePicker
|
|
|
|
} label: {
|
|
|
|
HStack(spacing: 12) {
|
|
|
|
menuLabel
|
|
|
|
.foregroundColor(.primary)
|
|
|
|
|
|
|
|
Image(systemName: "chevron.down.circle.fill")
|
|
|
|
.foregroundColor(.accentColor)
|
|
|
|
.imageScale(.small)
|
2022-12-18 04:38:30 +05:30
|
|
|
}
|
2022-12-19 00:09:03 +05:30
|
|
|
.transaction { t in t.animation = nil }
|
2022-12-18 04:38:30 +05:30
|
|
|
}
|
2022-12-19 00:09:03 +05:30
|
|
|
|
2022-12-18 04:38:30 +05:30
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-12-19 00:09:03 +05:30
|
|
|
var menuLabel: some View {
|
|
|
|
HStack {
|
|
|
|
Image(systemName: model.page.systemImageName)
|
|
|
|
.imageScale(.small)
|
|
|
|
Text(model.page.title)
|
|
|
|
.font(.headline)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var pagePicker: some View {
|
|
|
|
Picker("Page", selection: $model.page) {
|
|
|
|
ForEach(WatchNextViewModel.Page.allCases, id: \.rawValue) { page in
|
|
|
|
Label(page.title, systemImage: page.systemImageName)
|
|
|
|
.tag(page)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder var hideCloseButton: some View {
|
|
|
|
if model.isHideable {
|
|
|
|
hideButton
|
|
|
|
} else {
|
|
|
|
closeButton
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var hideButton: some View {
|
|
|
|
Button {
|
|
|
|
model.hide()
|
|
|
|
} label: {
|
|
|
|
Label("Hide", systemImage: "chevron.down")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-18 04:38:30 +05:30
|
|
|
var closeButton: some View {
|
|
|
|
Button {
|
2022-12-19 00:09:03 +05:30
|
|
|
model.close()
|
2022-12-18 04:38:30 +05:30
|
|
|
} label: {
|
|
|
|
Label("Close", systemImage: "xmark")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder var reopenButton: some View {
|
2022-12-19 00:09:03 +05:30
|
|
|
if model.isRestartable {
|
2022-12-18 04:38:30 +05:30
|
|
|
Button {
|
2022-12-19 00:09:03 +05:30
|
|
|
model.restart()
|
2022-12-18 04:38:30 +05:30
|
|
|
} label: {
|
2022-12-19 00:09:03 +05:30
|
|
|
Label(model.reason == .userInteracted ? "Back" : "Reopen", systemImage: "arrow.counterclockwise")
|
2022-12-18 04:38:30 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder var moreVideos: some View {
|
|
|
|
VStack(spacing: 12) {
|
2022-12-19 00:09:03 +05:30
|
|
|
switch model.page {
|
|
|
|
case .queue:
|
|
|
|
let queueForMoreVideos = player.queue.isEmpty ? [] : player.queue.suffix(from: model.isAutoplaying ? 1 : 0)
|
|
|
|
if !queueForMoreVideos.isEmpty {
|
2022-12-18 04:38:30 +05:30
|
|
|
ForEach(queueForMoreVideos) { item in
|
2022-12-19 04:39:54 +05:30
|
|
|
ContentItemView(item: .init(video: item.video))
|
|
|
|
.environment(\.inQueueListing, true)
|
|
|
|
.environment(\.listingStyle, .list)
|
2022-12-19 00:09:03 +05:30
|
|
|
}
|
|
|
|
} else if player.playbackMode != .related && player.playbackMode != .loopOne {
|
|
|
|
Label(
|
|
|
|
model.isAutoplaying ? "Nothing more in the queue" : "Queue is empty",
|
|
|
|
systemImage: WatchNextViewModel.Page.queue.systemImageName
|
|
|
|
)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
}
|
|
|
|
case .related:
|
|
|
|
if let item = model.item {
|
2022-12-18 04:38:30 +05:30
|
|
|
ForEach(item.video.related) { video in
|
|
|
|
ContentItemView(item: .init(video: video))
|
|
|
|
.environment(\.listingStyle, .list)
|
|
|
|
}
|
2022-12-19 00:09:03 +05:30
|
|
|
} else {
|
|
|
|
Label("Nothing was played",
|
|
|
|
systemImage: WatchNextViewModel.Page.related.systemImageName)
|
|
|
|
.foregroundColor(.secondary)
|
2022-12-18 04:38:30 +05:30
|
|
|
}
|
2022-12-19 00:09:03 +05:30
|
|
|
case .history:
|
|
|
|
if saveHistory {
|
2022-12-18 04:38:30 +05:30
|
|
|
HistoryView(limit: 15)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-19 00:09:03 +05:30
|
|
|
struct WatchNextView_Previews: PreviewProvider {
|
2022-12-18 04:38:30 +05:30
|
|
|
static var previews: some View {
|
|
|
|
WatchNextView()
|
|
|
|
.onAppear {
|
2022-12-19 00:09:03 +05:30
|
|
|
WatchNextViewModel.shared.finishedWatching(.init(.fixture))
|
2022-12-18 04:38:30 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|