iOS dev 30: hide Duo swap, Library Layout in Settings, Settings width on Duo, centred stem faders, folded spacing, no folded header menu
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
29a1742f8d
commit
150e47a305
8 files changed
+130
-84
No files matched your search
@@ -10,32 +10,33 @@ struct LibraryHome: View {
|
||||
@State private var added: [Track] = []
|
||||
@State private var reload = 0
|
||||
@Environment(\.scenePhase) private var scenePhase
|
||||
@State private var editing = false
|
||||
private var g: AppGraph { .shared }
|
||||
|
||||
/// Rows in the saved order. Titles not saved yet keep their default order after the saved ones.
|
||||
private func ordered<T>(_ items: [T], _ title: (T) -> String) -> [T] {
|
||||
let saved = g.settings.libraryOrder.split(separator: "|").map(String.init)
|
||||
static func ordered<T>(_ items: [T], _ s: Settings, _ title: (T) -> String) -> [T] {
|
||||
let saved = s.libraryOrder.split(separator: "|").map(String.init)
|
||||
func rank(_ t: String) -> Int { saved.firstIndex(of: t) ?? saved.count }
|
||||
return items.enumerated().sorted { (rank(title($0.element)), $0.offset) < (rank(title($1.element)), $1.offset) }.map(\.element)
|
||||
}
|
||||
private func ordered<T>(_ items: [T], _ title: (T) -> String) -> [T] { Self.ordered(items, g.settings, title) }
|
||||
|
||||
/// Moves a row one place within its section and saves the whole order.
|
||||
private func move(_ title: String, _ by: Int, in titles: [String]) {
|
||||
guard let i = titles.firstIndex(of: title), titles.indices.contains(i + by) else { return }
|
||||
var t = titles
|
||||
t.swapAt(i, i + by)
|
||||
let saved = g.settings.libraryOrder.split(separator: "|").map(String.init)
|
||||
g.settings.libraryOrder = (t + saved.filter { !t.contains($0) }).joined(separator: "|")
|
||||
/// Moves rows within one group (Settings > Library Layout) and saves the whole order.
|
||||
static func reorder(_ group: [String], from: IndexSet, to: Int, _ s: Settings) {
|
||||
var t = ordered(group, s) { $0 }
|
||||
t.move(fromOffsets: from, toOffset: to)
|
||||
let saved = s.libraryOrder.split(separator: "|").map(String.init)
|
||||
s.libraryOrder = (t + saved.filter { !t.contains($0) }).joined(separator: "|")
|
||||
}
|
||||
|
||||
private static let sectionNames = ["Recent Plays", "Recently Added", "On This Day", "Stations", "Browse"]
|
||||
static let sectionNames = ["Recent Plays", "Recently Added", "On This Day", "Stations", "Browse"]
|
||||
static let stationNames = ["Library Radio", "Random Album Radio"]
|
||||
static let browseNames = ["Playlists", "Artists", "Albums", "Songs", "Genres", "Downloads", "Web Radio"]
|
||||
private var shownSections: [String] { ordered(Self.sectionNames) { $0 } }
|
||||
private var hiddenSections: Set<String> { Set(g.settings.libraryHidden.split(separator: "|").map(String.init)) }
|
||||
private func toggle(_ name: String) {
|
||||
var h = hiddenSections
|
||||
static func hidden(_ s: Settings) -> Set<String> { Set(s.libraryHidden.split(separator: "|").map(String.init)) }
|
||||
static func toggle(_ name: String, _ s: Settings) {
|
||||
var h = hidden(s)
|
||||
if h.contains(name) { h.remove(name) } else { h.insert(name) }
|
||||
g.settings.libraryHidden = Self.sectionNames.filter(h.contains).joined(separator: "|")
|
||||
s.libraryHidden = sectionNames.filter(h.contains).joined(separator: "|")
|
||||
}
|
||||
|
||||
@ViewBuilder private func section(_ name: String) -> some View {
|
||||
@@ -88,8 +89,7 @@ struct LibraryHome: View {
|
||||
]
|
||||
let shown = ordered(stations) { $0.1 }
|
||||
ForEach(shown, id: \.1) { st in
|
||||
LibraryRow(icon: st.0, title: st.1, last: st.1 == shown.last?.1, editing: editing,
|
||||
move: { move(st.1, $0, in: shown.map(\.1)) }) { play(st.2) }
|
||||
LibraryRow(icon: st.0, title: st.1, last: st.1 == shown.last?.1) { play(st.2) }
|
||||
}
|
||||
default:
|
||||
// Every tab except Settings (and this one).
|
||||
@@ -101,8 +101,7 @@ struct LibraryHome: View {
|
||||
]
|
||||
let shownRows = ordered(rows) { $0.1 }
|
||||
ForEach(shownRows, id: \.1) { r in
|
||||
LibraryRow(icon: r.0, title: r.1, last: r.1 == shownRows.last?.1, editing: editing,
|
||||
move: { move(r.1, $0, in: shownRows.map(\.1)) }) { ui.push(r.2) }
|
||||
LibraryRow(icon: r.0, title: r.1, last: r.1 == shownRows.last?.1) { ui.push(r.2) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,24 +118,9 @@ struct LibraryHome: View {
|
||||
}
|
||||
}
|
||||
if ready {
|
||||
ForEach(shownSections, id: \.self) { name in
|
||||
let off = hiddenSections.contains(name)
|
||||
if editing {
|
||||
SectionEditBar(title: name, off: off,
|
||||
move: { move(name, $0, in: shownSections) },
|
||||
toggle: { toggle(name) })
|
||||
}
|
||||
if !off || editing {
|
||||
section(name).opacity(off ? 0.35 : 1).allowsHitTesting(!editing || !off)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.toolbar {
|
||||
if ready {
|
||||
ToolbarItem(placement: .topBarTrailing) {
|
||||
Button(editing ? "Done" : "Reorder") { withAnimation { editing.toggle() } }
|
||||
}
|
||||
// Order and visibility are set in Settings > Library Layout.
|
||||
let off = Self.hidden(s)
|
||||
ForEach(shownSections.filter { !off.contains($0) }, id: \.self) { section($0) }
|
||||
}
|
||||
}
|
||||
.onChange(of: scenePhase) { _, ph in if ph == .active { reload += 1 } }
|
||||
@@ -226,26 +210,6 @@ private struct RecentShelf: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// Edit-mode header for a whole section: move it or switch it on/off.
|
||||
private struct SectionEditBar: View {
|
||||
let title: String
|
||||
let off: Bool
|
||||
let move: (Int) -> Void
|
||||
let toggle: () -> Void
|
||||
@Environment(\.palette) private var p
|
||||
var body: some View {
|
||||
HStack(spacing: 18) {
|
||||
Text(title).font(.headline).foregroundStyle(p.label)
|
||||
Spacer()
|
||||
Image(systemName: off ? "eye.slash" : "eye").onTapGesture { toggle() }
|
||||
Image(systemName: "chevron.up").onTapGesture { move(-1) }
|
||||
Image(systemName: "chevron.down").onTapGesture { move(1) }
|
||||
}
|
||||
.font(.system(size: 17, weight: .semibold)).foregroundStyle(p.accent)
|
||||
.padding(.horizontal, MARGIN).padding(.vertical, 10)
|
||||
.background(p.label3.opacity(0.12))
|
||||
}
|
||||
}
|
||||
|
||||
private struct LibraryRow: View {
|
||||
let icon: String
|
||||
|
||||
Reference in new issue
Block a user