Queue mgmt, Podcast support, Favorites section.

This commit is contained in:
2026-04-08 10:26:50 +02:00
parent f55b7e478b
commit d7e7bef83f
14 changed files with 1177 additions and 60 deletions
+149 -53
View File
@@ -12,6 +12,7 @@ struct PlayerQueueView: View {
let playerId: String
@State private var isLoading = false
@State private var showClearConfirm = false
private var queueItems: [MAQueueItem] {
service.playerManager.queues[playerId] ?? []
@@ -25,63 +26,36 @@ struct PlayerQueueView: View {
service.playerManager.playerQueues[playerId]?.currentItem?.queueItemId
}
private var shuffleEnabled: Bool {
service.playerManager.playerQueues[playerId]?.shuffleEnabled ?? false
}
private var repeatMode: RepeatMode {
service.playerManager.playerQueues[playerId]?.repeatMode ?? .off
}
var body: some View {
Group {
VStack(spacing: 0) {
// Control buttons
controlBar
.padding(.horizontal, 16)
.padding(.vertical, 10)
Divider()
// Queue list
if isLoading && queueItems.isEmpty {
VStack {
Spacer()
ProgressView()
Spacer()
}
Spacer()
ProgressView()
Spacer()
} else if queueItems.isEmpty {
VStack {
Spacer()
Text("Queue is empty")
.font(.subheadline)
.foregroundStyle(.secondary)
Spacer()
}
Spacer()
Text("Queue is empty")
.font(.subheadline)
.foregroundStyle(.secondary)
Spacer()
} else {
ScrollViewReader { proxy in
ScrollView {
LazyVStack(spacing: 0) {
ForEach(Array(queueItems.enumerated()), id: \.element.id) { index, item in
let isCurrent = currentIndex == index
|| item.queueItemId == currentItemId
QueueItemRow(item: item, isCurrent: isCurrent)
.id(item.queueItemId)
.contentShape(Rectangle())
.onTapGesture {
Task {
try? await service.playerManager.playIndex(
playerId: playerId,
index: index
)
}
}
if index < queueItems.count - 1 {
Divider()
.padding(.leading, 76)
}
}
}
.padding(.bottom, 8)
}
.onAppear {
if let id = currentItemId {
proxy.scrollTo(id, anchor: .center)
}
}
.onChange(of: currentItemId) { _, newId in
if let newId {
withAnimation {
proxy.scrollTo(newId, anchor: .center)
}
}
}
}
queueList
}
}
.task {
@@ -89,6 +63,128 @@ struct PlayerQueueView: View {
try? await service.playerManager.loadQueue(playerId: playerId)
isLoading = false
}
.confirmationDialog("Clear the entire queue?", isPresented: $showClearConfirm, titleVisibility: .visible) {
Button("Clear Queue", role: .destructive) {
Task { try? await service.playerManager.clearQueue(playerId: playerId) }
}
Button("Cancel", role: .cancel) { }
}
}
// MARK: - Control Bar
@ViewBuilder
private var controlBar: some View {
HStack(spacing: 0) {
// Shuffle
Button {
Task { try? await service.playerManager.setShuffle(playerId: playerId, enabled: !shuffleEnabled) }
} label: {
VStack(spacing: 3) {
Image(systemName: "shuffle")
.font(.system(size: 20))
.foregroundStyle(shuffleEnabled ? Color.accentColor : .secondary)
Text("Shuffle")
.font(.caption2)
.foregroundStyle(shuffleEnabled ? Color.accentColor : .secondary)
}
.frame(maxWidth: .infinity)
}
.buttonStyle(.plain)
// Repeat
Button {
let next: RepeatMode
switch repeatMode {
case .off: next = .all
case .all: next = .one
case .one: next = .off
}
Task { try? await service.playerManager.setRepeatMode(playerId: playerId, mode: next) }
} label: {
VStack(spacing: 3) {
Image(systemName: repeatMode == .one ? "repeat.1" : "repeat")
.font(.system(size: 20))
.foregroundStyle(repeatMode == .off ? .secondary : Color.accentColor)
Text(repeatMode == .off ? "Repeat" : (repeatMode == .one ? "Repeat 1" : "Repeat All"))
.font(.caption2)
.foregroundStyle(repeatMode == .off ? .secondary : Color.accentColor)
}
.frame(maxWidth: .infinity)
}
.buttonStyle(.plain)
// Clear queue
Button {
showClearConfirm = true
} label: {
VStack(spacing: 3) {
Image(systemName: "xmark.bin")
.font(.system(size: 20))
.foregroundStyle(.secondary)
Text("Clear")
.font(.caption2)
.foregroundStyle(.secondary)
}
.frame(maxWidth: .infinity)
}
.buttonStyle(.plain)
.disabled(queueItems.isEmpty)
.opacity(queueItems.isEmpty ? 0.4 : 1.0)
}
}
// MARK: - Queue List
@ViewBuilder
private var queueList: some View {
ScrollViewReader { proxy in
List {
ForEach(Array(queueItems.enumerated()), id: \.element.id) { index, item in
let isCurrent = currentIndex == index || item.queueItemId == currentItemId
QueueItemRow(item: item, isCurrent: isCurrent)
.id(item.queueItemId)
.listRowInsets(EdgeInsets())
.listRowSeparator(.hidden)
.contentShape(Rectangle())
.onTapGesture {
Task {
try? await service.playerManager.playIndex(
playerId: playerId,
index: index
)
}
}
}
.onMove { source, destination in
guard let from = source.first else { return }
let posShift = destination > from ? destination - from - 1 : destination - from
guard posShift != 0 else { return }
let itemId = queueItems[from].queueItemId
Task {
try? await service.playerManager.moveQueueItem(
playerId: playerId,
queueItemId: itemId,
posShift: posShift
)
}
}
}
.listStyle(.plain)
.environment(\.editMode, .constant(.active))
.onAppear {
if let id = currentItemId {
proxy.scrollTo(id, anchor: .center)
}
}
.onChange(of: currentItemId) { _, newId in
if let newId {
withAnimation {
proxy.scrollTo(newId, anchor: .center)
}
}
}
}
}
}