1- import MapKit
21import SwiftData
32import SwiftUI
43
@@ -24,6 +23,19 @@ struct AlbumDetailView: View {
2423
2524 VStack ( alignment : . leading , spacing : Spacing . lg ) {
2625 AlbumHeaderSection ( album : album , showMetadata : showMetadata )
26+
27+ if showMetadata , album . artistInfo . hasInfo {
28+ AlbumWikipediaSection ( album . artistInfo . get ( ) )
29+ }
30+
31+ if showMetadata , album . albumInfo . hasInfo {
32+ AlbumWikipediaSection ( album . albumInfo . get ( ) )
33+ }
34+
35+ if showMetadata , let location = album . location {
36+ AlbumLocationSection ( location : location )
37+ }
38+
2739 AlbumDetailSection ( album : album , showMetadata : showMetadata )
2840 AlbumTrackSection ( vm : vm , musicUrl : album . musicUrl )
2941 }
@@ -40,6 +52,7 @@ struct AlbumDetailView: View {
4052 }
4153 }
4254 . ignoresSafeArea ( . all , edges : . top )
55+ . scrollIndicators ( . hidden )
4356 . withFullBackground ( )
4457 }
4558}
@@ -74,14 +87,15 @@ private struct AlbumHeaderSection: View {
7487
7588 VStack ( spacing : Spacing . md ) {
7689 HStack ( alignment : . firstTextBaseline , spacing : Spacing . sm ) {
77- LabeledContent {
90+ VStack ( alignment : . leading , spacing : Spacing . xs ) {
7891 Text ( album . title )
7992 . font ( Typography . albumDetail . title )
80- } label : {
93+ . foregroundStyle ( . themePrimary )
94+
8195 Text ( album . artist )
8296 . font ( Typography . albumDetail . artist )
97+ . foregroundStyle ( . accent )
8398 }
84- . labeledContentStyle ( . albumHeader )
8599
86100 Spacer ( )
87101
@@ -135,17 +149,24 @@ private struct AlbumDetailSection: View {
135149 }
136150
137151 if showMetadata {
138- LabeledContent ( " Recognized " , value : album . selectedAt . abbreviated )
139- LocationSection ( location : album . location , locationStatus : album . locationStatus )
152+ LabeledContent {
153+ VStack ( alignment : . trailing , spacing : Spacing . xs ) {
154+ Text ( album . selectedAt , format : . relative ( presentation : . named ) )
155+ Text ( album . selectedAt , format : Date . FormatStyle . abbreviated )
156+ }
157+ } label : {
158+ Text ( " Recognized " )
159+ }
140160 }
141161 }
162+ . labeledContentStyle ( . withThemeFont ( . firstTextBaseline ) )
142163 }
143164 }
144165}
145166
146- extension Date {
147- fileprivate var abbreviated : String {
148- formatted ( date : . abbreviated , time : . shortened )
167+ extension Date . FormatStyle {
168+ fileprivate static var abbreviated : Self {
169+ Self ( date : . abbreviated , time : . shortened )
149170 }
150171}
151172
@@ -164,7 +185,7 @@ private struct LocationSection: View {
164185 case . captured :
165186 if let location = location {
166187 DisclosureGroup ( " Location " ) {
167- MapView ( location : location )
188+ AlbumLocationSection ( location : location )
168189 }
169190 . disclosureGroupStyle ( . plain )
170191 } else {
@@ -177,108 +198,6 @@ private struct LocationSection: View {
177198 }
178199}
179200
180- private struct MapView : View {
181- @ Environment ( \. recordStoreLocator ) private var locator
182-
183- let location : CLLocation
184- let accuracyRadius : Double ?
185-
186- init ( location : CLLocation , accuracyRadius : Double ? = nil ) {
187- self . location = location
188- self . accuracyRadius = accuracyRadius
189- }
190-
191- @ State private var position : MapCameraPosition = . automatic
192- @ State private var candidateStores : [ RecordStoreCandidate ] = [ ]
193- @ State private var storeSelection = StoreSelection ( )
194-
195- var body : some View {
196- VStack ( alignment : . leading , spacing : Spacing . sm ) {
197- Map ( position : $position ) {
198- if let accuracyRadius , accuracyRadius > 0 {
199- MapCircle ( center : location . coordinate , radius : accuracyRadius )
200- . foregroundStyle ( . themeBlue . opacity ( 0.25 ) )
201- . stroke ( . themeBlue . opacity ( 0.5 ) , lineWidth : 1 )
202- }
203-
204- Marker ( " Location " , coordinate : location . coordinate )
205- }
206- . frame ( height : 200 )
207- . clipShape ( . rect ( cornerRadius : Radius . md ) )
208- . overlay ( alignment : . bottomTrailing ) {
209- Button ( " Re-center " , systemImage : " location.fill " ) {
210- withAnimation ( . easeInOut ( duration : 0.5 ) ) {
211- recenter ( )
212- }
213- }
214- . padding ( Padding . md )
215- . labelStyle ( . iconOnly )
216- . glassEffect ( . regular . tint ( . themeBlue . opacity ( 0.25 ) ) )
217- . offset (
218- x : - Padding . lg ,
219- y : - Padding . lg ,
220- )
221- }
222-
223- if candidateStores . isEmpty {
224- HStack ( spacing : Spacing . sm ) {
225- Text ( " Locating record stores nearby... " )
226- . font ( . gillSans ( . caption ) )
227- ProgressView ( )
228- . controlSize ( . small )
229- }
230- } else {
231- HStack ( spacing : Spacing . sm ) {
232- Text ( " Nearby: " )
233- . font ( . gillSans ( . caption ) )
234-
235- ScrollView ( . horizontal ) {
236- HStack ( spacing : Spacing . xs ) {
237- ForEach ( candidateStores ) { store in
238- RecordStoreToggle (
239- location : location ,
240- candidate : store ,
241- selection : storeSelection ,
242- )
243- }
244- }
245- . padding ( 1 )
246- }
247- . scrollIndicators ( . hidden )
248- }
249- }
250- }
251- . onAppear {
252- recenter ( )
253- }
254- . task {
255- if let stores = try? await locator . locate (
256- near : location ,
257- within : . kilometers ( 5 ) ,
258- limit : 3 ,
259- ) {
260- candidateStores = stores
261- }
262- }
263- }
264-
265- private func recenter ( ) {
266- if let accuracyRadius , accuracyRadius > 0 {
267- let visibleDistance = max ( 15_000 , accuracyRadius * 3 )
268-
269- position = . region (
270- MKCoordinateRegion (
271- center : location . coordinate ,
272- latitudinalMeters : visibleDistance ,
273- longitudinalMeters : visibleDistance ,
274- )
275- )
276- } else {
277- position = location . position
278- }
279- }
280- }
281-
282201private struct AlbumTrackSection : View {
283202 let vm : AlbumDetailViewModel
284203 let musicUrl : URL ?
@@ -314,6 +233,7 @@ private struct AlbumTrackSection: View {
314233 AlbumTrackSectionFooter ( musicUrl : musicUrl )
315234 }
316235 }
236+ . labeledContentStyle ( . withThemeFont )
317237 }
318238 }
319239 }
@@ -335,6 +255,7 @@ private struct AlbumTrackSectionFooter: View {
335255 . scaledToFit ( )
336256 . frame ( height : 32 )
337257 }
258+ . stopPlayerOnUrl ( )
338259 }
339260 }
340261 }
0 commit comments