yattee/Apple TV/VideoCellView.swift

109 lines
4.0 KiB
Swift
Raw Normal View History

2021-06-23 22:19:58 +00:00
import SwiftUI
struct VideoCellView: View {
2021-07-18 22:32:46 +00:00
@EnvironmentObject<NavigationState> private var navigationState
2021-06-23 22:19:58 +00:00
var video: Video
2021-06-28 10:43:07 +00:00
2021-06-23 22:19:58 +00:00
var body: some View {
2021-07-18 22:32:46 +00:00
Button(action: { navigationState.playVideo(video) }) {
2021-06-23 22:19:58 +00:00
VStack(alignment: .leading) {
2021-07-22 12:43:13 +00:00
ZStack {
2021-07-27 21:26:52 +00:00
if let url = video.thumbnailURL(quality: .high) {
AsyncImage(url: url) { image in
2021-06-23 22:19:58 +00:00
image
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 550, height: 310)
2021-07-27 21:26:52 +00:00
} placeholder: {
ProgressView()
2021-06-23 22:19:58 +00:00
}
.mask(RoundedRectangle(cornerRadius: 12))
} else {
Image(systemName: "exclamationmark.square")
.frame(width: 550, height: 310)
}
2021-07-22 12:43:13 +00:00
VStack {
HStack(alignment: .top) {
if video.live {
DetailBadge(text: "Live", style: .outstanding)
} else if video.upcoming {
DetailBadge(text: "Upcoming", style: .informational)
}
Spacer()
DetailBadge(text: video.author, style: .prominent)
}
.padding(10)
2021-07-11 20:52:49 +00:00
Spacer()
2021-07-22 12:43:13 +00:00
HStack(alignment: .top) {
Spacer()
if let time = video.playTime {
DetailBadge(text: time, style: .prominent)
}
2021-07-11 20:52:49 +00:00
}
2021-07-22 12:43:13 +00:00
.padding(10)
2021-06-23 22:19:58 +00:00
}
}
.frame(width: 550, height: 310)
VStack(alignment: .leading) {
Text(video.title)
.bold()
.lineLimit(2)
.multilineTextAlignment(.leading)
.padding(.horizontal)
.padding(.bottom, 2)
.frame(minHeight: 80, alignment: .top)
.truncationMode(.middle)
2021-07-22 12:43:13 +00:00
HStack(spacing: 8) {
if video.publishedDate != nil || video.views != 0 {
if let date = video.publishedDate {
2021-06-26 09:39:35 +00:00
Image(systemName: "calendar")
2021-07-22 12:43:13 +00:00
Text(date)
2021-06-26 09:39:35 +00:00
}
2021-06-23 22:19:58 +00:00
2021-06-26 09:39:35 +00:00
if video.views != 0 {
Image(systemName: "eye")
Text(video.viewsCount)
}
2021-07-22 12:43:13 +00:00
} else {
Section {
if video.live {
Image(systemName: "camera.fill")
Text("Premiering now")
} else {
Image(systemName: "questionmark.app.fill")
Text("date and views unavailable")
}
}
.opacity(0.6)
2021-06-23 22:19:58 +00:00
}
}
2021-07-22 12:43:13 +00:00
.padding([.horizontal, .bottom])
.foregroundColor(.secondary)
2021-06-23 22:19:58 +00:00
}
}
.frame(width: 550, alignment: .leading)
}
.buttonStyle(.plain)
.padding(.vertical)
}
}
2021-07-22 12:43:13 +00:00
struct VideoCellView_Preview: PreviewProvider {
static var previews: some View {
HStack {
VideoCellView(video: Video.fixture)
VideoCellView(video: Video.fixtureUpcomingWithoutPublishedOrViews)
VideoCellView(video: Video.fixtureLiveWithoutPublishedOrViews)
}
}
}