1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-14 06:10:32 +05:30
yattee/tvOS/VideoDetailsView.swift

114 lines
3.8 KiB
Swift
Raw Normal View History

2021-07-08 04:09:18 +05:30
import Defaults
import Siesta
import SwiftUI
struct VideoDetailsView: View {
2021-07-12 02:22:49 +05:30
@Environment(\.dismiss) private var dismiss
@EnvironmentObject<NavigationState> private var navigationState
2021-07-08 04:09:18 +05:30
@ObservedObject private var store = Store<Video>()
2021-07-19 04:02:46 +05:30
@State private var playVideoLinkActive = false
2021-07-08 04:09:18 +05:30
var resource: Resource {
2021-07-12 02:22:49 +05:30
InvidiousAPI.shared.video(video.id)
2021-07-08 04:09:18 +05:30
}
2021-07-12 02:22:49 +05:30
var video: Video
init(_ video: Video) {
self.video = video
2021-07-08 04:09:18 +05:30
resource.addObserver(store)
}
var body: some View {
2021-07-19 04:02:46 +05:30
NavigationView {
HStack {
2021-07-12 02:22:49 +05:30
Spacer()
2021-07-19 04:02:46 +05:30
VStack {
Spacer()
ScrollView(.vertical, showsIndicators: false) {
if let video = store.item {
VStack(alignment: .center) {
ZStack(alignment: .bottom) {
Group {
2021-07-28 02:56:52 +05:30
if let url = video.thumbnailURL(quality: .maxres) {
AsyncImage(url: url) { image in
2021-07-19 04:02:46 +05:30
image
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 1600, height: 800)
2021-07-28 02:56:52 +05:30
} placeholder: {
ProgressView()
2021-07-19 04:02:46 +05:30
}
2021-07-12 02:22:49 +05:30
}
}
2021-07-19 04:02:46 +05:30
.frame(width: 1600, height: 800)
2021-07-12 02:22:49 +05:30
2021-07-19 04:02:46 +05:30
VStack(alignment: .leading) {
Text(video.title)
.font(.system(size: 40))
2021-07-08 04:09:18 +05:30
2021-07-19 04:02:46 +05:30
HStack {
playVideoButton
2021-07-08 04:09:18 +05:30
2021-07-19 04:02:46 +05:30
openChannelButton
2021-07-12 02:22:49 +05:30
}
2021-07-08 04:09:18 +05:30
}
2021-07-19 04:02:46 +05:30
.padding(40)
.frame(width: 1600, alignment: .leading)
.background(.thinMaterial)
2021-07-08 04:09:18 +05:30
}
2021-07-19 04:02:46 +05:30
.mask(RoundedRectangle(cornerRadius: 20))
VStack {
Text(video.description)
.lineLimit(nil)
.focusable()
}.frame(width: 1600, alignment: .leading)
2021-07-08 04:09:18 +05:30
}
}
}
2021-07-19 04:02:46 +05:30
Spacer()
2021-07-08 04:09:18 +05:30
}
2021-07-19 04:02:46 +05:30
2021-07-12 02:22:49 +05:30
Spacer()
2021-07-08 04:09:18 +05:30
}
}
2021-07-12 02:22:49 +05:30
.background(.thinMaterial)
2021-07-08 04:09:18 +05:30
.onAppear {
resource.loadIfNeeded()
}
2021-07-19 04:02:46 +05:30
2021-07-08 04:09:18 +05:30
.edgesIgnoringSafeArea(.all)
}
2021-07-19 04:02:46 +05:30
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-08 04:09:18 +05:30
var openChannelButton: some View {
2021-08-26 03:42:59 +05:30
let channel = video.channel
2021-07-08 04:09:18 +05:30
return Button("Open \(channel.name) channel") {
2021-07-12 02:22:49 +05:30
navigationState.openChannel(channel)
2021-09-14 02:11:16 +05:30
navigationState.tabSelection = .channel(channel.id)
2021-07-19 04:02:46 +05:30
navigationState.returnToDetails = true
2021-07-12 02:22:49 +05:30
dismiss()
2021-07-08 04:09:18 +05:30
}
}
}