2021-11-03 23:14:09 +00:00
|
|
|
import Defaults
|
2021-08-22 19:13:33 +00:00
|
|
|
import Foundation
|
2021-12-17 20:01:05 +00:00
|
|
|
import SDWebImageSwiftUI
|
2021-08-22 19:13:33 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct VideoDetails: View {
|
2021-10-05 20:20:09 +00:00
|
|
|
enum Page {
|
2022-01-09 15:11:03 +00:00
|
|
|
case info, comments, related, queue
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Binding var sidebarQueue: Bool
|
|
|
|
@Binding var fullScreen: Bool
|
2021-08-25 22:12:59 +00:00
|
|
|
|
|
|
|
@State private var subscribed = false
|
2022-03-26 18:01:38 +00:00
|
|
|
@State private var subscriptionToggleButtonDisabled = false
|
2021-11-28 14:37:55 +00:00
|
|
|
@State private var presentingUnsubscribeAlert = false
|
2021-10-25 21:29:06 +00:00
|
|
|
@State private var presentingAddToPlaylist = false
|
2021-10-26 22:59:59 +00:00
|
|
|
@State private var presentingShareSheet = false
|
2021-11-13 15:45:47 +00:00
|
|
|
@State private var shareURL: URL?
|
2021-08-25 22:12:59 +00:00
|
|
|
|
2021-12-04 19:35:41 +00:00
|
|
|
@State private var currentPage = Page.info
|
2021-10-05 20:20:09 +00:00
|
|
|
|
2021-11-28 14:37:55 +00:00
|
|
|
@Environment(\.presentationMode) private var presentationMode
|
2021-10-28 17:14:55 +00:00
|
|
|
@Environment(\.inNavigationView) private var inNavigationView
|
2021-12-17 20:01:05 +00:00
|
|
|
@Environment(\.navigationStyle) private var navigationStyle
|
2021-10-05 20:20:09 +00:00
|
|
|
|
2021-10-20 22:21:50 +00:00
|
|
|
@EnvironmentObject<AccountsModel> private var accounts
|
2021-12-17 20:01:05 +00:00
|
|
|
@EnvironmentObject<NavigationModel> private var navigation
|
2021-10-05 20:20:09 +00:00
|
|
|
@EnvironmentObject<PlayerModel> private var player
|
2021-12-17 20:01:05 +00:00
|
|
|
@EnvironmentObject<RecentsModel> private var recents
|
2021-10-05 20:20:09 +00:00
|
|
|
@EnvironmentObject<SubscriptionsModel> private var subscriptions
|
|
|
|
|
2021-11-03 23:14:09 +00:00
|
|
|
@Default(.showKeywords) private var showKeywords
|
|
|
|
|
2021-10-05 20:20:09 +00:00
|
|
|
init(
|
|
|
|
sidebarQueue: Binding<Bool>? = nil,
|
|
|
|
fullScreen: Binding<Bool>? = nil
|
|
|
|
) {
|
|
|
|
_sidebarQueue = sidebarQueue ?? .constant(true)
|
|
|
|
_fullScreen = fullScreen ?? .constant(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
var video: Video? {
|
2021-12-26 21:14:46 +00:00
|
|
|
player.currentVideo
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
2021-08-22 19:13:33 +00:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
VStack(alignment: .leading) {
|
2021-10-05 20:20:09 +00:00
|
|
|
Group {
|
|
|
|
Group {
|
|
|
|
HStack(spacing: 0) {
|
|
|
|
title
|
2021-08-25 22:12:59 +00:00
|
|
|
|
2021-10-05 20:20:09 +00:00
|
|
|
toggleFullScreenDetailsButton
|
|
|
|
}
|
|
|
|
#if os(macOS)
|
2021-11-08 16:29:35 +00:00
|
|
|
.padding(.top, 10)
|
2021-10-05 20:20:09 +00:00
|
|
|
#endif
|
2021-08-22 19:13:33 +00:00
|
|
|
|
2021-10-05 20:20:09 +00:00
|
|
|
if !video.isNil {
|
|
|
|
Divider()
|
2021-08-25 22:12:59 +00:00
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
|
|
|
|
subscriptionsSection
|
2021-11-05 18:23:28 +00:00
|
|
|
.onChange(of: video) { video in
|
|
|
|
if let video = video {
|
|
|
|
subscribed = subscriptions.isSubscribing(video.channel.id)
|
|
|
|
}
|
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
.padding(.horizontal)
|
|
|
|
|
2021-12-17 20:01:05 +00:00
|
|
|
if !sidebarQueue ||
|
|
|
|
(CommentsModel.enabled && CommentsModel.placement == .separate)
|
|
|
|
{
|
2021-10-05 20:20:09 +00:00
|
|
|
pagePicker
|
|
|
|
.padding(.horizontal)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.contentShape(Rectangle())
|
|
|
|
.onSwipeGesture(
|
|
|
|
up: {
|
|
|
|
withAnimation {
|
|
|
|
fullScreen = true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
down: {
|
|
|
|
withAnimation {
|
|
|
|
if fullScreen {
|
|
|
|
fullScreen = false
|
|
|
|
} else {
|
2022-03-27 19:22:13 +00:00
|
|
|
self.player.hide()
|
2021-08-25 22:12:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
)
|
2021-08-22 19:13:33 +00:00
|
|
|
|
2021-10-05 20:20:09 +00:00
|
|
|
switch currentPage {
|
2021-12-04 19:35:41 +00:00
|
|
|
case .info:
|
2022-03-19 23:05:09 +00:00
|
|
|
ScrollView(.vertical, showsIndicators: false) {
|
|
|
|
detailsPage
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
case .queue:
|
2021-11-03 23:00:17 +00:00
|
|
|
PlayerQueueView(sidebarQueue: $sidebarQueue, fullScreen: $fullScreen)
|
2021-10-05 20:20:09 +00:00
|
|
|
.edgesIgnoringSafeArea(.horizontal)
|
2021-11-02 23:02:02 +00:00
|
|
|
|
|
|
|
case .related:
|
2021-11-03 23:00:17 +00:00
|
|
|
RelatedView()
|
|
|
|
.edgesIgnoringSafeArea(.horizontal)
|
2021-12-04 19:35:41 +00:00
|
|
|
case .comments:
|
2022-01-05 17:51:19 +00:00
|
|
|
CommentsView(embedInScrollView: true)
|
2021-12-04 19:35:41 +00:00
|
|
|
.edgesIgnoringSafeArea(.horizontal)
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-28 17:14:55 +00:00
|
|
|
.padding(.top, inNavigationView && fullScreen ? 10 : 0)
|
2021-10-05 20:20:09 +00:00
|
|
|
.onAppear {
|
2021-11-05 19:57:22 +00:00
|
|
|
if video.isNil && !sidebarQueue {
|
2021-11-03 23:00:17 +00:00
|
|
|
currentPage = .queue
|
|
|
|
}
|
2021-10-23 10:13:05 +00:00
|
|
|
|
2021-10-20 22:21:50 +00:00
|
|
|
guard video != nil, accounts.app.supportsSubscriptions else {
|
|
|
|
subscribed = false
|
2021-10-05 20:20:09 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2021-10-23 10:13:05 +00:00
|
|
|
.onChange(of: sidebarQueue) { queue in
|
2021-11-03 23:00:17 +00:00
|
|
|
if queue {
|
2022-01-09 15:11:03 +00:00
|
|
|
if currentPage == .related || currentPage == .queue {
|
2021-12-04 19:35:41 +00:00
|
|
|
currentPage = .info
|
2021-10-23 10:13:05 +00:00
|
|
|
}
|
2021-11-03 23:00:17 +00:00
|
|
|
} else if video.isNil {
|
|
|
|
currentPage = .queue
|
|
|
|
}
|
2021-10-23 10:13:05 +00:00
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
.edgesIgnoringSafeArea(.horizontal)
|
2022-01-05 17:51:19 +00:00
|
|
|
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .topLeading)
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var title: some View {
|
|
|
|
Group {
|
|
|
|
if video != nil {
|
|
|
|
Text(video!.title)
|
|
|
|
.onAppear {
|
2021-12-04 19:35:41 +00:00
|
|
|
currentPage = .info
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
2021-12-02 20:19:10 +00:00
|
|
|
.contextMenu {
|
|
|
|
Button {
|
|
|
|
player.closeCurrentItem()
|
|
|
|
if !sidebarQueue {
|
|
|
|
currentPage = .queue
|
2021-12-05 17:14:49 +00:00
|
|
|
} else {
|
|
|
|
currentPage = .info
|
2021-12-02 20:19:10 +00:00
|
|
|
}
|
|
|
|
} label: {
|
|
|
|
Label("Close Video", systemImage: "xmark.circle")
|
|
|
|
}
|
|
|
|
.disabled(player.currentItem.isNil)
|
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
|
|
|
|
.font(.title2.bold())
|
|
|
|
} else {
|
|
|
|
Text("Not playing")
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
}
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var toggleFullScreenDetailsButton: some View {
|
|
|
|
Button {
|
|
|
|
withAnimation {
|
|
|
|
fullScreen.toggle()
|
|
|
|
}
|
|
|
|
} label: {
|
|
|
|
Label("Resize", systemImage: fullScreen ? "chevron.down" : "chevron.up")
|
|
|
|
.labelStyle(.iconOnly)
|
|
|
|
}
|
|
|
|
.help("Toggle fullscreen details")
|
|
|
|
.buttonStyle(.plain)
|
|
|
|
.keyboardShortcut("t")
|
|
|
|
}
|
|
|
|
|
|
|
|
var subscriptionsSection: some View {
|
|
|
|
Group {
|
|
|
|
if video != nil {
|
|
|
|
HStack(alignment: .center) {
|
2021-12-17 20:01:05 +00:00
|
|
|
HStack(spacing: 10) {
|
|
|
|
Group {
|
|
|
|
ZStack(alignment: .bottomTrailing) {
|
|
|
|
authorAvatar
|
|
|
|
|
|
|
|
if subscribed {
|
|
|
|
Image(systemName: "star.circle.fill")
|
|
|
|
.background(Color.background)
|
|
|
|
.clipShape(Circle())
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
Text(video!.channel.name)
|
|
|
|
.font(.system(size: 14))
|
|
|
|
.bold()
|
|
|
|
|
2022-04-16 17:50:02 +00:00
|
|
|
Group {
|
|
|
|
if let subscribers = video!.channel.subscriptionsString {
|
|
|
|
Text("\(subscribers) subscribers")
|
2021-12-17 20:01:05 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-16 17:50:02 +00:00
|
|
|
.foregroundColor(.secondary)
|
|
|
|
.font(.caption2)
|
2021-12-17 20:01:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.contentShape(RoundedRectangle(cornerRadius: 12))
|
|
|
|
.contextMenu {
|
|
|
|
if let video = video {
|
|
|
|
Button(action: {
|
|
|
|
NavigationModel.openChannel(
|
|
|
|
video.channel,
|
|
|
|
player: player,
|
|
|
|
recents: recents,
|
|
|
|
navigation: navigation,
|
|
|
|
navigationStyle: navigationStyle
|
|
|
|
)
|
|
|
|
}) {
|
|
|
|
Label("\(video.channel.name) Channel", systemImage: "rectangle.stack.fill.badge.person.crop")
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-26 13:07:00 +00:00
|
|
|
if accounts.app.supportsSubscriptions, accounts.signedIn {
|
2021-10-20 22:21:50 +00:00
|
|
|
Spacer()
|
2021-10-05 20:20:09 +00:00
|
|
|
|
2021-10-20 22:21:50 +00:00
|
|
|
Section {
|
|
|
|
if subscribed {
|
2021-10-05 20:20:09 +00:00
|
|
|
Button("Unsubscribe") {
|
2021-11-28 14:37:55 +00:00
|
|
|
presentingUnsubscribeAlert = true
|
2021-10-20 22:21:50 +00:00
|
|
|
}
|
|
|
|
#if os(iOS)
|
2021-11-28 14:37:55 +00:00
|
|
|
.backport
|
2021-11-08 16:29:35 +00:00
|
|
|
.tint(.gray)
|
2021-10-20 22:21:50 +00:00
|
|
|
#endif
|
2021-11-28 14:37:55 +00:00
|
|
|
.alert(isPresented: $presentingUnsubscribeAlert) {
|
|
|
|
Alert(
|
|
|
|
title: Text(
|
2021-12-17 20:01:05 +00:00
|
|
|
"Are you sure you want to unsubscribe from \(video!.channel.name)?"
|
2021-11-28 14:37:55 +00:00
|
|
|
),
|
|
|
|
primaryButton: .destructive(Text("Unsubscribe")) {
|
2022-03-26 18:01:38 +00:00
|
|
|
subscriptionToggleButtonDisabled = true
|
2021-11-28 14:37:55 +00:00
|
|
|
|
2022-03-26 18:01:38 +00:00
|
|
|
subscriptions.unsubscribe(video!.channel.id) {
|
|
|
|
withAnimation {
|
|
|
|
subscriptionToggleButtonDisabled = false
|
|
|
|
subscribed.toggle()
|
|
|
|
}
|
2021-11-28 14:37:55 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
secondaryButton: .cancel()
|
|
|
|
)
|
2021-10-20 22:21:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Button("Subscribe") {
|
2022-03-26 18:01:38 +00:00
|
|
|
subscriptionToggleButtonDisabled = true
|
2021-10-05 20:20:09 +00:00
|
|
|
|
2022-03-26 18:01:38 +00:00
|
|
|
subscriptions.subscribe(video!.channel.id) {
|
|
|
|
withAnimation {
|
|
|
|
subscriptionToggleButtonDisabled = false
|
|
|
|
subscribed.toggle()
|
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-28 14:37:55 +00:00
|
|
|
.backport
|
2022-03-26 18:01:38 +00:00
|
|
|
.tint(subscriptionToggleButtonDisabled ? .gray : .blue)
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
2021-08-25 22:12:59 +00:00
|
|
|
}
|
2022-03-26 18:01:38 +00:00
|
|
|
.disabled(subscriptionToggleButtonDisabled)
|
2021-10-20 22:21:50 +00:00
|
|
|
.font(.system(size: 13))
|
|
|
|
.buttonStyle(.borderless)
|
2021-08-25 22:12:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-25 22:12:59 +00:00
|
|
|
|
2021-10-05 20:20:09 +00:00
|
|
|
var pagePicker: some View {
|
|
|
|
Picker("Page", selection: $currentPage) {
|
2021-11-03 23:00:17 +00:00
|
|
|
if !video.isNil {
|
2021-12-04 19:35:41 +00:00
|
|
|
Text("Info").tag(Page.info)
|
2021-12-06 18:11:19 +00:00
|
|
|
if CommentsModel.enabled, CommentsModel.placement == .separate {
|
2022-01-05 17:51:19 +00:00
|
|
|
Text("Comments").tag(Page.comments)
|
2021-12-04 19:35:41 +00:00
|
|
|
}
|
2021-12-06 18:11:19 +00:00
|
|
|
if !sidebarQueue {
|
|
|
|
Text("Related").tag(Page.related)
|
|
|
|
}
|
2021-12-04 19:35:41 +00:00
|
|
|
}
|
|
|
|
if !sidebarQueue {
|
|
|
|
Text("Queue").tag(Page.queue)
|
2021-11-03 23:00:17 +00:00
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
2021-11-03 23:00:17 +00:00
|
|
|
.labelsHidden()
|
2021-10-05 20:20:09 +00:00
|
|
|
.pickerStyle(.segmented)
|
|
|
|
.onDisappear {
|
2021-12-04 19:35:41 +00:00
|
|
|
currentPage = .info
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var publishedDateSection: some View {
|
|
|
|
Group {
|
2021-10-22 20:49:31 +00:00
|
|
|
if let video = player.currentVideo {
|
2021-10-05 20:20:09 +00:00
|
|
|
HStack(spacing: 4) {
|
|
|
|
if let published = video.publishedDate {
|
|
|
|
Text(published)
|
|
|
|
}
|
2021-08-22 19:13:33 +00:00
|
|
|
|
2021-11-28 14:37:55 +00:00
|
|
|
if let date = video.publishedAt {
|
2021-10-05 20:20:09 +00:00
|
|
|
if video.publishedDate != nil {
|
|
|
|
Text("•")
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
.opacity(0.3)
|
|
|
|
}
|
2021-11-28 14:37:55 +00:00
|
|
|
Text(formattedPublishedAt(date))
|
2021-08-22 19:13:33 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
.font(.system(size: 12))
|
|
|
|
.padding(.bottom, -1)
|
|
|
|
.foregroundColor(.secondary)
|
2021-08-22 19:13:33 +00:00
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-22 19:13:33 +00:00
|
|
|
|
2021-11-28 14:37:55 +00:00
|
|
|
func formattedPublishedAt(_ date: Date) -> String {
|
|
|
|
let dateFormatter = DateFormatter()
|
|
|
|
|
|
|
|
dateFormatter.dateStyle = .short
|
|
|
|
dateFormatter.timeStyle = .none
|
|
|
|
|
|
|
|
return dateFormatter.string(from: date)
|
|
|
|
}
|
|
|
|
|
2021-10-05 20:20:09 +00:00
|
|
|
var countsSection: some View {
|
|
|
|
Group {
|
2021-10-22 20:49:31 +00:00
|
|
|
if let video = player.currentVideo {
|
2021-10-05 20:20:09 +00:00
|
|
|
HStack {
|
2021-10-26 22:59:59 +00:00
|
|
|
ShareButton(
|
2021-11-10 22:05:59 +00:00
|
|
|
contentItem: contentItem,
|
2021-11-02 19:40:49 +00:00
|
|
|
presentingShareSheet: $presentingShareSheet,
|
|
|
|
shareURL: $shareURL
|
2021-10-26 22:59:59 +00:00
|
|
|
)
|
|
|
|
|
2021-10-05 20:20:09 +00:00
|
|
|
Spacer()
|
2021-08-25 22:12:59 +00:00
|
|
|
|
2021-10-05 20:20:09 +00:00
|
|
|
if let views = video.viewsCount {
|
2021-12-04 19:35:41 +00:00
|
|
|
videoDetail(label: "Views", value: views, symbol: "eye")
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
2021-08-25 22:12:59 +00:00
|
|
|
|
2021-10-05 20:20:09 +00:00
|
|
|
if let likes = video.likesCount {
|
|
|
|
Divider()
|
2022-01-05 17:51:19 +00:00
|
|
|
.frame(minHeight: 35)
|
2021-08-22 19:13:33 +00:00
|
|
|
|
2021-12-04 19:35:41 +00:00
|
|
|
videoDetail(label: "Likes", value: likes, symbol: "hand.thumbsup")
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
2021-08-25 22:12:59 +00:00
|
|
|
|
2021-10-05 20:20:09 +00:00
|
|
|
if let dislikes = video.dislikesCount {
|
|
|
|
Divider()
|
2022-01-05 17:51:19 +00:00
|
|
|
.frame(minHeight: 35)
|
2021-08-22 19:13:33 +00:00
|
|
|
|
2021-12-04 19:35:41 +00:00
|
|
|
videoDetail(label: "Dislikes", value: dislikes, symbol: "hand.thumbsdown")
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
2021-08-25 22:12:59 +00:00
|
|
|
|
2021-10-05 20:20:09 +00:00
|
|
|
Spacer()
|
2021-10-25 21:29:06 +00:00
|
|
|
|
2021-12-26 20:27:46 +00:00
|
|
|
Button {
|
|
|
|
presentingAddToPlaylist = true
|
|
|
|
} label: {
|
|
|
|
Label("Add to Playlist", systemImage: "text.badge.plus")
|
|
|
|
.labelStyle(.iconOnly)
|
|
|
|
.help("Add to Playlist...")
|
2021-10-25 21:29:06 +00:00
|
|
|
}
|
2021-12-26 20:27:46 +00:00
|
|
|
.buttonStyle(.plain)
|
|
|
|
.opacity(accounts.app.supportsUserPlaylists ? 1 : 0)
|
|
|
|
#if os(macOS)
|
|
|
|
.frame(minWidth: 35, alignment: .trailing)
|
|
|
|
#endif
|
2021-08-22 19:13:33 +00:00
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
.frame(maxHeight: 35)
|
|
|
|
.foregroundColor(.secondary)
|
2021-08-22 19:13:33 +00:00
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
2021-11-30 22:58:11 +00:00
|
|
|
.background(
|
|
|
|
EmptyView().sheet(isPresented: $presentingAddToPlaylist) {
|
|
|
|
if let video = video {
|
|
|
|
AddToPlaylistView(video: video)
|
|
|
|
}
|
2021-10-25 21:29:06 +00:00
|
|
|
}
|
2021-11-30 22:58:11 +00:00
|
|
|
)
|
2021-10-26 22:59:59 +00:00
|
|
|
#if os(iOS)
|
2021-11-30 22:58:11 +00:00
|
|
|
.background(
|
|
|
|
EmptyView().sheet(isPresented: $presentingShareSheet) {
|
|
|
|
if let shareURL = shareURL {
|
|
|
|
ShareSheet(activityItems: [shareURL])
|
|
|
|
}
|
2021-11-13 15:45:47 +00:00
|
|
|
}
|
2021-11-30 22:58:11 +00:00
|
|
|
)
|
2021-10-26 22:59:59 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
private var contentItem: ContentItem {
|
|
|
|
ContentItem(video: player.currentVideo!)
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
2021-08-25 22:12:59 +00:00
|
|
|
|
2021-12-17 20:01:05 +00:00
|
|
|
private var authorAvatar: some View {
|
|
|
|
Group {
|
|
|
|
if let video = video, let url = video.channel.thumbnailURL {
|
|
|
|
WebImage(url: url)
|
|
|
|
.resizable()
|
|
|
|
.placeholder {
|
|
|
|
Rectangle().fill(Color("PlaceholderColor"))
|
|
|
|
}
|
2021-12-24 19:21:11 +00:00
|
|
|
.retryOnAppear(true)
|
2021-12-17 20:01:05 +00:00
|
|
|
.indicator(.activity)
|
|
|
|
.clipShape(Circle())
|
|
|
|
.frame(width: 45, height: 45, alignment: .leading)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-05 20:20:09 +00:00
|
|
|
var detailsPage: some View {
|
|
|
|
Group {
|
2021-12-06 18:11:19 +00:00
|
|
|
Group {
|
2021-12-26 21:14:46 +00:00
|
|
|
if let video = player.currentVideo {
|
2022-01-05 17:51:19 +00:00
|
|
|
VStack(spacing: 6) {
|
2021-12-06 18:11:19 +00:00
|
|
|
HStack {
|
|
|
|
publishedDateSection
|
|
|
|
Spacer()
|
|
|
|
}
|
2021-08-22 19:13:33 +00:00
|
|
|
|
2021-12-06 18:11:19 +00:00
|
|
|
Divider()
|
2021-10-05 20:20:09 +00:00
|
|
|
|
2021-12-06 18:11:19 +00:00
|
|
|
countsSection
|
2021-08-22 19:13:33 +00:00
|
|
|
|
2022-01-05 17:51:19 +00:00
|
|
|
Divider()
|
|
|
|
}
|
2021-08-22 19:13:33 +00:00
|
|
|
|
2021-12-06 18:11:19 +00:00
|
|
|
VStack(alignment: .leading, spacing: 10) {
|
|
|
|
if let description = video.description {
|
|
|
|
Group {
|
|
|
|
if #available(iOS 15.0, macOS 12.0, tvOS 15.0, *) {
|
|
|
|
Text(description)
|
|
|
|
.textSelection(.enabled)
|
|
|
|
} else {
|
|
|
|
Text(description)
|
|
|
|
}
|
2021-11-28 14:37:55 +00:00
|
|
|
}
|
2021-12-06 18:11:19 +00:00
|
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
|
.font(.system(size: 14))
|
|
|
|
.lineSpacing(3)
|
|
|
|
} else {
|
|
|
|
Text("No description")
|
|
|
|
.foregroundColor(.secondary)
|
2021-11-28 14:37:55 +00:00
|
|
|
}
|
2021-08-22 19:13:33 +00:00
|
|
|
|
2021-12-06 18:11:19 +00:00
|
|
|
if showKeywords {
|
|
|
|
ScrollView(.horizontal, showsIndicators: showScrollIndicators) {
|
|
|
|
HStack {
|
|
|
|
ForEach(video.keywords, id: \.self) { keyword in
|
|
|
|
HStack(alignment: .center, spacing: 0) {
|
|
|
|
Text("#")
|
|
|
|
.font(.system(size: 11).bold())
|
|
|
|
|
|
|
|
Text(keyword)
|
|
|
|
.frame(maxWidth: 500)
|
|
|
|
}
|
|
|
|
.font(.caption)
|
|
|
|
.foregroundColor(.white)
|
|
|
|
.padding(.vertical, 4)
|
|
|
|
.padding(.horizontal, 8)
|
2021-12-29 18:40:25 +00:00
|
|
|
.background(Color("KeywordBackgroundColor"))
|
2021-12-06 18:11:19 +00:00
|
|
|
.mask(RoundedRectangle(cornerRadius: 3))
|
2021-11-03 23:14:09 +00:00
|
|
|
}
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
2021-12-06 18:11:19 +00:00
|
|
|
.padding(.bottom, 10)
|
2021-10-05 20:20:09 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-22 19:13:33 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-06 18:11:19 +00:00
|
|
|
|
|
|
|
if !video.isNil, CommentsModel.placement == .info {
|
|
|
|
Divider()
|
|
|
|
#if os(macOS)
|
|
|
|
.padding(.bottom, 20)
|
|
|
|
#else
|
|
|
|
.padding(.vertical, 10)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding(.horizontal)
|
|
|
|
|
2022-01-05 17:51:19 +00:00
|
|
|
LazyVStack {
|
2021-12-06 18:11:19 +00:00
|
|
|
if !video.isNil, CommentsModel.placement == .info {
|
|
|
|
CommentsView()
|
|
|
|
}
|
2021-08-22 19:13:33 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-25 22:12:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func videoDetail(label: String, value: String, symbol: String) -> some View {
|
|
|
|
VStack(spacing: 4) {
|
|
|
|
HStack(spacing: 2) {
|
|
|
|
Image(systemName: symbol)
|
|
|
|
|
|
|
|
Text(label.uppercased())
|
|
|
|
}
|
|
|
|
.font(.system(size: 9))
|
|
|
|
.opacity(0.6)
|
|
|
|
|
|
|
|
Text(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
.frame(maxWidth: 100)
|
2021-08-22 19:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var showScrollIndicators: Bool {
|
|
|
|
#if os(macOS)
|
|
|
|
false
|
|
|
|
#else
|
|
|
|
true
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-25 22:12:59 +00:00
|
|
|
struct VideoDetails_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2021-10-25 21:29:06 +00:00
|
|
|
VideoDetails(sidebarQueue: .constant(true))
|
2021-09-29 11:45:00 +00:00
|
|
|
.injectFixtureEnvironmentObjects()
|
2021-08-22 19:13:33 +00:00
|
|
|
}
|
|
|
|
}
|