Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : SP Music9// File : Features/Albums/AlbumDetailView.swift10// Description : Album page and artist page.11// Module : Features12// Repository : https://git.spboucher.ai/sp-music-ios13// Created : 2026-11-1714// Last Modified : 2026-11-1715//16// =============================================================================17// AUTHOR & PROFESSIONAL AFFILIATION18// =============================================================================19//20// Author : Simon-Pierre Boucher21// Position : Professor of Finance22// Institution : Université du Québec en Outaouais (UQO)23// Department : Département des sciences administratives24// Organization : SP Boucher25//26// Website : https://spboucher.ai27// Git : https://git.spboucher.ai28//29// =============================================================================30// OFFICIAL CONTACT DIRECTORY31// =============================================================================32//33// General : info@spboucher.ai34// Professional : contact@spboucher.ai35// Direct : simon@spboucher.ai36// Research : research@spboucher.ai37// Development : dev@spboucher.ai38// Support : support@spboucher.ai39// Security/Admin : admin@spboucher.ai40// Notifications : notifications@spboucher.ai41//42// Preferred Contact: support@spboucher.ai43//44// =============================================================================45// COPYRIGHT & INTELLECTUAL PROPERTY46// =============================================================================47//48// Copyright (c) 202649// Simon-Pierre Boucher50//51// All rights reserved where applicable.52//53// This file is governed by the applicable project license,54// copyright notices, institutional agreements and relevant law.55//56// Unless expressly authorized by the applicable license or57// rights holder, copying, redistribution, sublicensing,58// publication and commercial exploitation are not permitted.59//60// Existing third-party rights and notices remain unaffected.61//62// =============================================================================63// CONFIDENTIALITY & SECURITY64// =============================================================================65//66// Classification : Public67// Distribution : Public repository; use is governed by the project license68// Security Contact : admin@spboucher.ai69//70// Access to this source does not independently grant permission71// to redistribute or disclose confidential materials.72//73// Do not embed credentials, private keys, access tokens,74// certificates or confidential personal information.75//76// =============================================================================77// LICENSE & MAINTENANCE78// =============================================================================79//80// License : None specified (no license file in this repository)81// Maintainer : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import SPMusicCore89import SwiftUI9091struct AlbumDetailView: View {92 @Environment(AppEnvironment.self) private var env93 let albumId: String94 @State private var album: Album?95 @State private var tracks: [Track] = []96 @State private var loaded = false97 @State private var playlistFor: Track?9899 var body: some View {100 List {101 if let album {102 header(album).listRowSeparator(.hidden).listRowBackground(Color.spBackground).listRowInsets(EdgeInsets(top: 8, leading: 16, bottom: 12, trailing: 16))103 let multiDisc = Set(tracks.map(\.discNo)).count > 1104 ForEach(Array(tracks.enumerated()), id: \.element.id) { i, t in105 if multiDisc, i == 0 || tracks[i - 1].discNo != t.discNo {106 Text("Disque \(t.discNo)").font(.subheadline.weight(.semibold)).foregroundStyle(Color.spMuted).listRowBackground(Color.spBackground).listRowSeparator(.hidden)107 }108 TrackRow(track: t, number: t.trackNo ?? i + 1, showAlbumLink: false, onAddToPlaylist: { playlistFor = $0 }) { env.play(tracks, startAt: i) }109 .listRowBackground(Color.spBackground)110 }111 footer(album).listRowSeparator(.hidden).listRowBackground(Color.spBackground)112 }113 }114 .listStyle(.plain).scrollContentBackground(.hidden).background(Color.spBackground)115 .overlay { if loaded && album == nil { ContentUnavailableView("Album introuvable", systemImage: "square.stack", description: Text("Il n'est plus dans la bibliothèque.")) } }116 .navigationBarTitleDisplayMode(.inline)117 .toolbar {118 if let album {119 Button { Task { await env.setFavorite(album: album, !album.favorite) } } label: { Image(systemName: album.favorite ? "heart.fill" : "heart").foregroundStyle(album.favorite ? Color.spEmber : .primary) }120 .accessibilityLabel(album.favorite ? "Retirer l'album des favoris" : "Ajouter l'album aux favoris")121 }122 }123 .sheet(item: $playlistFor) { AddToPlaylistSheet(tracks: [$0]) }124 .task(id: env.reloadKey(albumId)) {125 album = await env.db.album(id: albumId, downloadedOnly: env.downloadedOnly)126 tracks = await env.db.tracks(albumId: albumId, downloadedOnly: env.downloadedOnly)127 loaded = true128 }129 }130131 /// Cover beside the text when the column is wide enough (iPad, landscape), above it otherwise.132 private func header(_ a: Album) -> some View {133 ViewThatFits(in: .horizontal) {134 HStack(alignment: .bottom, spacing: 28) {135 ArtworkView(id: a.artworkId, side: 240, corner: 14).shadow(radius: 16, y: 8)136 info(a, leading: true).frame(minWidth: 330, alignment: .leading)137 Spacer(minLength: 0)138 }139 VStack(spacing: 16) { ArtworkView(id: a.artworkId, side: 250, corner: 14).shadow(radius: 16, y: 8); info(a, leading: false) }.frame(maxWidth: .infinity)140 }141 }142 private func info(_ a: Album, leading: Bool) -> some View {143 VStack(alignment: leading ? .leading : .center, spacing: 6) {144 Text(a.title).font(.title2.bold()).multilineTextAlignment(leading ? .leading : .center).accessibilityIdentifier("album-title")145 // Inside a list row a NavigationLink brings its own chevron and stretches: the link sits behind the text instead.146 Text(a.artistName).font(.title3).foregroundStyle(Color.spEmber)147 .background { NavigationLink(value: Route.artist(a.artistId)) { EmptyView() }.opacity(0) }148 .accessibilityAddTraits(.isLink)149 Text([a.genre, a.year.map(String.init), tracks.first.map { $0.formatDescription }].compactMap { $0 }.joined(separator: " · ")).font(.footnote).foregroundStyle(Color.spMuted)150 PlayShuffleButtons(tracks: tracks).padding(.top, 10).frame(maxWidth: 420)151 DownloadButton(kind: .album, id: a.id, label: "Télécharger l'album").buttonStyle(.bordered).tint(Color.spEmber).padding(.top, 2)152 }153 }154 private func footer(_ a: Album) -> some View {155 Text("\(a.trackCount) titre\(a.trackCount > 1 ? "s" : "") · \(Format.longDuration(ms: a.durationMs))").font(.footnote).foregroundStyle(Color.spMuted)156 }157}158159struct ArtistDetailView: View {160 @Environment(AppEnvironment.self) private var env161 let artistId: String162 @State private var artist: Artist?163 @State private var albums: [Album] = []164 @State private var tracks: [Track] = []165 @State private var playlistFor: Track?166167 var body: some View {168 ScrollView {169 LazyVStack(alignment: .leading, spacing: 22) {170 if let artist {171 VStack(spacing: 12) {172 ArtworkView(id: artist.artworkId, side: 150, corner: 75)173 Text(artist.name).font(.largeTitle.bold()).multilineTextAlignment(.center)174 PlayShuffleButtons(tracks: tracks).frame(maxWidth: 420)175 }176 .frame(maxWidth: .infinity).padding(.horizontal)177 }178 if !albums.isEmpty {179 SectionTitle(title: "Albums")180 LazyVGrid(columns: [GridItem(.adaptive(minimum: 150, maximum: 220), spacing: 16)], spacing: 20) {181 ForEach(albums) { a in NavigationLink(value: Route.album(a.id)) { AlbumCard(album: a) }.buttonStyle(.plain) }182 }183 .padding(.horizontal)184 }185 if !tracks.isEmpty {186 SectionTitle(title: "Titres")187 VStack(spacing: 10) {188 ForEach(Array(tracks.prefix(60).enumerated()), id: \.element.id) { i, t in TrackRow(track: t, onAddToPlaylist: { playlistFor = $0 }) { env.play(tracks, startAt: i) } }189 }190 .padding(.horizontal)191 }192 }193 .padding(.vertical)194 }195 .background(Color.spBackground)196 .navigationBarTitleDisplayMode(.inline)197 .sheet(item: $playlistFor) { AddToPlaylistSheet(tracks: [$0]) }198 .task(id: env.reloadKey(artistId)) {199 let only = env.downloadedOnly200 artist = await env.db.artist(id: artistId, downloadedOnly: only)201 albums = await env.db.albums(artistId: artistId, downloadedOnly: only)202 tracks = await env.db.tracks(artistId: artistId, downloadedOnly: only)203 }204 }205}206