2022-11-13 17:52:15 +00:00
|
|
|
import Defaults
|
|
|
|
import Foundation
|
|
|
|
import SDWebImageSwiftUI
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct VideoDetails: View {
|
|
|
|
enum DetailsPage: String, CaseIterable, Defaults.Serializable {
|
|
|
|
case info, inspector, chapters, comments, related, queue
|
|
|
|
}
|
|
|
|
|
2022-11-18 21:22:57 +00:00
|
|
|
@Binding var page: DetailsPage
|
2022-11-13 17:52:15 +00:00
|
|
|
@Binding var sidebarQueue: Bool
|
|
|
|
@Binding var fullScreen: Bool
|
|
|
|
var bottomPadding = false
|
|
|
|
|
|
|
|
@State private var subscribed = false
|
|
|
|
@State private var subscriptionToggleButtonDisabled = false
|
|
|
|
|
|
|
|
@Environment(\.navigationStyle) private var navigationStyle
|
|
|
|
#if os(iOS)
|
|
|
|
@Environment(\.verticalSizeClass) private var verticalSizeClass
|
|
|
|
#endif
|
|
|
|
|
|
|
|
@Environment(\.colorScheme) private var colorScheme
|
|
|
|
|
2022-11-24 20:36:05 +00:00
|
|
|
@ObservedObject private var accounts = AccountsModel.shared
|
|
|
|
let comments = CommentsModel.shared
|
|
|
|
@ObservedObject private var player = PlayerModel.shared
|
2022-11-13 17:52:15 +00:00
|
|
|
|
2022-11-18 21:43:16 +00:00
|
|
|
@Default(.enableReturnYouTubeDislike) private var enableReturnYouTubeDislike
|
2022-11-13 22:36:46 +00:00
|
|
|
@Default(.detailsToolbarPosition) private var detailsToolbarPosition
|
2022-11-13 17:52:15 +00:00
|
|
|
@Default(.playerSidebar) private var playerSidebar
|
|
|
|
|
|
|
|
var video: Video? {
|
|
|
|
player.currentVideo
|
|
|
|
}
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
VStack(alignment: .leading, spacing: 0) {
|
|
|
|
ControlsBar(
|
|
|
|
fullScreen: $fullScreen,
|
|
|
|
presentingControls: false,
|
|
|
|
backgroundEnabled: false,
|
|
|
|
borderTop: false,
|
|
|
|
detailsTogglePlayer: false,
|
|
|
|
detailsToggleFullScreen: true
|
|
|
|
)
|
|
|
|
|
|
|
|
VideoActions(video: video)
|
|
|
|
|
|
|
|
ZStack(alignment: .bottom) {
|
|
|
|
currentPage
|
2022-11-13 21:50:42 +00:00
|
|
|
.frame(maxWidth: detailsSize.width)
|
2022-11-13 17:52:15 +00:00
|
|
|
.transition(.fade)
|
|
|
|
|
|
|
|
HStack(alignment: .center) {
|
2022-11-13 22:36:46 +00:00
|
|
|
if detailsToolbarPosition.needsLeftSpacer { Spacer() }
|
|
|
|
|
2022-11-13 17:52:15 +00:00
|
|
|
VideoDetailsToolbar(video: video, page: $page, sidebarQueue: sidebarQueue)
|
2022-11-13 22:36:46 +00:00
|
|
|
|
|
|
|
if detailsToolbarPosition.needsRightSpacer { Spacer() }
|
2022-11-13 17:52:15 +00:00
|
|
|
}
|
2022-11-13 22:36:46 +00:00
|
|
|
.padding(.leading, detailsToolbarPosition == .left ? 10 : 0)
|
|
|
|
.padding(.trailing, detailsToolbarPosition == .right ? 10 : 0)
|
|
|
|
|
2022-11-13 17:52:15 +00:00
|
|
|
#if os(iOS)
|
2022-11-13 22:36:46 +00:00
|
|
|
.offset(y: bottomPadding ? -SafeArea.insets.bottom : 0)
|
2022-11-13 17:52:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
.onChange(of: player.currentItem) { newItem in
|
2022-11-19 13:21:53 +00:00
|
|
|
Delay.by(0.2) {
|
|
|
|
guard let newItem else {
|
|
|
|
page = sidebarQueue ? .inspector : .queue
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if let video = newItem.video {
|
|
|
|
page = video.isLocal ? .inspector : .info
|
|
|
|
} else {
|
|
|
|
page = sidebarQueue ? .inspector : .queue
|
|
|
|
}
|
2022-11-13 17:52:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.onAppear {
|
2022-11-18 21:22:57 +00:00
|
|
|
if video.isNil ||
|
|
|
|
!VideoDetailsTool.find(for: page)!.isAvailable(for: video!, sidebarQueue: sidebarQueue)
|
|
|
|
{
|
2022-11-19 13:21:53 +00:00
|
|
|
page = video == nil ? (sidebarQueue ? .inspector : .queue) : (video!.isLocal ? .inspector : .info)
|
2022-11-18 21:22:57 +00:00
|
|
|
}
|
2022-11-13 17:52:15 +00:00
|
|
|
|
|
|
|
guard video != nil, accounts.app.supportsSubscriptions else {
|
|
|
|
subscribed = false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.onChange(of: sidebarQueue) { queue in
|
|
|
|
if queue {
|
|
|
|
if page == .related || page == .queue {
|
|
|
|
page = video.isNil || video!.isLocal ? .inspector : .info
|
|
|
|
}
|
|
|
|
} else if video.isNil {
|
|
|
|
page = .inspector
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.overlay(GeometryReader { proxy in
|
|
|
|
Color.clear
|
|
|
|
.onAppear {
|
|
|
|
detailsSize = proxy.size
|
|
|
|
}
|
|
|
|
.onChange(of: proxy.size) { newSize in
|
|
|
|
detailsSize = newSize
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.background(colorScheme == .dark ? Color.black : .white)
|
|
|
|
}
|
|
|
|
|
|
|
|
private var contentItem: ContentItem {
|
|
|
|
ContentItem(video: player.currentVideo)
|
|
|
|
}
|
|
|
|
|
|
|
|
var currentPage: some View {
|
|
|
|
VStack {
|
|
|
|
switch page {
|
|
|
|
case .info:
|
|
|
|
detailsPage
|
|
|
|
|
|
|
|
case .inspector:
|
|
|
|
InspectorView(video: video)
|
|
|
|
|
|
|
|
case .chapters:
|
|
|
|
ChaptersView()
|
|
|
|
|
|
|
|
case .comments:
|
|
|
|
CommentsView(embedInScrollView: true)
|
|
|
|
.onAppear {
|
2022-11-19 12:12:29 +00:00
|
|
|
Delay.by(0.3) { comments.loadIfNeeded() }
|
2022-11-13 17:52:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case .related:
|
|
|
|
RelatedView()
|
|
|
|
|
|
|
|
case .queue:
|
|
|
|
PlayerQueueView(sidebarQueue: sidebarQueue, fullScreen: $fullScreen)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.contentShape(Rectangle())
|
2022-11-24 20:36:05 +00:00
|
|
|
.frame(maxHeight: .infinity)
|
2022-11-13 17:52:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@State private var detailsSize = CGSize.zero
|
|
|
|
|
|
|
|
var detailsPage: some View {
|
|
|
|
ScrollView(.vertical, showsIndicators: false) {
|
|
|
|
if let video {
|
|
|
|
VStack(alignment: .leading, spacing: 10) {
|
2022-11-13 20:55:19 +00:00
|
|
|
videoProperties
|
|
|
|
|
2022-11-13 17:52:15 +00:00
|
|
|
if !player.videoBeingOpened.isNil && (video.description.isNil || video.description!.isEmpty) {
|
|
|
|
VStack(alignment: .leading, spacing: 0) {
|
|
|
|
ForEach(1 ... Int.random(in: 2 ... 5), id: \.self) { _ in
|
|
|
|
Text(String(repeating: Video.fixture.description ?? "", count: Int.random(in: 1 ... 4)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.redacted(reason: .placeholder)
|
|
|
|
} else if video.description != nil, !video.description!.isEmpty {
|
|
|
|
VideoDescription(video: video, detailsSize: detailsSize)
|
|
|
|
#if os(iOS)
|
|
|
|
.padding(.bottom, player.playingFullScreen ? 10 : SafeArea.insets.bottom)
|
|
|
|
#endif
|
|
|
|
} else if !video.isLocal {
|
|
|
|
Text("No description")
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding(.top, 10)
|
|
|
|
.padding(.bottom, 60)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding(.horizontal)
|
|
|
|
}
|
2022-11-13 20:55:19 +00:00
|
|
|
|
|
|
|
@ViewBuilder var videoProperties: some View {
|
|
|
|
HStack(spacing: 2) {
|
|
|
|
publishedDateSection
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
|
|
|
|
HStack(spacing: 4) {
|
|
|
|
Image(systemName: "eye")
|
|
|
|
|
|
|
|
if let views = video?.viewsCount, player.videoBeingOpened.isNil {
|
|
|
|
Text(views)
|
|
|
|
} else {
|
2022-11-13 21:50:42 +00:00
|
|
|
if player.videoBeingOpened == nil {
|
|
|
|
Text("?")
|
|
|
|
} else {
|
|
|
|
Text("1,234M").redacted(reason: .placeholder)
|
|
|
|
}
|
2022-11-13 20:55:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Image(systemName: "hand.thumbsup")
|
|
|
|
|
|
|
|
if let likes = video?.likesCount, player.videoBeingOpened.isNil {
|
|
|
|
Text(likes)
|
|
|
|
} else {
|
2022-11-13 21:50:42 +00:00
|
|
|
if player.videoBeingOpened == nil {
|
|
|
|
Text("?")
|
|
|
|
} else {
|
|
|
|
Text("1,234M").redacted(reason: .placeholder)
|
|
|
|
}
|
2022-11-13 20:55:19 +00:00
|
|
|
}
|
|
|
|
|
2022-11-18 21:43:16 +00:00
|
|
|
if enableReturnYouTubeDislike {
|
2022-11-13 20:55:19 +00:00
|
|
|
Image(systemName: "hand.thumbsdown")
|
|
|
|
|
|
|
|
if let dislikes = video?.dislikesCount, player.videoBeingOpened.isNil {
|
|
|
|
Text(dislikes)
|
|
|
|
} else {
|
2022-11-13 21:50:42 +00:00
|
|
|
if player.videoBeingOpened == nil {
|
|
|
|
Text("?")
|
|
|
|
} else {
|
|
|
|
Text("1,234M").redacted(reason: .placeholder)
|
|
|
|
}
|
2022-11-13 20:55:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.font(.system(size: 12))
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
}
|
|
|
|
|
|
|
|
var publishedDateSection: some View {
|
|
|
|
Group {
|
|
|
|
if let video {
|
|
|
|
HStack(spacing: 4) {
|
|
|
|
if let published = video.publishedDate {
|
|
|
|
Text(published)
|
|
|
|
} else {
|
|
|
|
Text("1 century ago").redacted(reason: .placeholder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-13 17:52:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct VideoDetails_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2022-11-18 21:22:57 +00:00
|
|
|
VideoDetails(page: .constant(.info), sidebarQueue: .constant(true), fullScreen: .constant(false))
|
2022-11-13 17:52:15 +00:00
|
|
|
.injectFixtureEnvironmentObjects()
|
|
|
|
}
|
|
|
|
}
|