Version one on the App Store
This commit is contained in:
@@ -9,7 +9,6 @@ import SwiftUI
|
||||
|
||||
struct AlbumDetailView: View {
|
||||
@Environment(MAService.self) private var service
|
||||
@Environment(\.audioPlayer) private var audioPlayer
|
||||
let album: MAAlbum
|
||||
|
||||
@State private var tracks: [MAMediaItem] = []
|
||||
@@ -18,39 +17,86 @@ struct AlbumDetailView: View {
|
||||
@State private var showError = false
|
||||
@State private var showPlayerPicker = false
|
||||
@State private var selectedPlayer: MAPlayer?
|
||||
@State private var kenBurnsScale: CGFloat = 1.0
|
||||
@State private var completeAlbum: MAAlbum?
|
||||
@State private var albumDescription: String?
|
||||
@State private var isDescriptionExpanded = false
|
||||
|
||||
private var players: [MAPlayer] {
|
||||
Array(service.playerManager.players.values).sorted { $0.name < $1.name }
|
||||
Array(service.playerManager.players.values)
|
||||
.filter { $0.available }
|
||||
.sorted { $0.name < $1.name }
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
VStack(spacing: 24) {
|
||||
// Album Header
|
||||
albumHeader
|
||||
|
||||
// Play Button
|
||||
playButton
|
||||
|
||||
Divider()
|
||||
|
||||
// Tracklist
|
||||
if isLoading {
|
||||
ProgressView()
|
||||
.padding()
|
||||
} else if tracks.isEmpty {
|
||||
Text("No tracks found")
|
||||
.foregroundStyle(.secondary)
|
||||
.padding()
|
||||
} else {
|
||||
trackList
|
||||
ZStack {
|
||||
// Blurred Background with Ken Burns Effect
|
||||
backgroundArtwork
|
||||
|
||||
// Content
|
||||
ScrollView {
|
||||
VStack(spacing: 24) {
|
||||
// Album Header
|
||||
albumHeader
|
||||
|
||||
// Play Button
|
||||
playButton
|
||||
|
||||
Divider()
|
||||
.background(Color.white.opacity(0.3))
|
||||
|
||||
// Album description
|
||||
if let albumDescription {
|
||||
descriptionSection(albumDescription)
|
||||
}
|
||||
|
||||
// Tracklist
|
||||
if isLoading {
|
||||
ProgressView()
|
||||
.padding()
|
||||
.tint(.white)
|
||||
} else if tracks.isEmpty {
|
||||
Text("No tracks found")
|
||||
.foregroundStyle(.white.opacity(0.7))
|
||||
.padding()
|
||||
} else {
|
||||
trackList
|
||||
}
|
||||
|
||||
// Show when the album came from a provider-specific URI and the
|
||||
// full library version is available
|
||||
if let completeAlbum {
|
||||
NavigationLink(value: completeAlbum) {
|
||||
Label("Show complete album", systemImage: "music.note.list")
|
||||
.font(.subheadline.bold())
|
||||
.foregroundStyle(.white.opacity(0.85))
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding()
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 12)
|
||||
.fill(Color.white.opacity(0.1))
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 12)
|
||||
.stroke(Color.white.opacity(0.2), lineWidth: 1)
|
||||
)
|
||||
)
|
||||
}
|
||||
.padding(.horizontal)
|
||||
.padding(.bottom, 8)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationTitle(album.name)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbarColorScheme(.dark, for: .navigationBar)
|
||||
.task {
|
||||
await loadTracks()
|
||||
async let tracksLoad: () = loadTracks()
|
||||
async let detailLoad: () = loadAlbumDetail()
|
||||
_ = await (tracksLoad, detailLoad)
|
||||
withAnimation(.linear(duration: 20).repeatForever(autoreverses: true)) {
|
||||
kenBurnsScale = 1.15
|
||||
}
|
||||
}
|
||||
.alert("Error", isPresented: $showError) {
|
||||
Button("OK", role: .cancel) { }
|
||||
@@ -62,76 +108,105 @@ struct AlbumDetailView: View {
|
||||
.sheet(isPresented: $showPlayerPicker) {
|
||||
EnhancedPlayerPickerView(
|
||||
players: players,
|
||||
supportsLocalPlayback: audioPlayer != nil,
|
||||
onSelect: { selection in
|
||||
Task {
|
||||
switch selection {
|
||||
case .localPlayer:
|
||||
await playOnLocalPlayer()
|
||||
case .remotePlayer(let player):
|
||||
await playAlbum(on: player)
|
||||
}
|
||||
}
|
||||
onSelect: { player in
|
||||
Task { await playAlbum(on: player) }
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Background Artwork
|
||||
|
||||
@ViewBuilder
|
||||
private var backgroundArtwork: some View {
|
||||
GeometryReader { geometry in
|
||||
CachedAsyncImage(url: service.imageProxyURL(path: album.imageUrl, provider: album.imageProvider, size: 512)) { image in
|
||||
image
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
.frame(width: geometry.size.width, height: geometry.size.height)
|
||||
.scaleEffect(kenBurnsScale)
|
||||
.blur(radius: 50)
|
||||
.overlay {
|
||||
// Dark gradient overlay for better text contrast
|
||||
LinearGradient(
|
||||
colors: [
|
||||
Color.black.opacity(0.7),
|
||||
Color.black.opacity(0.5),
|
||||
Color.black.opacity(0.7)
|
||||
],
|
||||
startPoint: .top,
|
||||
endPoint: .bottom
|
||||
)
|
||||
}
|
||||
.clipped()
|
||||
} placeholder: {
|
||||
Rectangle()
|
||||
.fill(
|
||||
LinearGradient(
|
||||
colors: [Color(.systemGray6), Color(.systemGray5)],
|
||||
startPoint: .topLeading,
|
||||
endPoint: .bottomTrailing
|
||||
)
|
||||
)
|
||||
.overlay {
|
||||
Color.black.opacity(0.6)
|
||||
}
|
||||
}
|
||||
}
|
||||
.ignoresSafeArea()
|
||||
}
|
||||
|
||||
// MARK: - Album Header
|
||||
|
||||
@ViewBuilder
|
||||
private var albumHeader: some View {
|
||||
VStack(spacing: 16) {
|
||||
// Cover Art
|
||||
if let imageUrl = album.imageUrl {
|
||||
let coverURL = service.imageProxyURL(path: imageUrl, size: 512)
|
||||
|
||||
CachedAsyncImage(url: coverURL) { image in
|
||||
image
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
} placeholder: {
|
||||
Rectangle()
|
||||
.fill(Color.gray.opacity(0.2))
|
||||
}
|
||||
.frame(width: 250, height: 250)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 12))
|
||||
.shadow(radius: 10)
|
||||
} else {
|
||||
CachedAsyncImage(url: service.imageProxyURL(path: album.imageUrl, provider: album.imageProvider, size: 512)) { image in
|
||||
image
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
} placeholder: {
|
||||
RoundedRectangle(cornerRadius: 12)
|
||||
.fill(Color.gray.opacity(0.2))
|
||||
.frame(width: 250, height: 250)
|
||||
.fill(Color.white.opacity(0.1))
|
||||
.overlay {
|
||||
Image(systemName: "opticaldisc")
|
||||
.font(.system(size: 60))
|
||||
.foregroundStyle(.secondary)
|
||||
.foregroundStyle(.white.opacity(0.5))
|
||||
}
|
||||
}
|
||||
.frame(width: 250, height: 250)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 12))
|
||||
.shadow(color: .black.opacity(0.5), radius: 20, y: 10)
|
||||
|
||||
// Album Info
|
||||
VStack(spacing: 8) {
|
||||
if let artists = album.artists, !artists.isEmpty {
|
||||
Text(artists.map { $0.name }.joined(separator: ", "))
|
||||
.font(.title3)
|
||||
.foregroundStyle(.secondary)
|
||||
.fontWeight(.semibold)
|
||||
.foregroundStyle(.white)
|
||||
.multilineTextAlignment(.center)
|
||||
.shadow(color: .black.opacity(0.3), radius: 2, x: 0, y: 1)
|
||||
}
|
||||
|
||||
HStack {
|
||||
if let year = album.year {
|
||||
Text(String(year))
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(.tertiary)
|
||||
.foregroundStyle(.white.opacity(0.8))
|
||||
}
|
||||
|
||||
if !tracks.isEmpty {
|
||||
Text("•")
|
||||
.foregroundStyle(.tertiary)
|
||||
.foregroundStyle(.white.opacity(0.8))
|
||||
Text("\(tracks.count) tracks")
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(.tertiary)
|
||||
.foregroundStyle(.white.opacity(0.8))
|
||||
}
|
||||
}
|
||||
.shadow(color: .black.opacity(0.3), radius: 2, x: 0, y: 1)
|
||||
}
|
||||
.padding(.horizontal)
|
||||
}
|
||||
@@ -156,12 +231,24 @@ struct AlbumDetailView: View {
|
||||
.font(.headline)
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding()
|
||||
.background(Color.accentColor)
|
||||
.background(
|
||||
LinearGradient(
|
||||
colors: [Color.white.opacity(0.3), Color.white.opacity(0.2)],
|
||||
startPoint: .top,
|
||||
endPoint: .bottom
|
||||
)
|
||||
)
|
||||
.foregroundStyle(.white)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 12))
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 12)
|
||||
.stroke(Color.white.opacity(0.3), lineWidth: 1)
|
||||
)
|
||||
.shadow(color: .black.opacity(0.3), radius: 10, y: 5)
|
||||
}
|
||||
.padding(.horizontal)
|
||||
.disabled(tracks.isEmpty || players.isEmpty)
|
||||
.opacity((tracks.isEmpty || players.isEmpty) ? 0.5 : 1.0)
|
||||
}
|
||||
|
||||
// MARK: - Track List
|
||||
@@ -170,7 +257,7 @@ struct AlbumDetailView: View {
|
||||
private var trackList: some View {
|
||||
LazyVStack(spacing: 0) {
|
||||
ForEach(Array(tracks.enumerated()), id: \.element.id) { index, track in
|
||||
TrackRow(track: track, trackNumber: index + 1)
|
||||
TrackRow(track: track, trackNumber: index + 1, useLightTheme: true)
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
if players.count == 1 {
|
||||
@@ -184,31 +271,95 @@ struct AlbumDetailView: View {
|
||||
|
||||
if index < tracks.count - 1 {
|
||||
Divider()
|
||||
.background(Color.white.opacity(0.2))
|
||||
.padding(.leading, 60)
|
||||
}
|
||||
}
|
||||
}
|
||||
.background(Color(.systemBackground))
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 12)
|
||||
.fill(Color.black.opacity(0.3))
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 12)
|
||||
.stroke(Color.white.opacity(0.1), lineWidth: 1)
|
||||
)
|
||||
)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 12))
|
||||
.padding(.horizontal)
|
||||
.padding(.bottom, 24)
|
||||
}
|
||||
|
||||
// MARK: - Description Section
|
||||
|
||||
@ViewBuilder
|
||||
private func descriptionSection(_ text: String) -> some View {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
Text("About")
|
||||
.font(.title2.bold())
|
||||
.foregroundStyle(.white)
|
||||
.shadow(color: .black.opacity(0.3), radius: 2, x: 0, y: 1)
|
||||
|
||||
Text(verbatim: text)
|
||||
.font(.body)
|
||||
.foregroundStyle(.white.opacity(0.85))
|
||||
.lineLimit(isDescriptionExpanded ? nil : 4)
|
||||
.lineSpacing(3)
|
||||
|
||||
Button {
|
||||
withAnimation(.easeInOut(duration: 0.25)) {
|
||||
isDescriptionExpanded.toggle()
|
||||
}
|
||||
} label: {
|
||||
Text(isDescriptionExpanded ? "Show less" : "Show more")
|
||||
.font(.subheadline.bold())
|
||||
.foregroundStyle(.white.opacity(0.6))
|
||||
}
|
||||
}
|
||||
.padding(.horizontal)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
private func loadTracks() async {
|
||||
print("🔵 AlbumDetailView: Loading tracks for album: \(album.name)")
|
||||
print("🔵 AlbumDetailView: Album URI: \(album.uri)")
|
||||
isLoading = true
|
||||
errorMessage = nil
|
||||
|
||||
do {
|
||||
tracks = try await service.libraryManager.getAlbumTracks(albumUri: album.uri)
|
||||
print("✅ AlbumDetailView: Loaded \(tracks.count) tracks")
|
||||
isLoading = false
|
||||
} catch {
|
||||
print("❌ AlbumDetailView: Failed to load tracks: \(error)")
|
||||
errorMessage = error.localizedDescription
|
||||
showError = true
|
||||
isLoading = false
|
||||
}
|
||||
|
||||
// If this album came from a provider-specific URI (not the full library version),
|
||||
// try to find the matching library album so we can offer a "Show complete album" link.
|
||||
if let scheme = URL(string: album.uri)?.scheme, scheme != "library" {
|
||||
completeAlbum = service.libraryManager.albums.first {
|
||||
$0.name.caseInsensitiveCompare(album.name) == .orderedSame
|
||||
&& $0.uri.hasPrefix("library://")
|
||||
&& ($0.year == album.year || album.year == nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func loadAlbumDetail() async {
|
||||
do {
|
||||
let detail = try await service.getAlbumDetail(albumUri: album.uri)
|
||||
if let desc = detail.metadata?.description, !desc.isEmpty {
|
||||
albumDescription = desc
|
||||
}
|
||||
} catch {
|
||||
// Description is optional — silently ignore if unavailable
|
||||
}
|
||||
}
|
||||
|
||||
private func playAlbum(on player: MAPlayer) async {
|
||||
do {
|
||||
try await service.playerManager.playMedia(
|
||||
@@ -221,28 +372,6 @@ struct AlbumDetailView: View {
|
||||
}
|
||||
}
|
||||
|
||||
private func playOnLocalPlayer() async {
|
||||
guard let audioPlayer else {
|
||||
errorMessage = "Local player not available"
|
||||
showError = true
|
||||
return
|
||||
}
|
||||
|
||||
do {
|
||||
// Play first track on local player
|
||||
// Note: We use "local_player" as a virtual queue ID
|
||||
if let firstTrack = tracks.first {
|
||||
try await audioPlayer.playMediaItem(
|
||||
uri: firstTrack.uri,
|
||||
queueId: "local_player"
|
||||
)
|
||||
}
|
||||
} catch {
|
||||
errorMessage = error.localizedDescription
|
||||
showError = true
|
||||
}
|
||||
}
|
||||
|
||||
private func playTrack(_ track: MAMediaItem, on player: MAPlayer) async {
|
||||
do {
|
||||
try await service.playerManager.playMedia(
|
||||
@@ -261,25 +390,27 @@ struct AlbumDetailView: View {
|
||||
struct TrackRow: View {
|
||||
let track: MAMediaItem
|
||||
let trackNumber: Int
|
||||
var useLightTheme: Bool = false
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 12) {
|
||||
// Track Number
|
||||
Text("\(trackNumber)")
|
||||
.font(.subheadline)
|
||||
.foregroundStyle(.secondary)
|
||||
.foregroundStyle(useLightTheme ? .white.opacity(0.7) : .secondary)
|
||||
.frame(width: 30, alignment: .trailing)
|
||||
|
||||
// Track Info
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(track.name)
|
||||
.font(.body)
|
||||
.foregroundStyle(useLightTheme ? .white : .primary)
|
||||
.lineLimit(1)
|
||||
|
||||
if let artists = track.artists, !artists.isEmpty {
|
||||
Text(artists.map { $0.name }.joined(separator: ", "))
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
.foregroundStyle(useLightTheme ? .white.opacity(0.7) : .secondary)
|
||||
.lineLimit(1)
|
||||
}
|
||||
}
|
||||
@@ -290,7 +421,7 @@ struct TrackRow: View {
|
||||
if let duration = track.duration {
|
||||
Text(formatDuration(duration))
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
.foregroundStyle(useLightTheme ? .white.opacity(0.7) : .secondary)
|
||||
}
|
||||
}
|
||||
.padding(.vertical, 8)
|
||||
|
||||
Reference in New Issue
Block a user