-
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.
- Loading branch information
Lee Jun Kit
committed
Jun 19, 2021
1 parent
76d1a16
commit c3f7bd3
Showing
8 changed files
with
231 additions
and
94 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 was deleted.
Oops, something went wrong.
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,78 @@ | ||
// | ||
// CarouselRow.swift | ||
// Spottie | ||
// | ||
// Created by Lee Jun Kit on 5/6/21. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct CarouselRow: View { | ||
let viewModel: ViewModel | ||
let onItemPressed: (String) -> Void | ||
|
||
var body: some View { | ||
if viewModel.groupID.hasPrefix("podcast") { | ||
EmptyView() | ||
} else { | ||
VStack(alignment: .leading) { | ||
Text(viewModel.title) | ||
.font(.title).bold() | ||
.padding(.leading) | ||
viewModel.subtitle.map({ | ||
Text($0) | ||
.font(.body) | ||
.foregroundColor(.secondary) | ||
.padding(.leading) | ||
.padding(.bottom, 8) | ||
}) | ||
HStack(alignment: .top, spacing: 40) { | ||
ForEach(viewModel.items) { item in | ||
let vm = CarouselRowItem.ViewModel.init(item) | ||
CarouselRowItem(viewModel: vm) | ||
.onTapGesture { | ||
onItemPressed(item.id) | ||
} | ||
} | ||
} | ||
.padding([.leading, .trailing]) | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
extension CarouselRow { | ||
enum RenderMode { | ||
case circular | ||
case normal | ||
} | ||
|
||
class ViewModel: ObservableObject { | ||
var groupID: String | ||
var title: String | ||
var subtitle: String? | ||
var items: [RecommendationItem] | ||
|
||
init(_ recommendationGroup: RecommendationGroup, numberOfItemsToShow: Int) { | ||
self.groupID = recommendationGroup.id | ||
|
||
title = recommendationGroup.name | ||
subtitle = recommendationGroup.tagline | ||
|
||
let numItems = recommendationGroup.items.count | ||
if (numItems < numberOfItemsToShow) { | ||
items = recommendationGroup.items | ||
} else { | ||
items = Array(recommendationGroup.items[0...numberOfItemsToShow - 1]) | ||
} | ||
} | ||
} | ||
} | ||
|
||
//struct CarouselRow_Previews: PreviewProvider { | ||
//// static let group = RecommendationGroup() | ||
//// static var previews: some View { | ||
//// CarouselRow(viewModel: <#T##CarouselRow.ViewModel#>.init()) | ||
//// } | ||
//} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// ShortcutsGrid.swift | ||
// Spottie | ||
// | ||
// Created by Lee Jun Kit on 18/6/21. | ||
// | ||
|
||
import SwiftUI | ||
import SDWebImageSwiftUI | ||
|
||
struct ShortcutGrid: View { | ||
let items: [RecommendationItem] | ||
let onItemPressed: (String) -> Void | ||
var gridItemLayout = Array(repeating: GridItem(.flexible(), spacing: 20), count: 3) | ||
|
||
var body: some View { | ||
VStack(alignment: .leading) { | ||
Text("Good Morning") | ||
.font(.largeTitle).bold() | ||
.padding(.leading) | ||
LazyVGrid(columns: gridItemLayout, spacing: 20) { | ||
ForEach(items) { item in | ||
ShortcutItem( | ||
itemHeight: 80, | ||
viewModel: ShortcutItem.ViewModel(item) | ||
) | ||
.onTapGesture { | ||
onItemPressed(item.id) | ||
} | ||
.frame(height: 80) | ||
} | ||
} | ||
.padding([.leading, .trailing]) | ||
} | ||
|
||
} | ||
} | ||
|
||
//struct ShortcutsGrid_Previews: PreviewProvider { | ||
// static var previews: some View { | ||
// ShortcutGrid() | ||
// } | ||
//} |
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,74 @@ | ||
// | ||
// ShortcutItem.swift | ||
// Spottie | ||
// | ||
// Created by Lee Jun Kit on 19/6/21. | ||
// | ||
|
||
import SwiftUI | ||
import SDWebImageSwiftUI | ||
|
||
struct ShortcutItem: View { | ||
var itemHeight: CGFloat | ||
var viewModel: ViewModel | ||
|
||
@State private var isHovering = false | ||
|
||
var body: some View { | ||
HStack { | ||
WebImage(url: viewModel.artworkURL) | ||
.resizable() | ||
.frame(width: itemHeight, height: itemHeight) | ||
.aspectRatio(1.0, contentMode: .fill) | ||
Text(viewModel.title).bold() | ||
.padding(.leading) | ||
Spacer() | ||
} | ||
.background( | ||
Color(NSColor.alternatingContentBackgroundColors[1]) | ||
.opacity(isHovering ? 1.0 : 0.3) | ||
) | ||
.onHover { hovering in | ||
isHovering = hovering | ||
} | ||
} | ||
} | ||
|
||
extension ShortcutItem { | ||
class ViewModel { | ||
var title: String | ||
var artworkURL: URL | ||
|
||
init(_ item: RecommendationItem) { | ||
if let data = item.data { | ||
switch data { | ||
case let .album(album): | ||
self.title = album.name | ||
self.artworkURL = album.getArtworkURL()! | ||
case let .artist(artist): | ||
self.title = artist.name | ||
self.artworkURL = URL(string: artist.images[0].url)! | ||
case let.playlist(playlist): | ||
self.title = playlist.name | ||
self.artworkURL = URL(string: playlist.images[0].url)! | ||
case let .link(link): | ||
self.title = link.name | ||
self.artworkURL = URL(string: link.images[0].url)! | ||
} | ||
} else { | ||
self.title = "Unknown" | ||
self.artworkURL = URL(string: "https://misc.scdn.co/liked-songs/liked-songs-640.png")! | ||
} | ||
} | ||
} | ||
} | ||
|
||
//struct ShortcutItem_Previews: PreviewProvider { | ||
// static var previews: some View { | ||
// ShortcutItem( | ||
// itemHeight: 80, | ||
// title: "Liked Songs", | ||
// imageURL: URL(string: "https://misc.scdn.co/liked-songs/liked-songs-640.png")! | ||
// ) | ||
// } | ||
//} |
Oops, something went wrong.