Skip to content

Commit

Permalink
feat(scrobbles): show artist, shorter relative time
Browse files Browse the repository at this point in the history
  • Loading branch information
angristan committed Jul 10, 2021
1 parent 75b116a commit e52b1db
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion firstfm/Data/Entities/Artist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ struct Artist: Codable, Identifiable {
struct ScrobbledArtist: Codable {
let mbid: String
// let image: [LastFMImage]
let name: String?
let name: String
}
2 changes: 1 addition & 1 deletion firstfm/Data/Entities/Track.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct LastFMDate: Codable {
let unixTimestamp = Double(self.uts)!
let date = Date(timeIntervalSince1970: unixTimestamp)
let formatter = RelativeDateTimeFormatter()
formatter.unitsStyle = .full
formatter.unitsStyle = .abbreviated
let relativeDate = formatter.localizedString(for: date, relativeTo: Date())
return relativeDate
}
Expand Down
1 change: 1 addition & 0 deletions firstfm/Data/ViewModel/ScrobblesViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ScrobblesViewModel: ObservableObject {

LastFMAPI.request(lastFMMethod: "user.getRecentTracks", args: [
"limit": "30",
"extended": "1",
"user": storedUsername ?? "",
]) { (data: RecentTracksResponse?, error) -> Void in
self.isLoading = false
Expand Down
1 change: 0 additions & 1 deletion firstfm/Views/ScrobblesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import SwiftUIRefresh
struct Scrobbles: View {
@ObservedObject var vm = ScrobblesViewModel()
@State var scrobblesLoaded = false
@State private var selectedChartsIndex = 0
@State private var isPullLoaderShowing = false

var body: some View {
Expand Down
15 changes: 11 additions & 4 deletions firstfm/Views/SubViews/ScrobbledTrackRowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,18 @@ struct ScrobbledTrackRow: View {

VStack(alignment: .leading) {
Spacer()
Text(track.name)
.font(.headline)
.lineLimit(1)
HStack {
Text(track.name)
.font(.headline)
.lineLimit(1)
Spacer()
Text(track.date?.getRelative() ?? "Now Playing")
.font(.subheadline)
.foregroundColor(.gray)
.frame(alignment: .leading)
}
Spacer()
Text(track.date?.getRelative() ?? "Now Playing")
Text(track.artist.name)
.font(.subheadline)
.foregroundColor(.gray)
}
Expand Down

0 comments on commit e52b1db

Please sign in to comment.