-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented carousel, loading uris from home, space bar to toggle pla…
…y/pause
- Loading branch information
Lee Jun Kit
committed
Jun 16, 2021
1 parent
54878e6
commit 3a186da
Showing
20 changed files
with
558 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
Spottie/Backend/Types/API/PersonalizedRecommendationsResponse.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// PersonalizedRecommendationsResponse.swift | ||
// Spottie | ||
// | ||
// Created by Lee Jun Kit on 8/6/21. | ||
// | ||
|
||
import Foundation | ||
|
||
struct PersonalizedRecommendationsResponse: Decodable { | ||
var content: Content | ||
|
||
struct Content: Decodable { | ||
var items: [RecommendationGroup] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// RecommendationGroup.swift | ||
// Spottie | ||
// | ||
// Created by Lee Jun Kit on 7/6/21. | ||
// | ||
|
||
import Foundation | ||
|
||
struct RecommendationGroup: Decodable, Hashable, Identifiable { | ||
var id: String | ||
var name: String | ||
var rendering: String | ||
var items: [RecommendationItem] | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case id | ||
case name | ||
case rendering | ||
case items | ||
case content | ||
} | ||
|
||
struct Content: Decodable { | ||
var items: [RecommendationItem] | ||
} | ||
|
||
init(from decoder: Decoder) throws { | ||
let values = try decoder.container(keyedBy: CodingKeys.self) | ||
|
||
self.id = try values.decode(String.self, forKey:.id) | ||
self.name = try values.decode(String.self, forKey:.name) | ||
self.rendering = try values.decode(String.self, forKey:.rendering) | ||
|
||
let contentContainer = try values.decode(Content.self, forKey:.content) | ||
self.items = contentContainer.items | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// | ||
// RecommendationItem.swift | ||
// Spottie | ||
// | ||
// Created by Lee Jun Kit on 7/6/21. | ||
// | ||
|
||
import Foundation | ||
|
||
enum RecommendationItemData { | ||
case link(RecommendationLink) | ||
case album(WebAPISimplifiedAlbumObject) | ||
case artist(WebAPIArtistObject) | ||
case playlist(WebAPIPlaylistObject) | ||
} | ||
|
||
struct RecommendationItem: Hashable, Identifiable, Decodable { | ||
static func == (lhs: RecommendationItem, rhs: RecommendationItem) -> Bool { | ||
if lhs.type == rhs.type { | ||
if (lhs.type == .unknown) { | ||
return true | ||
} | ||
} | ||
|
||
return lhs.id == rhs.id; | ||
} | ||
|
||
func hash(into hasher: inout Hasher) { | ||
hasher.combine(self.id) | ||
} | ||
|
||
enum RecommendationItemType: String, Decodable, CaseIterable { | ||
case link | ||
case album | ||
case artist | ||
case playlist | ||
case unknown | ||
} | ||
|
||
var id: String | ||
var type: RecommendationItemType | ||
var data: RecommendationItemData? | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case type | ||
case data | ||
} | ||
|
||
init(from decoder: Decoder) throws { | ||
let values = try decoder.container(keyedBy: CodingKeys.self) | ||
var typeRawValue = try values.decode(String.self, forKey:.type) | ||
print("Encountered RecommendationItemType \(typeRawValue)") | ||
|
||
if (!(RecommendationItemType.allCases.map { | ||
$0.rawValue | ||
}.contains(typeRawValue))) { | ||
typeRawValue = "unknown" | ||
} | ||
|
||
self.type = RecommendationItemType(rawValue: typeRawValue)! | ||
|
||
// attempt to decode RecommendationItemData | ||
let container = try decoder.singleValueContainer() | ||
switch(self.type) { | ||
case .link: | ||
data = RecommendationItemData.link(try container.decode(RecommendationLink.self)) | ||
self.id = "spotify:link:\(UUID().uuidString)" | ||
case .artist: | ||
let artist = try container.decode(WebAPIArtistObject.self) | ||
self.id = artist.uri | ||
data = RecommendationItemData.artist(artist) | ||
case .album: | ||
let album = try container.decode(WebAPISimplifiedAlbumObject.self) | ||
self.id = album.uri | ||
data = RecommendationItemData.album(album) | ||
case .playlist: | ||
let playlist = try container.decode(WebAPIPlaylistObject.self) | ||
self.id = playlist.uri | ||
data = RecommendationItemData.playlist(playlist) | ||
case .unknown: | ||
self.id = "spotify:unknown:\(UUID().uuidString)" | ||
break | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// RecommendationLink.swift | ||
// Spottie | ||
// | ||
// Created by Lee Jun Kit on 7/6/21. | ||
// | ||
|
||
import Foundation | ||
|
||
struct RecommendationLink: Decodable { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// RecommendationsObject.swift | ||
// Spottie | ||
// | ||
// Created by Lee Jun Kit on 7/6/21. | ||
// | ||
|
||
import Foundation | ||
|
||
struct RecommendationList: Decodable { | ||
var id: String | ||
var name: String | ||
var rendering: String | ||
var items: [Item] | ||
|
||
struct Item: Decodable { | ||
var type: String | ||
var name: String | ||
var uri: String | ||
var href: String | ||
} | ||
} |
Oops, something went wrong.