Skip to content

Commit

Permalink
feat: rework ArtistView
Browse files Browse the repository at this point in the history
  • Loading branch information
angristan committed Jul 19, 2021
1 parent a5c9d4e commit 94aa11f
Show file tree
Hide file tree
Showing 11 changed files with 378 additions and 60 deletions.
62 changes: 62 additions & 0 deletions firstfm.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@
82505CE72675300400CCCB58 /* ArtistSearchResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82505CE62675300400CCCB58 /* ArtistSearchResponse.swift */; };
82505CE92675368400CCCB58 /* LastFMImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82505CE82675368400CCCB58 /* LastFMImage.swift */; };
8253DC0C26A0E10100F5F426 /* NotificationBannerSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 8253DC0B26A0E10100F5F426 /* NotificationBannerSwift */; };
825F0F8426A48597007BA84B /* FancyScrollView in Frameworks */ = {isa = PBXBuildFile; productRef = 825F0F8326A48597007BA84B /* FancyScrollView */; };
825F0F8726A48C9C007BA84B /* Introspect in Frameworks */ = {isa = PBXBuildFile; productRef = 825F0F8626A48C9C007BA84B /* Introspect */; };
825F0F8926A4B2E0007BA84B /* ArtistInfoResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 825F0F8826A4B2E0007BA84B /* ArtistInfoResponse.swift */; };
825F0F8B26A5B6E1007BA84B /* NumberFormat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 825F0F8A26A5B6E1007BA84B /* NumberFormat.swift */; };
825F0F8D26A5E8BB007BA84B /* ArtistInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 825F0F8C26A5E8BB007BA84B /* ArtistInfo.swift */; };
825F0F8F26A5E8D3007BA84B /* ArtistBio.swift in Sources */ = {isa = PBXBuildFile; fileRef = 825F0F8E26A5E8D3007BA84B /* ArtistBio.swift */; };
825F0F9126A5E8F5007BA84B /* SimilarArtist.swift in Sources */ = {isa = PBXBuildFile; fileRef = 825F0F9026A5E8F5007BA84B /* SimilarArtist.swift */; };
825F0F9326A5E90C007BA84B /* Tag.swift in Sources */ = {isa = PBXBuildFile; fileRef = 825F0F9226A5E90C007BA84B /* Tag.swift */; };
825F0F9526A5E938007BA84B /* ArtistStats.swift in Sources */ = {isa = PBXBuildFile; fileRef = 825F0F9426A5E938007BA84B /* ArtistStats.swift */; };
826CBA992678EB8800B11170 /* ArtistView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 826CBA982678EB8800B11170 /* ArtistView.swift */; };
82844E012673991F00578DD4 /* FirstfmApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82844E002673991F00578DD4 /* FirstfmApp.swift */; };
82844E052673992200578DD4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 82844E042673992200578DD4 /* Assets.xcassets */; };
Expand Down Expand Up @@ -94,6 +103,13 @@
82505CDE2675074E00CCCB58 /* ContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
82505CE62675300400CCCB58 /* ArtistSearchResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArtistSearchResponse.swift; sourceTree = "<group>"; };
82505CE82675368400CCCB58 /* LastFMImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LastFMImage.swift; sourceTree = "<group>"; };
825F0F8826A4B2E0007BA84B /* ArtistInfoResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArtistInfoResponse.swift; sourceTree = "<group>"; };
825F0F8A26A5B6E1007BA84B /* NumberFormat.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NumberFormat.swift; sourceTree = "<group>"; };
825F0F8C26A5E8BB007BA84B /* ArtistInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArtistInfo.swift; sourceTree = "<group>"; };
825F0F8E26A5E8D3007BA84B /* ArtistBio.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArtistBio.swift; sourceTree = "<group>"; };
825F0F9026A5E8F5007BA84B /* SimilarArtist.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimilarArtist.swift; sourceTree = "<group>"; };
825F0F9226A5E90C007BA84B /* Tag.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tag.swift; sourceTree = "<group>"; };
825F0F9426A5E938007BA84B /* ArtistStats.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArtistStats.swift; sourceTree = "<group>"; };
826CBA982678EB8800B11170 /* ArtistView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArtistView.swift; sourceTree = "<group>"; };
82844DFD2673991F00578DD4 /* firstfm.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = firstfm.app; sourceTree = BUILT_PRODUCTS_DIR; };
82844E002673991F00578DD4 /* FirstfmApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirstfmApp.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -138,6 +154,8 @@
files = (
82E80C39269777C60098DC3C /* SwiftUIRefresh in Frameworks */,
8253DC0C26A0E10100F5F426 /* NotificationBannerSwift in Frameworks */,
825F0F8726A48C9C007BA84B /* Introspect in Frameworks */,
825F0F8426A48597007BA84B /* FancyScrollView in Frameworks */,
82505CE42675178B00CCCB58 /* Kingfisher in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -150,6 +168,7 @@
children = (
4A8C296026983B7300F55ECC /* LastFMAPI.swift */,
82C282E126A31CFD000E5F41 /* StringMD5.swift */,
825F0F8A26A5B6E1007BA84B /* NumberFormat.swift */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -241,9 +260,14 @@
82D512F12674FE9D00206EBB /* API */,
82FBAE462674B8FC000D8E29 /* Artist.swift */,
4A69011726A344FD001561C8 /* ArtistAlbum.swift */,
825F0F8E26A5E8D3007BA84B /* ArtistBio.swift */,
825F0F8C26A5E8BB007BA84B /* ArtistInfo.swift */,
825F0F9426A5E938007BA84B /* ArtistStats.swift */,
82BBD2452698B13B009B42FC /* Country.swift */,
82C282E526A32E94000E5F41 /* Friend.swift */,
82505CE82675368400CCCB58 /* LastFMImage.swift */,
825F0F9026A5E8F5007BA84B /* SimilarArtist.swift */,
825F0F9226A5E90C007BA84B /* Tag.swift */,
82A006B7267960D90009BD71 /* Track.swift */,
821493A12694C38E007A21C8 /* User.swift */,
);
Expand All @@ -268,6 +292,7 @@
82A006BB2679631A0009BD71 /* TopTracksResponseContainer.swift */,
82A006B9267963010009BD71 /* TrackResponse.swift */,
821493A32694C427007A21C8 /* UserInfoResponse.swift */,
825F0F8826A4B2E0007BA84B /* ArtistInfoResponse.swift */,
);
path = API;
sourceTree = "<group>";
Expand Down Expand Up @@ -320,6 +345,8 @@
82505CE32675178B00CCCB58 /* Kingfisher */,
82E80C38269777C60098DC3C /* SwiftUIRefresh */,
8253DC0B26A0E10100F5F426 /* NotificationBannerSwift */,
825F0F8326A48597007BA84B /* FancyScrollView */,
825F0F8626A48C9C007BA84B /* Introspect */,
);
productName = firstfm;
productReference = 82844DFD2673991F00578DD4 /* firstfm.app */;
Expand Down Expand Up @@ -352,6 +379,8 @@
82505CE22675178B00CCCB58 /* XCRemoteSwiftPackageReference "Kingfisher" */,
82E80C37269777C50098DC3C /* XCRemoteSwiftPackageReference "SwiftUIRefresh" */,
8253DC0A26A0E10100F5F426 /* XCRemoteSwiftPackageReference "NotificationBanner" */,
825F0F8226A48597007BA84B /* XCRemoteSwiftPackageReference "FancyScrollView" */,
825F0F8526A48C9C007BA84B /* XCRemoteSwiftPackageReference "SwiftUI-Introspect" */,
);
productRefGroup = 82844DFE2673991F00578DD4 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -413,6 +442,9 @@
82FBAE4E2674BD02000D8E29 /* TopArtistsResponseArtistContainer.swift in Sources */,
82A006BA267963010009BD71 /* TrackResponse.swift in Sources */,
82FBAE4C2674BCB7000D8E29 /* ArtistResponse.swift in Sources */,
825F0F9326A5E90C007BA84B /* Tag.swift in Sources */,
825F0F9526A5E938007BA84B /* ArtistStats.swift in Sources */,
825F0F9126A5E8F5007BA84B /* SimilarArtist.swift in Sources */,
82C282EC26A370D2000E5F41 /* ScobbledTrackViewModel.swift in Sources */,
82505CE02675074E00CCCB58 /* ChartListView.swift in Sources */,
82D5B4D42696DC7800716931 /* RecentTracks.swift in Sources */,
Expand All @@ -423,6 +455,7 @@
82C282E026A2E474000E5F41 /* LoginResponse.swift in Sources */,
4A56027A26A3B17800E6C315 /* AlbumRow.swift in Sources */,
82FBAE472674B8FC000D8E29 /* Artist.swift in Sources */,
825F0F8B26A5B6E1007BA84B /* NumberFormat.swift in Sources */,
4A69011826A344FD001561C8 /* ArtistAlbum.swift in Sources */,
82D5B4D02696DB8500716931 /* ScrobblesView.swift in Sources */,
82505CDF2675074E00CCCB58 /* ArtistRow.swift in Sources */,
Expand All @@ -431,6 +464,7 @@
821493A42694C427007A21C8 /* UserInfoResponse.swift in Sources */,
82C282EA26A3354E000E5F41 /* FriendRow.swift in Sources */,
82844E012673991F00578DD4 /* FirstfmApp.swift in Sources */,
825F0F8D26A5E8BB007BA84B /* ArtistInfo.swift in Sources */,
82A006B6267960710009BD71 /* TrackRowView.swift in Sources */,
82A006B8267960D90009BD71 /* Track.swift in Sources */,
82A006BC2679631A0009BD71 /* TopTracksResponseContainer.swift in Sources */,
Expand All @@ -443,12 +477,14 @@
82BBD2462698B13B009B42FC /* Country.swift in Sources */,
4A69012626A3A08F001561C8 /* AlbumSearchResponse.swift in Sources */,
82C282E226A31CFD000E5F41 /* StringMD5.swift in Sources */,
825F0F8926A4B2E0007BA84B /* ArtistInfoResponse.swift in Sources */,
82C282E826A3332E000E5F41 /* FriendsResponse.swift in Sources */,
820455E0267ABC930009A418 /* AuthViewModel.swift in Sources */,
4A8C296126983B7300F55ECC /* LastFMAPI.swift in Sources */,
82BBD24A2698C33D009B42FC /* TopCountryView.swift in Sources */,
820455DC267AA8E70009A418 /* LoginView.swift in Sources */,
820455DE267AB7D70009A418 /* ProfileView.swift in Sources */,
825F0F8F26A5E8D3007BA84B /* ArtistBio.swift in Sources */,
82C282E626A32E94000E5F41 /* Friend.swift in Sources */,
8226AB2226998A86007ECE5F /* TopCountryViewModel.swift in Sources */,
4A69011A26A347C4001561C8 /* ArtistTopAlbumsResponse.swift in Sources */,
Expand Down Expand Up @@ -671,6 +707,22 @@
minimumVersion = 3.0.7;
};
};
825F0F8226A48597007BA84B /* XCRemoteSwiftPackageReference "FancyScrollView" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/nerdsupremacist/FancyScrollView.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.1.3;
};
};
825F0F8526A48C9C007BA84B /* XCRemoteSwiftPackageReference "SwiftUI-Introspect" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/siteline/SwiftUI-Introspect.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.1.3;
};
};
82E80C37269777C50098DC3C /* XCRemoteSwiftPackageReference "SwiftUIRefresh" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/timbersoftware/SwiftUIRefresh.git";
Expand All @@ -692,6 +744,16 @@
package = 8253DC0A26A0E10100F5F426 /* XCRemoteSwiftPackageReference "NotificationBanner" */;
productName = NotificationBannerSwift;
};
825F0F8326A48597007BA84B /* FancyScrollView */ = {
isa = XCSwiftPackageProductDependency;
package = 825F0F8226A48597007BA84B /* XCRemoteSwiftPackageReference "FancyScrollView" */;
productName = FancyScrollView;
};
825F0F8626A48C9C007BA84B /* Introspect */ = {
isa = XCSwiftPackageProductDependency;
package = 825F0F8526A48C9C007BA84B /* XCRemoteSwiftPackageReference "SwiftUI-Introspect" */;
productName = Introspect;
};
82E80C38269777C60098DC3C /* SwiftUIRefresh */ = {
isa = XCSwiftPackageProductDependency;
package = 82E80C37269777C50098DC3C /* XCRemoteSwiftPackageReference "SwiftUIRefresh" */;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
{
"object": {
"pins": [
{
"package": "FancyScrollView",
"repositoryURL": "https://github.com/nerdsupremacist/FancyScrollView.git",
"state": {
"branch": null,
"revision": "5240ad515fcfea10f00e1769b058cabc9cf5fdc4",
"version": "0.1.3"
}
},
{
"package": "Kingfisher",
"repositoryURL": "https://github.com/onevcat/Kingfisher",
Expand All @@ -20,7 +29,7 @@
}
},
{
"package": "NotificationBannerSwift",
"package": "NotificationBanner",
"repositoryURL": "https://github.com/eenwak/NotificationBanner",
"state": {
"branch": null,
Expand All @@ -38,7 +47,7 @@
}
},
{
"package": "Introspect",
"package": "SwiftUI-Introspect",
"repositoryURL": "https://github.com/siteline/SwiftUI-Introspect.git",
"state": {
"branch": null,
Expand Down
12 changes: 12 additions & 0 deletions firstfm/Data/Entities/API/ArtistInfoResponse.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// ArtistInfoResponse.swift
// firstfm
//
// Created by Stanislas Lange on 18/07/2021.
//

import Foundation

struct ArtistInfoResponse: Codable {
let artist: ArtistInfo
}
22 changes: 22 additions & 0 deletions firstfm/Data/Entities/ArtistBio.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// ArtistBio.swift
// firstfm
//
// Created by Stanislas Lange on 19/07/2021.
//

import Foundation

struct ArtistBio: Codable {
let links: ArtistBioLinks
let content, published, summary: String
}

struct ArtistBioLinks: Codable {
let link: ArtistBioLink
}

struct ArtistBioLink: Codable {
let rel: String
let href: String
}
20 changes: 20 additions & 0 deletions firstfm/Data/Entities/ArtistInfo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// ArtistInfo.swift
// firstfm
//
// Created by Stanislas Lange on 19/07/2021.
//

import Foundation

struct ArtistInfo: Codable {
let bio: ArtistBio
let ontour: Int
let stats: ArtistStats
let mbid: String
let image: [LastFMImage]
var similar: SimilarArtists
let url: String
let tags: Tags
let name, streamable: String
}
12 changes: 12 additions & 0 deletions firstfm/Data/Entities/ArtistStats.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// ArtistStats.swift
// firstfm
//
// Created by Stanislas Lange on 19/07/2021.
//

import Foundation

struct ArtistStats: Codable {
let playcount, listeners: Int
}
18 changes: 18 additions & 0 deletions firstfm/Data/Entities/SimilarArtist.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// SimilarArtist.swift
// firstfm
//
// Created by Stanislas Lange on 19/07/2021.
//

import Foundation

struct SimilarArtist: Codable {
let url: String
let name: String
var image: [LastFMImage]
}

struct SimilarArtists: Codable {
var artist: [SimilarArtist]
}
17 changes: 17 additions & 0 deletions firstfm/Data/Entities/Tag.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Tag.swift
// firstfm
//
// Created by Stanislas Lange on 19/07/2021.
//

import Foundation

struct Tags: Codable {
let tag: [Tag]
}

struct Tag: Codable {
let name: String
let url: String
}
50 changes: 50 additions & 0 deletions firstfm/Data/Utils/NumberFormat.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// DoubleFormat.swift
// firstfm
//
// Created by Stanislas Lange on 19/07/2021.
//

import Foundation

// https://stackoverflow.com/a/48371527/6945353

extension Double {
func reduceScale(to places: Int) -> Double {
let multiplier = pow(10, Double(places))
let newDecimal = multiplier * self // move the decimal right
let truncated = Double(Int(newDecimal)) // drop the fraction
let originalDecimal = truncated / multiplier // move the decimal back
return originalDecimal
}
}

extension Int {
func formatted() -> String {
let num = abs(Double(self))
let sign = (self < 0) ? "-" : ""

switch num {
case 1_000_000_000...:
var formatted = num / 1_000_000_000
formatted = formatted.reduceScale(to: 1)
return "\(sign)\(formatted)B"

case 1_000_000...:
var formatted = num / 1_000_000
formatted = formatted.reduceScale(to: 1)
return "\(sign)\(formatted)M"

case 1_000...:
var formatted = num / 1_000
formatted = formatted.reduceScale(to: 1)
return "\(sign)\(formatted)k"

case 0...:
return "\(self)"

default:
return "\(sign)\(self)"
}
}
}

0 comments on commit 94aa11f

Please sign in to comment.