Playlist delete in long-press menu, empty playlists, Edit Songs moved to ••• (build 62)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
29cc9a03d4
commit
7f4a07d846
5 files changed
+71
-29
No files matched your search
@@ -54,13 +54,13 @@ struct MediaMenu {
|
||||
playlistKey: nil, extra: [], confirmDownload: true, stemmed: stemmed(cov))
|
||||
}
|
||||
|
||||
/// [changed] hears the playlist after a rename or a new cover, so an open page can follow.
|
||||
func playlist(_ pl: Playlist, extra: [SheetAction] = [], changed: ((Playlist) -> Void)? = nil) -> [SheetAction] {
|
||||
/// [changed] hears the playlist after a rename or a new cover, so an open page can follow; [deleted] after a delete.
|
||||
func playlist(_ pl: Playlist, extra: [SheetAction] = [], changed: ((Playlist) -> Void)? = nil, deleted: (() -> Void)? = nil) -> [SheetAction] {
|
||||
let plex = g.plex
|
||||
let copy = SheetAction("Copy to Stem Playlist…", icon: "doc.on.doc") { copyToStems(pl) }
|
||||
let gr = DownloadGroup(kind: .playlist, key: pl.ratingKey, title: pl.title, subtitle: "Playlist", thumb: pl.thumb)
|
||||
return collection(pl.title, gr, { try await plex.playlistTracks(pl.ratingKey) }, playlistKey: pl.ratingKey,
|
||||
extra: [copy] + (pl.smart ? [] : playlistEdits(pl, changed)) + extra,
|
||||
extra: [copy] + (pl.smart ? [] : playlistEdits(pl, changed)) + extra + [delete(pl, deleted)],
|
||||
confirmDownload: pl.trackCount > 50)
|
||||
}
|
||||
|
||||
@@ -98,6 +98,24 @@ struct MediaMenu {
|
||||
return [rename, cover]
|
||||
}
|
||||
|
||||
private func delete(_ pl: Playlist, _ deleted: (() -> Void)?) -> SheetAction {
|
||||
let plex = g.plex
|
||||
let overlays = overlays
|
||||
let ui = ui
|
||||
return SheetAction("Delete Playlist…", icon: "trash", destructive: true) {
|
||||
overlays.confirm("Delete “\(pl.title)”?", "This removes it from the server for every app.", "Delete") {
|
||||
Task {
|
||||
do {
|
||||
try await plex.deletePlaylist(pl.ratingKey)
|
||||
ui.playlistEdits += 1
|
||||
overlays.hud("Deleted “\(pl.title)”", "trash")
|
||||
deleted?()
|
||||
} catch { overlays.hud("Couldn't delete: \(error.localizedDescription)", "exclamationmark.triangle") }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func stemPlaylist(_ pl: StemPlaylist, extra: [SheetAction] = [], onPage: Bool = false) -> [SheetAction] {
|
||||
var a = [
|
||||
SheetAction("Play Next", icon: "text.line.first.and.arrowtriangle.forward") {
|
||||
@@ -296,6 +314,29 @@ struct MediaMenu {
|
||||
}
|
||||
}
|
||||
|
||||
/// Empty playlist; asks which server first when more than one is signed in.
|
||||
func newEmptyPlaylist(onCreated: @escaping () -> Void = {}) {
|
||||
let plex = g.plex
|
||||
let servers = plex.playlistServers
|
||||
let make: (String?) -> Void = { id in
|
||||
overlays.prompt("New Playlist", "Add songs later with “Add to Playlist”.", "Create", placeholder: "Playlist name") { name in
|
||||
Task {
|
||||
do {
|
||||
_ = try await plex.createEmptyPlaylist(name, serverId: id)
|
||||
overlays.hud("Created “\(name)”")
|
||||
ui.playlistEdits += 1
|
||||
onCreated()
|
||||
} catch {
|
||||
overlays.hud("Couldn't create: \(error.localizedDescription)", "exclamationmark.triangle")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if servers.count > 1 {
|
||||
overlays.actions("Which Server?", servers.map { s in SheetAction(s.1.isEmpty ? "Server" : s.1) { make(s.0) } })
|
||||
} else { make(servers.first?.0) }
|
||||
}
|
||||
|
||||
func newPlaylist(_ tracks: [Track], onCreated: @escaping () -> Void = {}) {
|
||||
let plex = g.plex
|
||||
overlays.prompt("New Playlist", "Name it; you can add more songs later.", "Create", placeholder: "Playlist name") { name in
|
||||
|
||||
@@ -54,18 +54,16 @@ struct PlaylistsScreen: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// Plex can't hold an empty playlist, so new ones start from songs you have.
|
||||
private func newPlaylist() {
|
||||
let queue = g.playback.queue
|
||||
var acts: [SheetAction] = []
|
||||
var acts: [SheetAction] = [SheetAction("Empty Playlist…", icon: "plus") { ui.menu.newEmptyPlaylist { reload += 1 } }]
|
||||
if !queue.isEmpty {
|
||||
acts.append(SheetAction("New Playlist from Queue (\(queue.count))") { ui.menu.newPlaylist(queue.map(\.track)) { reload += 1 } })
|
||||
}
|
||||
if let now = g.playback.current?.track {
|
||||
acts.append(SheetAction("New Playlist with “\(now.title)”") { ui.menu.newPlaylist([now]) { reload += 1 } })
|
||||
}
|
||||
if acts.isEmpty { ui.overlays.hud("Play something first, or use “Add to Playlist” on any song.", "info.circle") }
|
||||
else { ui.overlays.actions("New Playlist", acts) }
|
||||
ui.overlays.actions("New Playlist", acts)
|
||||
}
|
||||
|
||||
private func newStemPlaylist() {
|
||||
@@ -159,9 +157,8 @@ struct StemPlaylistScreen: View {
|
||||
}
|
||||
.toolbar {
|
||||
ToolbarItemGroup(placement: .topBarTrailing) {
|
||||
if !editing { MoreMenu(items: moreItems(pl)) }
|
||||
if editing { Button("Done") { g.stemPlaylists.setItems(pl.id, items); editing = false }.bold() }
|
||||
else if !pl.items.isEmpty { Button("Edit") { items = pl.items; editing = true } }
|
||||
else { MoreMenu(items: moreItems(pl)) }
|
||||
}
|
||||
}
|
||||
.modifier(SplitHidesTitle())
|
||||
@@ -179,18 +176,19 @@ struct StemPlaylistScreen: View {
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.top, 8).padding(.bottom, 16)
|
||||
.padding(.bottom, 16)
|
||||
}
|
||||
|
||||
private func moreItems(_ pl: StemPlaylist) -> [SheetAction] {
|
||||
let lists = g.stemPlaylists
|
||||
let edit = pl.items.isEmpty ? [] : [SheetAction("Edit Songs", icon: "list.bullet") { items = pl.items; editing = true }]
|
||||
let rename = SheetAction("Rename…", icon: "pencil") {
|
||||
ui.overlays.prompt("Rename Stem Playlist", nil, initial: pl.title, "Save") { lists.rename(pl.id, $0) }
|
||||
}
|
||||
let mixAll = SheetAction("Set Mix for All Songs…", icon: "slider.horizontal.3") {
|
||||
ui.menu.chooseMix(pl.tracks) { m in lists.setItems(pl.id, pl.items.map { var it = $0; it.mix = MixPresets.normalized(m); return it }) }
|
||||
}
|
||||
return ui.menu.stemPlaylist(pl, extra: pl.items.isEmpty ? [rename] : [rename, mixAll], onPage: true)
|
||||
return ui.menu.stemPlaylist(pl, extra: edit + (pl.items.isEmpty ? [rename] : [rename, mixAll]), onPage: true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,12 +268,9 @@ struct PlaylistScreen: View {
|
||||
}
|
||||
.toolbar {
|
||||
ToolbarItemGroup(placement: .topBarTrailing) {
|
||||
if !editing { MoreMenu(items: moreItems(list)) }
|
||||
if !playlist.smart && !list.isEmpty {
|
||||
if saving { ProgressView() }
|
||||
else if editing { Button("Done") { commit(list) }.bold() }
|
||||
else { Button("Edit") { items = list; removed = []; editing = true } }
|
||||
}
|
||||
if saving { ProgressView() }
|
||||
else if editing { Button("Done") { commit(list) }.bold() }
|
||||
else { MoreMenu(items: moreItems(list)) }
|
||||
}
|
||||
}
|
||||
.modifier(SplitHidesTitle())
|
||||
@@ -297,7 +292,7 @@ struct PlaylistScreen: View {
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.top, 8).padding(.bottom, 16)
|
||||
.padding(.bottom, 16)
|
||||
}
|
||||
|
||||
private func removeAction(_ t: Track) -> [SheetAction] {
|
||||
@@ -311,19 +306,13 @@ struct PlaylistScreen: View {
|
||||
}
|
||||
|
||||
private func moreItems(_ list: [Track]) -> [SheetAction] {
|
||||
var extra: [SheetAction] = []
|
||||
let plex = g.plex
|
||||
let key = playlist.ratingKey
|
||||
extra.append(SheetAction("Delete Playlist", icon: "trash", destructive: true) {
|
||||
ui.overlays.confirm("Delete “\(title)”?", "This removes it from Plex for every app.", "Delete") {
|
||||
Task { if (try? await plex.deletePlaylist(key)) != nil { ui.pop() } }
|
||||
}
|
||||
})
|
||||
let extra = playlist.smart || list.isEmpty ? [] :
|
||||
[SheetAction("Edit Songs", icon: "list.bullet") { items = list; removed = []; editing = true }]
|
||||
var pl = playlist
|
||||
pl.title = title
|
||||
pl.thumb = thumb
|
||||
pl.trackCount = list.count
|
||||
return ui.menu.playlist(pl, extra: extra) { title = $0.title; thumb = $0.thumb }
|
||||
return ui.menu.playlist(pl, extra: extra, changed: { title = $0.title; thumb = $0.thumb }, deleted: { ui.pop() })
|
||||
}
|
||||
|
||||
/// Sends removals, then replays the new order as "move after" calls against a simulated server list.
|
||||
|
||||
Reference in new issue
Block a user