2022-11-13 23:22:15 +05:30
|
|
|
import Defaults
|
|
|
|
import Foundation
|
|
|
|
import SDWebImageSwiftUI
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct VideoDetails: View {
|
2023-04-22 14:26:42 +05:30
|
|
|
struct TitleView: View {
|
|
|
|
@ObservedObject private var model = PlayerModel.shared
|
|
|
|
@State private var titleSize = CGSize.zero
|
|
|
|
|
|
|
|
var video: Video? { model.videoForDisplay }
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
HStack(spacing: 0) {
|
|
|
|
Text(model.videoForDisplay?.displayTitle ?? "Not playing")
|
|
|
|
.font(.title3.bold())
|
|
|
|
.lineLimit(4)
|
2022-12-19 03:04:22 +05:30
|
|
|
}
|
2023-04-22 14:26:42 +05:30
|
|
|
.padding(.vertical, 4)
|
2022-12-19 03:04:22 +05:30
|
|
|
}
|
2023-04-22 14:26:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
struct ChannelView: View {
|
|
|
|
@ObservedObject private var model = PlayerModel.shared
|
|
|
|
|
|
|
|
var video: Video? { model.videoForDisplay }
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
HStack {
|
|
|
|
Button {
|
|
|
|
guard let channel = video?.channel else { return }
|
|
|
|
NavigationModel.shared.openChannel(channel, navigationStyle: .sidebar)
|
|
|
|
} label: {
|
|
|
|
ChannelAvatarView(
|
|
|
|
channel: video?.channel,
|
|
|
|
video: video
|
|
|
|
)
|
|
|
|
.frame(maxWidth: 40, maxHeight: 40)
|
|
|
|
.padding(.trailing, 5)
|
|
|
|
}
|
|
|
|
.buttonStyle(.plain)
|
|
|
|
|
|
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
|
|
HStack {
|
|
|
|
Text(model.videoForDisplay?.channel.name ?? "Yattee")
|
|
|
|
.font(.subheadline)
|
|
|
|
.fontWeight(.semibold)
|
|
|
|
.lineLimit(1)
|
|
|
|
|
|
|
|
if let video, !video.isLocal {
|
|
|
|
Group {
|
|
|
|
Text("•")
|
|
|
|
|
|
|
|
HStack(spacing: 2) {
|
|
|
|
Image(systemName: "person.2.fill")
|
|
|
|
|
|
|
|
if let channel = model.videoForDisplay?.channel {
|
|
|
|
if let subscriptions = channel.subscriptionsString {
|
|
|
|
Text(subscriptions)
|
|
|
|
} else {
|
|
|
|
Text("1234").redacted(reason: .placeholder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.font(.caption2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
|
|
|
|
if video != nil {
|
|
|
|
VideoMetadataView()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct VideoMetadataView: View {
|
|
|
|
@ObservedObject private var model = PlayerModel.shared
|
|
|
|
@Default(.enableReturnYouTubeDislike) private var enableReturnYouTubeDislike
|
|
|
|
|
|
|
|
var video: Video? { model.videoForDisplay }
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
HStack(spacing: 4) {
|
|
|
|
publishedDateSection
|
|
|
|
|
|
|
|
Text("•")
|
|
|
|
|
|
|
|
HStack(spacing: 4) {
|
|
|
|
if model.videoBeingOpened != nil || video?.viewsCount != nil {
|
|
|
|
Image(systemName: "eye")
|
|
|
|
}
|
|
|
|
|
|
|
|
if let views = video?.viewsCount {
|
|
|
|
Text(views)
|
|
|
|
} else if model.videoBeingOpened != nil {
|
|
|
|
Text("1,234M").redacted(reason: .placeholder)
|
|
|
|
}
|
|
|
|
|
|
|
|
if model.videoBeingOpened != nil || video?.likesCount != nil {
|
|
|
|
Image(systemName: "hand.thumbsup")
|
|
|
|
}
|
|
|
|
|
2023-04-22 17:56:57 +05:30
|
|
|
if let likes = video?.likesCount, !likes.isEmpty {
|
2023-04-22 14:26:42 +05:30
|
|
|
Text(likes)
|
2023-04-22 17:56:57 +05:30
|
|
|
} else {
|
2023-04-22 14:26:42 +05:30
|
|
|
Text("1,234M").redacted(reason: .placeholder)
|
|
|
|
}
|
|
|
|
|
|
|
|
if enableReturnYouTubeDislike {
|
|
|
|
if model.videoBeingOpened != nil || video?.dislikesCount != nil {
|
|
|
|
Image(systemName: "hand.thumbsdown")
|
|
|
|
}
|
|
|
|
|
2023-04-22 17:56:57 +05:30
|
|
|
if let dislikes = video?.dislikesCount, !dislikes.isEmpty {
|
2023-04-22 14:26:42 +05:30
|
|
|
Text(dislikes)
|
2023-04-22 17:56:57 +05:30
|
|
|
} else {
|
2023-04-22 14:26:42 +05:30
|
|
|
Text("1,234M").redacted(reason: .placeholder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.font(.caption2)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum DetailsPage: String, CaseIterable, Defaults.Serializable {
|
|
|
|
case info, comments, queue
|
2022-12-19 03:04:22 +05:30
|
|
|
|
|
|
|
var title: String {
|
|
|
|
rawValue.capitalized.localized()
|
|
|
|
}
|
2022-11-13 23:22:15 +05:30
|
|
|
}
|
|
|
|
|
2022-12-18 04:38:30 +05:30
|
|
|
var video: Video?
|
|
|
|
|
2022-11-13 23:22:15 +05:30
|
|
|
@Binding var fullScreen: Bool
|
2023-04-22 14:26:42 +05:30
|
|
|
@Binding var sidebarQueue: Bool
|
2022-11-13 23:22:15 +05:30
|
|
|
|
2022-12-18 17:41:06 +05:30
|
|
|
@State private var detailsSize = CGSize.zero
|
2022-12-23 00:05:36 +05:30
|
|
|
@State private var detailsVisibility = Constants.detailsVisibility
|
2022-11-13 23:22:15 +05:30
|
|
|
@State private var subscribed = false
|
|
|
|
@State private var subscriptionToggleButtonDisabled = false
|
2022-12-19 03:04:22 +05:30
|
|
|
@State private var page = DetailsPage.info
|
2023-04-22 22:52:13 +05:30
|
|
|
@State private var descriptionExpanded = false
|
2022-11-13 23:22:15 +05:30
|
|
|
|
|
|
|
@Environment(\.navigationStyle) private var navigationStyle
|
|
|
|
#if os(iOS)
|
|
|
|
@Environment(\.verticalSizeClass) private var verticalSizeClass
|
|
|
|
#endif
|
|
|
|
|
|
|
|
@Environment(\.colorScheme) private var colorScheme
|
|
|
|
|
2022-11-25 02:06:05 +05:30
|
|
|
@ObservedObject private var accounts = AccountsModel.shared
|
|
|
|
let comments = CommentsModel.shared
|
2022-12-19 00:09:03 +05:30
|
|
|
@ObservedObject private var player = PlayerModel.shared
|
2022-11-13 23:22:15 +05:30
|
|
|
|
2022-11-19 03:13:16 +05:30
|
|
|
@Default(.enableReturnYouTubeDislike) private var enableReturnYouTubeDislike
|
2022-11-13 23:22:15 +05:30
|
|
|
@Default(.playerSidebar) private var playerSidebar
|
2023-04-22 14:26:42 +05:30
|
|
|
@Default(.showInspector) private var showInspector
|
2023-04-22 22:52:13 +05:30
|
|
|
@Default(.expandVideoDescription) private var expandVideoDescription
|
2022-11-13 23:22:15 +05:30
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
VStack(alignment: .leading, spacing: 0) {
|
2023-04-22 14:26:42 +05:30
|
|
|
VStack(alignment: .leading, spacing: 0) {
|
|
|
|
TitleView()
|
|
|
|
if video != nil, !video!.isLocal {
|
|
|
|
ChannelView()
|
|
|
|
.layoutPriority(1)
|
|
|
|
.padding(.bottom, 6)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
|
.contentShape(Rectangle())
|
|
|
|
.padding(.horizontal, 16)
|
|
|
|
#if !os(tvOS)
|
|
|
|
.tapRecognizer(
|
|
|
|
tapSensitivity: 0.2,
|
|
|
|
doubleTapAction: {
|
|
|
|
withAnimation(.default) {
|
|
|
|
fullScreen.toggle()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
#endif
|
2022-11-13 23:22:15 +05:30
|
|
|
|
2022-12-19 00:09:03 +05:30
|
|
|
VideoActions(video: player.videoForDisplay)
|
2023-04-22 14:26:42 +05:30
|
|
|
.padding(.vertical, 5)
|
|
|
|
.frame(maxHeight: 50)
|
|
|
|
.frame(maxWidth: .infinity)
|
|
|
|
.borderTop(height: 0.5, color: Color("ControlsBorderColor"))
|
|
|
|
.borderBottom(height: 0.5, color: Color("ControlsBorderColor"))
|
2022-12-18 04:38:30 +05:30
|
|
|
.animation(nil, value: player.currentItem)
|
2023-04-22 14:26:42 +05:30
|
|
|
.frame(minWidth: 0, maxWidth: .infinity)
|
2022-11-13 23:22:15 +05:30
|
|
|
|
2022-12-19 03:04:22 +05:30
|
|
|
pageView
|
2022-12-23 00:05:36 +05:30
|
|
|
#if os(iOS)
|
|
|
|
.opacity(detailsVisibility ? 1 : 0)
|
|
|
|
#endif
|
2022-11-13 23:22:15 +05:30
|
|
|
}
|
|
|
|
.overlay(GeometryReader { proxy in
|
|
|
|
Color.clear
|
|
|
|
.onAppear {
|
|
|
|
detailsSize = proxy.size
|
|
|
|
}
|
|
|
|
.onChange(of: proxy.size) { newSize in
|
2022-12-18 17:41:06 +05:30
|
|
|
guard !player.playingFullScreen else { return }
|
2022-11-13 23:22:15 +05:30
|
|
|
detailsSize = newSize
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.background(colorScheme == .dark ? Color.black : .white)
|
|
|
|
}
|
|
|
|
|
2022-12-18 17:41:06 +05:30
|
|
|
#if os(iOS)
|
|
|
|
private var maxWidth: Double {
|
|
|
|
let width = min(detailsSize.width, player.playerSize.width)
|
|
|
|
if width.isNormal, width > 0 {
|
|
|
|
return width
|
2022-11-13 23:22:15 +05:30
|
|
|
}
|
2022-12-18 17:41:06 +05:30
|
|
|
|
|
|
|
return 0
|
2022-11-13 23:22:15 +05:30
|
|
|
}
|
2022-12-18 17:41:06 +05:30
|
|
|
#endif
|
2022-11-13 23:22:15 +05:30
|
|
|
|
2022-12-18 17:41:06 +05:30
|
|
|
private var contentItem: ContentItem {
|
|
|
|
ContentItem(video: player.currentVideo)
|
|
|
|
}
|
2022-11-13 23:22:15 +05:30
|
|
|
|
2022-12-19 15:18:30 +05:30
|
|
|
@ViewBuilder var pageMenu: some View {
|
2022-12-19 03:04:22 +05:30
|
|
|
Picker("Page", selection: $page) {
|
2022-12-23 00:05:36 +05:30
|
|
|
ForEach(DetailsPage.allCases.filter { pageAvailable($0) }, id: \.rawValue) { page in
|
2023-04-22 14:26:42 +05:30
|
|
|
Text(page.title).tag(page)
|
2022-11-13 23:22:15 +05:30
|
|
|
}
|
|
|
|
}
|
2023-04-22 14:26:42 +05:30
|
|
|
.pickerStyle(.segmented)
|
|
|
|
.labelsHidden()
|
2022-12-19 03:04:22 +05:30
|
|
|
}
|
|
|
|
|
2022-12-23 00:05:36 +05:30
|
|
|
func pageAvailable(_ page: DetailsPage) -> Bool {
|
|
|
|
guard let video else { return false }
|
|
|
|
|
|
|
|
switch page {
|
2023-04-22 14:26:42 +05:30
|
|
|
case .queue:
|
2023-04-22 20:03:08 +05:30
|
|
|
return !sidebarQueue && player.isAdvanceToNextItemAvailable
|
2022-12-23 00:05:36 +05:30
|
|
|
default:
|
|
|
|
return !video.isLocal
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-19 03:04:22 +05:30
|
|
|
var pageView: some View {
|
2023-04-22 20:19:45 +05:30
|
|
|
ScrollView(.vertical, showsIndicators: false) {
|
|
|
|
LazyVStack {
|
|
|
|
pageMenu
|
|
|
|
.padding(5)
|
|
|
|
|
|
|
|
switch page {
|
|
|
|
case .info:
|
|
|
|
Group {
|
|
|
|
if let video {
|
|
|
|
VStack(alignment: .leading, spacing: 10) {
|
|
|
|
if !player.videoBeingOpened.isNil && (video.description.isNil || video.description!.isEmpty) {
|
|
|
|
VStack {
|
|
|
|
ProgressView()
|
|
|
|
.progressViewStyle(.circular)
|
2023-04-22 14:26:42 +05:30
|
|
|
}
|
2023-04-22 20:19:45 +05:30
|
|
|
.frame(maxWidth: .infinity)
|
|
|
|
} else if let description = video.description, !description.isEmpty {
|
2023-04-22 22:52:13 +05:30
|
|
|
Section(header: descriptionHeader) {
|
|
|
|
VideoDescription(video: video, detailsSize: detailsSize, expand: $descriptionExpanded)
|
|
|
|
}
|
2023-04-22 20:19:45 +05:30
|
|
|
} else if !video.isLocal {
|
|
|
|
Text("No description")
|
|
|
|
.font(.caption)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
}
|
2023-04-22 14:26:42 +05:30
|
|
|
|
2023-04-22 20:19:45 +05:30
|
|
|
if video.isLocal || showInspector == .always {
|
|
|
|
InspectorView(video: player.videoForDisplay)
|
|
|
|
}
|
2023-04-22 14:26:42 +05:30
|
|
|
|
2023-04-22 20:19:45 +05:30
|
|
|
if !sidebarQueue,
|
|
|
|
!(player.videoForDisplay?.related.isEmpty ?? true)
|
|
|
|
{
|
|
|
|
RelatedView()
|
|
|
|
.padding(.top, 20)
|
2022-12-19 03:04:22 +05:30
|
|
|
}
|
|
|
|
}
|
2023-04-22 20:19:45 +05:30
|
|
|
.padding(.bottom, 60)
|
2022-12-19 03:04:22 +05:30
|
|
|
}
|
2023-04-22 20:19:45 +05:30
|
|
|
}
|
|
|
|
.onAppear {
|
|
|
|
if video != nil, !pageAvailable(page) {
|
2023-04-22 14:26:42 +05:30
|
|
|
page = .info
|
|
|
|
}
|
2023-04-22 20:19:45 +05:30
|
|
|
}
|
|
|
|
.transition(.opacity)
|
|
|
|
.animation(nil, value: player.currentItem)
|
|
|
|
.padding(.horizontal)
|
|
|
|
#if os(iOS)
|
|
|
|
.frame(maxWidth: YatteeApp.isForPreviews ? .infinity : maxWidth)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case .queue:
|
|
|
|
PlayerQueueView(sidebarQueue: false)
|
|
|
|
.padding(.horizontal)
|
|
|
|
|
|
|
|
case .comments:
|
|
|
|
CommentsView(embedInScrollView: false)
|
2023-04-22 14:26:42 +05:30
|
|
|
.onAppear {
|
2023-04-22 20:19:45 +05:30
|
|
|
comments.loadIfNeeded()
|
2022-12-23 00:05:36 +05:30
|
|
|
}
|
2022-12-19 03:04:22 +05:30
|
|
|
}
|
2022-12-18 17:41:06 +05:30
|
|
|
}
|
|
|
|
}
|
2023-04-22 14:26:42 +05:30
|
|
|
#if os(iOS)
|
|
|
|
.onAppear {
|
|
|
|
if fullScreen {
|
|
|
|
if let video, video.isLocal {
|
|
|
|
page = .info
|
2022-11-14 02:25:19 +05:30
|
|
|
}
|
2023-04-22 14:26:42 +05:30
|
|
|
detailsVisibility = true
|
|
|
|
return
|
2022-11-14 02:25:19 +05:30
|
|
|
}
|
2023-04-22 14:26:42 +05:30
|
|
|
Delay.by(0.8) { withAnimation(.easeIn(duration: 0.25)) { self.detailsVisibility = true } }
|
2022-11-14 02:25:19 +05:30
|
|
|
}
|
2023-04-22 14:26:42 +05:30
|
|
|
#endif
|
2022-11-14 02:25:19 +05:30
|
|
|
|
2023-04-22 14:26:42 +05:30
|
|
|
.onChange(of: player.queue) { _ in
|
|
|
|
if video != nil, !pageAvailable(page) {
|
|
|
|
page = .info
|
2022-11-14 02:25:19 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-04-22 22:52:13 +05:30
|
|
|
|
|
|
|
var descriptionHeader: some View {
|
|
|
|
HStack {
|
|
|
|
Text("Description".localized())
|
|
|
|
|
|
|
|
if !expandVideoDescription, !descriptionExpanded {
|
|
|
|
Spacer()
|
|
|
|
Image(systemName: "arrow.up.and.down")
|
|
|
|
.imageScale(.small)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.font(.caption)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
}
|
2022-11-13 23:22:15 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
struct VideoDetails_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2023-04-22 14:26:42 +05:30
|
|
|
VideoDetails(video: .fixture, fullScreen: .constant(false), sidebarQueue: .constant(false))
|
2022-11-13 23:22:15 +05:30
|
|
|
}
|
|
|
|
}
|