2021-07-28 04:10:04 +05:30
|
|
|
import Defaults
|
2021-07-28 02:56:52 +05:30
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct VideoView: View {
|
2021-09-25 13:48:22 +05:30
|
|
|
@EnvironmentObject<NavigationModel> private var navigation
|
2021-07-28 04:10:04 +05:30
|
|
|
|
|
|
|
#if os(iOS)
|
|
|
|
@Environment(\.verticalSizeClass) private var verticalSizeClass
|
|
|
|
#endif
|
|
|
|
|
2021-09-01 02:47:50 +05:30
|
|
|
@Environment(\.inNavigationView) private var inNavigationView
|
2021-09-19 02:06:42 +05:30
|
|
|
@Environment(\.horizontalCells) private var horizontalCells
|
2021-09-01 02:47:50 +05:30
|
|
|
|
2021-07-28 04:10:04 +05:30
|
|
|
var video: Video
|
|
|
|
|
2021-07-28 02:56:52 +05:30
|
|
|
var body: some View {
|
2021-09-01 02:47:50 +05:30
|
|
|
Group {
|
|
|
|
if inNavigationView {
|
|
|
|
NavigationLink(destination: VideoPlayerView(video)) {
|
|
|
|
content
|
|
|
|
}
|
|
|
|
} else {
|
2021-09-25 13:48:22 +05:30
|
|
|
Button(action: { navigation.playVideo(video) }) {
|
2021-09-01 02:47:50 +05:30
|
|
|
content
|
2021-08-03 02:40:22 +05:30
|
|
|
}
|
2021-07-28 04:10:04 +05:30
|
|
|
}
|
|
|
|
}
|
2021-09-27 03:58:42 +05:30
|
|
|
.buttonStyle(.plain)
|
2021-08-03 02:40:22 +05:30
|
|
|
.contentShape(RoundedRectangle(cornerRadius: 12))
|
|
|
|
.contextMenu { VideoContextMenuView(video: video) }
|
2021-08-02 04:31:24 +05:30
|
|
|
}
|
2021-07-28 04:10:04 +05:30
|
|
|
|
2021-09-01 02:47:50 +05:30
|
|
|
var content: some View {
|
|
|
|
VStack {
|
2021-09-27 03:58:42 +05:30
|
|
|
#if os(iOS)
|
|
|
|
if verticalSizeClass == .compact, !horizontalCells {
|
|
|
|
horizontalRow
|
|
|
|
.padding(.vertical, 4)
|
|
|
|
} else {
|
2021-09-01 02:47:50 +05:30
|
|
|
verticalRow
|
2021-09-27 03:58:42 +05:30
|
|
|
}
|
|
|
|
#else
|
|
|
|
verticalRow
|
|
|
|
#endif
|
2021-09-01 02:47:50 +05:30
|
|
|
}
|
|
|
|
#if os(macOS)
|
|
|
|
.background()
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-08-02 04:31:24 +05:30
|
|
|
var horizontalRow: some View {
|
2021-07-28 04:10:04 +05:30
|
|
|
HStack(alignment: .top, spacing: 2) {
|
2021-08-03 02:40:22 +05:30
|
|
|
Section {
|
|
|
|
#if os(tvOS)
|
|
|
|
thumbnailImage(quality: .medium)
|
|
|
|
#else
|
|
|
|
thumbnail
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
.frame(maxWidth: 320)
|
2021-07-28 04:10:04 +05:30
|
|
|
|
|
|
|
VStack(alignment: .leading, spacing: 0) {
|
2021-09-19 02:06:42 +05:30
|
|
|
videoDetail(video.title, lineLimit: 5)
|
2021-07-28 04:10:04 +05:30
|
|
|
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
|
|
|
|
|
2021-08-02 04:31:24 +05:30
|
|
|
videoDetail(video.author)
|
2021-07-28 04:10:04 +05:30
|
|
|
|
2021-09-19 02:06:42 +05:30
|
|
|
if additionalDetailsAvailable {
|
|
|
|
Spacer()
|
|
|
|
|
|
|
|
HStack {
|
|
|
|
if let date = video.publishedDate {
|
|
|
|
VStack {
|
|
|
|
Image(systemName: "calendar")
|
|
|
|
Text(date)
|
|
|
|
}
|
|
|
|
}
|
2021-07-28 04:10:04 +05:30
|
|
|
|
2021-09-19 02:06:42 +05:30
|
|
|
if video.views != 0 {
|
|
|
|
VStack {
|
|
|
|
Image(systemName: "eye")
|
|
|
|
Text(video.viewsCount!)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
}
|
2021-07-28 04:10:04 +05:30
|
|
|
}
|
|
|
|
.padding()
|
|
|
|
.frame(minHeight: 180)
|
|
|
|
|
2021-08-03 02:40:22 +05:30
|
|
|
#if os(tvOS)
|
|
|
|
if video.playTime != nil || video.live || video.upcoming {
|
2021-08-02 04:31:24 +05:30
|
|
|
Spacer()
|
2021-07-28 04:10:04 +05:30
|
|
|
|
2021-08-03 02:40:22 +05:30
|
|
|
VStack(alignment: .center) {
|
|
|
|
Spacer()
|
|
|
|
|
|
|
|
if let time = video.playTime {
|
|
|
|
HStack(spacing: 4) {
|
|
|
|
Image(systemName: "clock")
|
|
|
|
Text(time)
|
|
|
|
.fontWeight(.bold)
|
|
|
|
}
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
} else if video.live {
|
|
|
|
DetailBadge(text: "Live", style: .outstanding)
|
|
|
|
} else if video.upcoming {
|
|
|
|
DetailBadge(text: "Upcoming", style: .informational)
|
2021-07-28 04:10:04 +05:30
|
|
|
}
|
2021-08-02 04:31:24 +05:30
|
|
|
|
2021-08-03 02:40:22 +05:30
|
|
|
Spacer()
|
|
|
|
}
|
2021-07-28 04:10:04 +05:30
|
|
|
}
|
2021-08-03 02:40:22 +05:30
|
|
|
#endif
|
2021-07-28 04:10:04 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var verticalRow: some View {
|
2021-09-19 02:06:42 +05:30
|
|
|
VStack(alignment: .leading, spacing: 0) {
|
2021-08-02 04:31:24 +05:30
|
|
|
thumbnail
|
2021-07-28 04:10:04 +05:30
|
|
|
|
2021-09-25 13:48:22 +05:30
|
|
|
VStack(alignment: .leading, spacing: 0) {
|
2021-08-02 04:31:24 +05:30
|
|
|
videoDetail(video.title, lineLimit: additionalDetailsAvailable ? 2 : 3)
|
|
|
|
#if os(tvOS)
|
2021-08-03 02:40:22 +05:30
|
|
|
.frame(minHeight: additionalDetailsAvailable ? 80 : 120, alignment: .top)
|
|
|
|
#elseif os(macOS)
|
|
|
|
.frame(minHeight: 30, alignment: .top)
|
|
|
|
#else
|
|
|
|
.frame(minHeight: 50, alignment: .top)
|
2021-08-02 04:31:24 +05:30
|
|
|
#endif
|
2021-08-03 02:40:22 +05:30
|
|
|
.padding(.bottom)
|
2021-07-28 04:10:04 +05:30
|
|
|
|
2021-09-14 02:11:16 +05:30
|
|
|
Group {
|
|
|
|
if additionalDetailsAvailable {
|
2021-09-19 02:06:42 +05:30
|
|
|
HStack(spacing: 8) {
|
|
|
|
if let date = video.publishedDate {
|
|
|
|
Image(systemName: "calendar")
|
|
|
|
Text(date)
|
|
|
|
}
|
|
|
|
|
|
|
|
if video.views != 0 {
|
|
|
|
Image(systemName: "eye")
|
|
|
|
Text(video.viewsCount!)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.foregroundColor(.secondary)
|
2021-09-14 02:11:16 +05:30
|
|
|
} else {
|
|
|
|
Spacer()
|
|
|
|
}
|
2021-07-28 04:10:04 +05:30
|
|
|
}
|
2021-09-14 02:11:16 +05:30
|
|
|
.frame(minHeight: 30, alignment: .top)
|
2021-09-25 13:48:22 +05:30
|
|
|
#if os(tvOS)
|
|
|
|
.padding(.bottom, 10)
|
|
|
|
#endif
|
2021-07-28 04:10:04 +05:30
|
|
|
}
|
2021-09-19 02:06:42 +05:30
|
|
|
.padding(.top, 4)
|
|
|
|
.frame(minWidth: 0, maxWidth: .infinity, alignment: .topLeading)
|
2021-08-02 04:31:24 +05:30
|
|
|
#if os(tvOS)
|
2021-08-03 02:40:22 +05:30
|
|
|
.padding(.horizontal, 8)
|
2021-08-02 04:31:24 +05:30
|
|
|
#endif
|
2021-07-28 04:10:04 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var additionalDetailsAvailable: Bool {
|
|
|
|
video.publishedDate != nil || video.views != 0
|
|
|
|
}
|
|
|
|
|
2021-08-02 04:31:24 +05:30
|
|
|
var thumbnail: some View {
|
2021-08-01 03:40:56 +05:30
|
|
|
ZStack(alignment: .leading) {
|
2021-08-23 00:43:33 +05:30
|
|
|
thumbnailImage(quality: .maxresdefault)
|
2021-07-28 04:10:04 +05:30
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
|
|
|
|
HStack(alignment: .top) {
|
|
|
|
Spacer()
|
|
|
|
|
|
|
|
if let time = video.playTime {
|
|
|
|
DetailBadge(text: time, style: .prominent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding(10)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-02 04:31:24 +05:30
|
|
|
func thumbnailImage(quality: Thumbnail.Quality) -> some View {
|
2021-07-28 04:10:04 +05:30
|
|
|
Group {
|
|
|
|
if let url = video.thumbnailURL(quality: quality) {
|
|
|
|
AsyncImage(url: url) { image in
|
|
|
|
image
|
|
|
|
.resizable()
|
|
|
|
} placeholder: {
|
2021-09-19 23:01:21 +05:30
|
|
|
HStack {
|
|
|
|
ProgressView()
|
|
|
|
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
|
|
|
|
}
|
2021-07-28 04:10:04 +05:30
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Image(systemName: "exclamationmark.square")
|
|
|
|
}
|
|
|
|
}
|
2021-08-23 00:43:33 +05:30
|
|
|
.background(.gray)
|
|
|
|
.mask(RoundedRectangle(cornerRadius: 12))
|
2021-08-03 02:40:22 +05:30
|
|
|
#if os(tvOS)
|
2021-09-27 03:58:42 +05:30
|
|
|
.frame(minHeight: 320)
|
2021-08-03 02:40:22 +05:30
|
|
|
#endif
|
2021-09-19 02:06:42 +05:30
|
|
|
.modifier(AspectRatioModifier())
|
2021-07-28 04:10:04 +05:30
|
|
|
}
|
|
|
|
|
2021-08-02 04:31:24 +05:30
|
|
|
func videoDetail(_ text: String, lineLimit: Int = 1) -> some View {
|
2021-07-28 04:10:04 +05:30
|
|
|
Text(text)
|
2021-08-02 04:31:24 +05:30
|
|
|
.fontWeight(.bold)
|
2021-07-28 04:10:04 +05:30
|
|
|
.lineLimit(lineLimit)
|
|
|
|
.truncationMode(.middle)
|
2021-07-28 02:56:52 +05:30
|
|
|
}
|
2021-08-03 02:40:22 +05:30
|
|
|
|
2021-09-19 02:06:42 +05:30
|
|
|
struct AspectRatioModifier: ViewModifier {
|
|
|
|
@Environment(\.horizontalCells) private var horizontalCells
|
|
|
|
|
|
|
|
func body(content: Content) -> some View {
|
|
|
|
Group {
|
|
|
|
if horizontalCells {
|
|
|
|
content
|
|
|
|
} else {
|
|
|
|
content
|
|
|
|
.aspectRatio(1.777, contentMode: .fill)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-28 02:56:52 +05:30
|
|
|
}
|