Skip to content

Commit

Permalink
feat(artist): add redacted placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
angristan committed Jul 21, 2021
1 parent b69227d commit 31d5e02
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 34 deletions.
7 changes: 5 additions & 2 deletions firstfm/ViewModel/ChartViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class ChartViewModel: ObservableObject {
reset()

LastFMAPI.request(lastFMMethod: "chart.getTopArtists", args: ["limit": "30"]) { (data: TopArtistsResponse?, error) -> Void in
self.isLoading = false

if error != nil {
DispatchQueue.main.async {
FloatingNotificationBanner(title: "Failed to load charts", subtitle: error?.localizedDescription, style: .danger).show()
// Force refresh, otherwise pull loader doesn't dismiss itself
self.artists = self.artists
self.isLoading = false
}
}

Expand All @@ -33,6 +33,7 @@ class ChartViewModel: ObservableObject {

DispatchQueue.main.async {
self.artists = artists
self.isLoading = false
}

for (index, artist) in data.artists.artist.enumerated() {
Expand All @@ -53,18 +54,20 @@ class ChartViewModel: ObservableObject {
reset()

LastFMAPI.request(lastFMMethod: "chart.getTopTracks", args: ["limit": "30"]) { (data: TopTrackResponse?, error) -> Void in
self.isLoading = false

if error != nil {
DispatchQueue.main.async {
FloatingNotificationBanner(title: "Failed to load charts", subtitle: error?.localizedDescription, style: .danger).show()
// Force refresh, otherwise pull loader doesn't dismiss itself
self.tracks = self.tracks
self.isLoading = false
}
}

if let data = data {
DispatchQueue.main.async {
self.tracks = data.tracks.track
self.isLoading = false
}

for (index, track) in data.tracks.track.enumerated() {
Expand Down
16 changes: 15 additions & 1 deletion firstfm/Views/Artist/ArtistInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct ArtistInfoView: View {
.font(.subheadline)
.foregroundColor(.gray)
}
Text(artistInfo?.bio.content ?? "").lineLimit(3)
Text(artistInfo?.bio.content ?? "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.").lineLimit(3)

ScrollView(.horizontal, showsIndicators: true) {
HStack {
Expand All @@ -31,6 +31,20 @@ struct ArtistInfoView: View {
.cornerRadius(.infinity)
.lineLimit(1)
}
} else {
// Placeholder for redacted
ForEach(["pop", "synthpop", "female vocalist", "indie"], id: \.self) {tag in
Button(action: {}) {
HStack {
Text(tag)
}
}
.padding(10)
.foregroundColor(.white)
.background(Color.gray)
.cornerRadius(.infinity)
.lineLimit(1)
}
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions firstfm/Views/Artist/ArtistView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,28 @@ struct ArtistView: View {
VStack(alignment: .leading) {
ArtistInfoView(artistInfo: model.artist, artist: artist)
.padding()
.redacted(reason: model.isLoading ? .placeholder : [])

TopArtistTracksView(tracks: model.tracks)
.frame(
width: g.size.width - 5,
height: g.size.height * 0.7,
alignment: .center
)
.redacted(reason: model.isLoading ? .placeholder : [])

TopArtistAlbumsView(albums: model.albums).offset(y: -50)
.redacted(reason: model.isLoading ? .placeholder : [])

SimilarArtistsView(similarArtists: model.artist?.similar.artist ?? [])
.offset(y: -30)
.redacted(reason: model.isLoading ? .placeholder : [])

}.padding(.top, 10)
.onAppear {
self.model.getAll(artist)
}
}.navigationTitle(artist.name)
}.opacity(model.isLoading ? 0 : 1)

// Show loader above the rest of the ZStack
if model.isLoading {
ProgressView().scaleEffect(2)
}
}
}
Expand Down
22 changes: 19 additions & 3 deletions firstfm/Views/Artist/SimilarArtistsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ struct SimilarArtistsView: View {

var body: some View {
Section {
Text("Similar artists").font(.headline)
Text("Similar artists").font(.headline).unredacted()
ScrollView(.horizontal, showsIndicators: false) {
HStack {
// if let artist = self.model.artist {
if !similarArtists.isEmpty {
ForEach(similarArtists, id: \.name) {artist in
VStack {
KFImage.url(URL(string: artist.image[0].url )!)
Expand All @@ -24,7 +24,23 @@ struct SimilarArtistsView: View {
.foregroundColor(.gray).lineLimit(1)
}
}
// }
} else {
// Placeholder for redacted
ForEach((1...5), id: \.self) {_ in
VStack {
KFImage.url(URL(string: "https://lastfm.freetls.fastly.net/i/u/64s/4128a6eb29f94943c9d206c08e625904.webp")!)
.resizable()
.loadImmediately()
.aspectRatio(contentMode: .fill)
.frame(width: 150, height: 150)
.clipShape(Circle())
.cornerRadius(.infinity)

Text("Artist").font(.subheadline)
.foregroundColor(.gray).lineLimit(1)
}
}
}
}
}
}.padding()
Expand Down
54 changes: 38 additions & 16 deletions firstfm/Views/Artist/TopArtistAlbumsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,44 @@ struct TopArtistAlbumsView: View {
GridItem(.flexible(minimum: 50, maximum: 200)),
GridItem(.flexible(minimum: 50, maximum: 200))
], spacing: 30 ) {
ForEach(albums, id: \.name) { album in
NavigationLink(
destination: Color(.red),
label: {
VStack {
KFImage.url(URL(string: album.image[0].url )!)
.resizable()
.loadImmediately()
.cornerRadius(5)
.aspectRatio(contentMode: .fill)
Text(album.name).font(.headline).lineLimit(1).foregroundColor(.white)
Text("\(String(format: "%ld", locale: Locale.current, album.playcount) ) listeners")
.font(.subheadline)
.foregroundColor(.gray).lineLimit(1)
}
})
if !albums.isEmpty {
ForEach(albums, id: \.name) { album in
NavigationLink(
destination: Color(.red),
label: {
VStack {
KFImage.url(URL(string: album.image[0].url )!)
.resizable()
.loadImmediately()
.cornerRadius(5)
.aspectRatio(contentMode: .fill)
Text(album.name).font(.headline).lineLimit(1).foregroundColor(.white)
Text("\(String(format: "%ld", locale: Locale.current, album.playcount) ) listeners")
.font(.subheadline)
.foregroundColor(.gray).lineLimit(1)
}
})

}
} else {
// Placeholder for redacted
ForEach((1...6), id: \.self) {_ in
NavigationLink(
destination: Color(.red),
label: {
VStack {
KFImage.url(URL(string: "https://lastfm.freetls.fastly.net/i/u/64s/4128a6eb29f94943c9d206c08e625904.webp" )!)
.resizable()
.loadImmediately()
.cornerRadius(5)
.aspectRatio(contentMode: .fill)
Text("Album name").font(.headline).lineLimit(1).foregroundColor(.white)
Text("\(String(format: "%ld", locale: Locale.current, 0) ) listeners")
.font(.subheadline)
.foregroundColor(.gray).lineLimit(1)
}
})
}

}
}
Expand Down
26 changes: 19 additions & 7 deletions firstfm/Views/Artist/TopArtistTracksView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,26 @@ struct TopArtistTracksView: View {
var body: some View {
List {
Section {
Text("Top tracks").font(.headline)
ForEach(tracks, id: \.name) { track in
NavigationLink(
destination: Color(.red),
label: {
TrackRow(track: track)
})
Text("Top tracks").font(.headline).unredacted()
if !tracks.isEmpty {
ForEach(tracks, id: \.name) { track in
NavigationLink(
destination: Color(.red),
label: {
TrackRow(track: track)
})
}
} else {
// Placeholder for redacted
ForEach((1...5), id: \.self) {_ in
NavigationLink(
destination: Color(.red),
label: {
TrackRow(track: Track(name: "toto", playcount: "123", listeners: "123", url: "123", artist: nil, image: [LastFMImage(url: "https://lastfm.freetls.fastly.net/i/u/64s/4128a6eb29f94943c9d206c08e625904.webp", size: "lol")]))
})
}
}

}
}
}
Expand Down

0 comments on commit 31d5e02

Please sign in to comment.