mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Watch next improvements, clear queue buttons
This commit is contained in:
@@ -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] {
|
||||
|
@@ -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(
|
||||
|
31
Shared/Views/ClearQueueButton.swift
Normal file
31
Shared/Views/ClearQueueButton.swift
Normal 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()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user