Skip to content

Commit c3e57f2

Browse files
committed
feat(wiki): add artist, album extract from respective wikipedia articles.
1 parent 3b37c78 commit c3e57f2

24 files changed

Lines changed: 636 additions & 169 deletions

‎Snapper.xcodeproj/project.xcproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"Models/Track.swift",
101101
"Resources/Assets.xcassets",
102102
"Services/Api/Dto/AlbumDto.swift",
103+
"Services/Api/Dto/AlbumWikiResponseDto.swift",
103104
"Services/Api/Dto/TrackDto.swift",
104105
"Storage/JsonFile.swift",
105106
"Storage/SnapperSchema.swift",

‎Snapper/App/PreviewConsoleHandler.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ enum PreviewLoggerFactory {
1111

1212
struct PreviewConsoleHandler: LogHandler {
1313
let label: String
14-
var logLevel: Logger.Level = .info
14+
var logLevel: Logger.Level = .trace
1515
var metadata: Logger.Metadata = [:]
1616

1717
subscript(metadataKey key: String) -> Logger.Metadata.Value? {

‎Snapper/Features/AlbumDetail/AlbumDetailView.swift‎

Lines changed: 33 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import MapKit
21
import SwiftData
32
import 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-
282201
private 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
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import MapKit
2+
import SwiftUI
3+
4+
struct AlbumLocationSection: View {
5+
let location: CLLocation
6+
7+
@State private var position: MapCameraPosition = .automatic
8+
@State private var isExpanded = true
9+
10+
var body: some View {
11+
VStack(alignment: .leading, spacing: Spacing.sm) {
12+
DisclosureGroup(isExpanded: $isExpanded) {
13+
Map(position: $position, interactionModes: [.pan, .zoom]) {
14+
Marker("Album", coordinate: location.coordinate)
15+
.tint(.accent)
16+
}
17+
.frame(height: 200)
18+
.overlay(alignment: .bottomTrailing) {
19+
VStack {
20+
Button("Re-center", systemImage: "location.fill") {
21+
withAnimation(.easeInOut(duration: 0.5)) {
22+
recenter()
23+
}
24+
}
25+
.padding(Padding.md)
26+
.labelStyle(.iconOnly)
27+
.foregroundStyle(.themePrimaryActive)
28+
.glassEffect(.clear.tint(.themeSurface1))
29+
}
30+
.padding(Padding.lg)
31+
}
32+
} label: {
33+
Text("Location")
34+
.font(.zillaSlab(.headline).bold())
35+
}
36+
.disclosureGroupStyle(.theme(.surface1))
37+
38+
NearbyRecordStoresView(location: location)
39+
}
40+
.onChange(of: isExpanded, initial: true) { _, newValue in
41+
if newValue {
42+
recenter()
43+
}
44+
}
45+
}
46+
47+
private func recenter() {
48+
position = location.position
49+
}
50+
}
51+
52+
private struct NearbyRecordStoresView: View {
53+
private enum State {
54+
case ready
55+
case loading
56+
case success([RecordStoreCandidate])
57+
case failure(Error)
58+
}
59+
60+
@Environment(\.recordStoreLocator) private var locator
61+
62+
let location: CLLocation
63+
64+
@State private var state: State = .ready
65+
@State private var selection = StoreSelection()
66+
67+
var body: some View {
68+
Group {
69+
switch state {
70+
case .ready, .loading:
71+
ProgressView("Locating record stores nearby...")
72+
.progressViewStyle(.inline(.trailing))
73+
.font(.gillSans(.caption))
74+
.controlSize(.small)
75+
76+
case .failure(_):
77+
Label("Unable to load record stores", systemImage: "xmark.circle")
78+
.labelStyle(.trailingIcon)
79+
.controlSize(.small)
80+
81+
case .success(let stores) where stores.isEmpty:
82+
Text("Unable to load record stores")
83+
84+
case .success(let stores):
85+
HStack(spacing: Spacing.sm) {
86+
Text("Nearby:")
87+
.font(.gillSans(.caption))
88+
89+
ScrollView(.horizontal) {
90+
HStack(spacing: Spacing.xs) {
91+
ForEach(stores) { store in
92+
RecordStoreToggle(
93+
location: location,
94+
candidate: store,
95+
selection: selection,
96+
)
97+
}
98+
}
99+
.padding(1)
100+
}
101+
.scrollIndicators(.hidden)
102+
}
103+
}
104+
}
105+
.task {
106+
state = .loading
107+
do {
108+
let stores = try await locator.locate(
109+
near: location,
110+
within: .kilometers(5),
111+
limit: 3,
112+
)
113+
state = .success(stores)
114+
} catch {
115+
state = .failure(error)
116+
}
117+
}
118+
}
119+
}
120+
121+
#if DEBUG
122+
#Preview {
123+
let logger = PreviewLoggerFactory.makeLogger("playground")
124+
let location: LocationStub = .newYork
125+
126+
AlbumLocationSection(location: location.location)
127+
.environment(\.recordStoreLocator, .live(logger))
128+
.padding()
129+
}
130+
#endif

0 commit comments

Comments
 (0)