yattee/tvOS/VideoDetailsView.swift

113 lines
3.7 KiB
Swift
Raw Normal View History

2021-07-07 22:39:18 +00:00
import Defaults
import Siesta
import SwiftUI
struct VideoDetailsView: View {
2021-07-11 20:52:49 +00:00
@Environment(\.dismiss) private var dismiss
@EnvironmentObject<NavigationState> private var navigationState
2021-07-07 22:39:18 +00:00
@ObservedObject private var store = Store<Video>()
2021-07-18 22:32:46 +00:00
@State private var playVideoLinkActive = false
2021-07-07 22:39:18 +00:00
var resource: Resource {
2021-07-11 20:52:49 +00:00
InvidiousAPI.shared.video(video.id)
2021-07-07 22:39:18 +00:00
}
2021-07-11 20:52:49 +00:00
var video: Video
init(_ video: Video) {
self.video = video
2021-07-07 22:39:18 +00:00
resource.addObserver(store)
}
var body: some View {
2021-07-18 22:32:46 +00:00
NavigationView {
HStack {
2021-07-11 20:52:49 +00:00
Spacer()
2021-07-18 22:32:46 +00:00
VStack {
Spacer()
ScrollView(.vertical, showsIndicators: false) {
if let video = store.item {
VStack(alignment: .center) {
ZStack(alignment: .bottom) {
Group {
2021-07-27 21:26:52 +00:00
if let url = video.thumbnailURL(quality: .maxres) {
AsyncImage(url: url) { image in
2021-07-18 22:32:46 +00:00
image
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 1600, height: 800)
2021-07-27 21:26:52 +00:00
} placeholder: {
ProgressView()
2021-07-18 22:32:46 +00:00
}
2021-07-11 20:52:49 +00:00
}
}
2021-07-18 22:32:46 +00:00
.frame(width: 1600, height: 800)
2021-07-11 20:52:49 +00:00
2021-07-18 22:32:46 +00:00
VStack(alignment: .leading) {
Text(video.title)
.font(.system(size: 40))
2021-07-07 22:39:18 +00:00
2021-07-18 22:32:46 +00:00
HStack {
playVideoButton
2021-07-07 22:39:18 +00:00
2021-07-18 22:32:46 +00:00
openChannelButton
2021-07-11 20:52:49 +00:00
}
2021-07-07 22:39:18 +00:00
}
2021-07-18 22:32:46 +00:00
.padding(40)
.frame(width: 1600, alignment: .leading)
.background(.thinMaterial)
2021-07-07 22:39:18 +00:00
}
2021-07-18 22:32:46 +00:00
.mask(RoundedRectangle(cornerRadius: 20))
VStack {
Text(video.description)
.lineLimit(nil)
.focusable()
}.frame(width: 1600, alignment: .leading)
2021-07-07 22:39:18 +00:00
}
}
}
2021-07-18 22:32:46 +00:00
Spacer()
2021-07-07 22:39:18 +00:00
}
2021-07-18 22:32:46 +00:00
2021-07-11 20:52:49 +00:00
Spacer()
2021-07-07 22:39:18 +00:00
}
}
2021-07-11 20:52:49 +00:00
.background(.thinMaterial)
2021-07-07 22:39:18 +00:00
.onAppear {
resource.loadIfNeeded()
}
2021-07-18 22:32:46 +00:00
2021-07-07 22:39:18 +00:00
.edgesIgnoringSafeArea(.all)
}
2021-07-18 22:32:46 +00:00
var playVideoButton: some View {
Button(action: {
navigationState.returnToDetails = true
playVideoLinkActive = true
}) {
HStack(spacing: 8) {
Image(systemName: "play.rectangle.fill")
Text("Play")
}
}
.background(NavigationLink(destination: VideoPlayerView(video), isActive: $playVideoLinkActive) { EmptyView() }.hidden())
}
2021-07-07 22:39:18 +00:00
var openChannelButton: some View {
let channel = Channel.from(video: store.item!)
return Button("Open \(channel.name) channel") {
2021-07-11 20:52:49 +00:00
navigationState.openChannel(channel)
2021-07-18 22:32:46 +00:00
navigationState.returnToDetails = true
2021-07-11 20:52:49 +00:00
dismiss()
2021-07-07 22:39:18 +00:00
}
}
}