Watch next improvements, clear queue buttons

This commit is contained in:
Arkadiusz Fal
2022-12-21 18:21:44 +01:00
parent 18cbbd3c90
commit c01ff56854
5 changed files with 138 additions and 71 deletions

View File

@@ -13,25 +13,29 @@ struct QueueView: View {
expanded.toggle()
}
} label: {
HStack {
HStack(spacing: 12) {
sectionLabel(label)
Spacer()
Label("Show more", systemImage: expanded ? "chevron.up" : "chevron.down")
.animation(nil, value: expanded)
.foregroundColor(.accentColor)
.imageScale(.large)
.labelStyle(.iconOnly)
.opacity(items.count > 1 ? 1 : 0)
ClearQueueButton()
if items.count > 1 {
Label("Show more", systemImage: expanded ? "chevron.up" : "chevron.down")
.animation(nil, value: expanded)
.foregroundColor(.accentColor)
.imageScale(.large)
.labelStyle(.iconOnly)
}
}
}
.buttonStyle(.plain)
ForEach(limitedItems) { item in
ContentItemView(item: .init(video: item.video))
.environment(\.listingStyle, .list)
.environment(\.inQueueListing, true)
.environment(\.noListingDividers, limit == 1)
.transition(.opacity)
LazyVStack(alignment: .leading) {
ForEach(limitedItems) { item in
ContentItemView(item: .init(video: item.video))
.environment(\.listingStyle, .list)
.environment(\.inQueueListing, true)
.environment(\.noListingDividers, limit == 1)
.transition(.opacity)
}
}
}
}
@@ -46,12 +50,12 @@ struct QueueView: View {
return "Next in Queue (\(items.count))"
}
var limitedItems: [PlayerQueueItem] {
var limitedItems: [ContentItem] {
if let limit {
return Array(items.prefix(limit))
return Array(items.prefix(limit).map(\.contentItem))
}
return items
return items.map(\.contentItem)
}
var items: [PlayerQueueItem] {

View File

@@ -11,59 +11,62 @@ struct WatchNextView: View {
var body: some View {
Group {
#if os(iOS)
NavigationView {
watchNext
.toolbar {
ToolbarItem(placement: .principal) {
watchNextMenu
}
}
}
.navigationViewStyle(.stack)
#else
VStack {
HStack {
hideCloseButton
.labelStyle(.iconOnly)
.frame(maxWidth: .infinity, alignment: .leading)
Spacer()
watchNextMenu
.frame(maxWidth: .infinity)
Spacer()
HStack {
#if os(macOS)
Text("Mode")
.foregroundColor(.secondary)
#endif
playbackModeControl
HStack {
if model.isRestartable {
reopenButton
if model.isPresenting {
#if os(iOS)
NavigationView {
watchNext
.toolbar {
ToolbarItem(placement: .principal) {
watchNextMenu
}
}
}
.frame(maxWidth: .infinity, alignment: .trailing)
}
#if os(macOS)
.padding()
#endif
watchNext
}
#endif
.navigationViewStyle(.stack)
#else
VStack {
HStack {
hideCloseButton
.labelStyle(.iconOnly)
.frame(maxWidth: .infinity, alignment: .leading)
Spacer()
watchNextMenu
.frame(maxWidth: .infinity)
Spacer()
HStack {
#if os(macOS)
Text("Mode")
.foregroundColor(.secondary)
#endif
playbackModeControl
HStack {
if model.isRestartable {
reopenButton
}
}
}
.frame(maxWidth: .infinity, alignment: .trailing)
}
#if os(macOS)
.padding()
#endif
watchNext
}
#endif
}
}
.transition(.opacity)
.zIndex(0)
#if os(tvOS)
.background(Color.background(scheme: colorScheme))
.background(Color.background(scheme: colorScheme))
#else
.background(Color.background)
.background(Color.background)
#endif
.opacity(model.isPresenting ? 1 : 0)
}
var watchNext: some View {
@@ -211,6 +214,13 @@ struct WatchNextView: View {
}
}
var queueForMoreVideos: [ContentItem] {
guard !player.queue.isEmpty else { return [] }
let suffix = player.playbackMode == .queue && model.isAutoplaying && model.canAutoplay ? 1 : 0
return player.queue.suffix(from: suffix).map(\.contentItem)
}
@ViewBuilder var moreVideos: some View {
VStack(spacing: 12) {
switch model.page {
@@ -222,21 +232,27 @@ struct WatchNextView: View {
Divider()
}
let queueForMoreVideos = player.queue.isEmpty ? [] : player.queue.suffix(from: player.playbackMode == .queue && model.isAutoplaying && model.canAutoplay ? 1 : 0)
if (model.isAutoplaying && model.canAutoplay && !queueForMoreVideos.isEmpty) ||
(!model.isAutoplaying && !queueForMoreVideos.isEmpty)
{
Text("Next in queue")
.font(.headline)
.frame(maxWidth: .infinity, alignment: .leading)
HStack {
Text("Next in queue")
.font(.headline)
.frame(maxWidth: .infinity, alignment: .leading)
Spacer()
ClearQueueButton()
}
}
if !queueForMoreVideos.isEmpty {
ForEach(queueForMoreVideos) { item in
ContentItemView(item: .init(video: item.video))
.environment(\.inQueueListing, true)
.environment(\.listingStyle, .list)
LazyVStack {
ForEach(queueForMoreVideos) { item in
ContentItemView(item: item)
.environment(\.inQueueListing, true)
.environment(\.listingStyle, .list)
}
}
} else {
Label(

View File

@@ -0,0 +1,31 @@
import SwiftUI
struct ClearQueueButton: View {
private var navigation = NavigationModel.shared
var body: some View {
Button {
navigation.presentAlert(
Alert(
title: Text("Are you sure you want to clear the queue?"),
primaryButton: .destructive(Text("Clear All")) {
PlayerModel.shared.removeQueueItems()
},
secondaryButton: .cancel()
)
)
} label: {
Label("Clear Queue", systemImage: "trash")
.font(.headline)
.labelStyle(.iconOnly)
.foregroundColor(.secondary)
}
.buttonStyle(.plain)
}
}
struct ClearQueueButton_Previews: PreviewProvider {
static var previews: some View {
ClearQueueButton()
}
}