2021-12-27 02:44:46 +05:30
|
|
|
import CoreMedia
|
2021-11-06 01:27:22 +05:30
|
|
|
import Defaults
|
2021-10-06 01:50:09 +05:30
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct NowPlayingView: View {
|
2021-11-03 04:32:02 +05:30
|
|
|
enum ViewSection: CaseIterable {
|
2022-11-11 19:24:12 +05:30
|
|
|
case nowPlaying, playingNext, related, comments, chapters
|
2021-11-03 04:32:02 +05:30
|
|
|
}
|
|
|
|
|
2022-11-11 19:24:12 +05:30
|
|
|
var sections = [ViewSection.nowPlaying, .playingNext, .related]
|
2021-10-22 20:30:09 +05:30
|
|
|
var inInfoViewController = false
|
2021-10-06 01:50:09 +05:30
|
|
|
|
2021-12-05 01:05:41 +05:30
|
|
|
@State private var repliesID: Comment.ID?
|
|
|
|
|
2021-12-27 02:44:46 +05:30
|
|
|
@FetchRequest(sortDescriptors: [.init(key: "watchedAt", ascending: false)])
|
|
|
|
var watches: FetchedResults<Watch>
|
|
|
|
|
2022-11-25 02:06:05 +05:30
|
|
|
@ObservedObject private var comments = CommentsModel.shared
|
|
|
|
@ObservedObject private var player = PlayerModel.shared
|
2021-10-06 01:50:09 +05:30
|
|
|
|
2021-11-06 01:27:22 +05:30
|
|
|
@Default(.saveHistory) private var saveHistory
|
|
|
|
|
2021-10-06 01:50:09 +05:30
|
|
|
var body: some View {
|
2021-10-22 20:30:09 +05:30
|
|
|
if inInfoViewController {
|
2021-10-06 01:50:09 +05:30
|
|
|
content
|
|
|
|
.background(.thinMaterial)
|
|
|
|
.mask(RoundedRectangle(cornerRadius: 24))
|
|
|
|
} else {
|
|
|
|
content
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var content: some View {
|
2021-10-23 15:43:05 +05:30
|
|
|
List {
|
|
|
|
Group {
|
2021-11-03 04:32:02 +05:30
|
|
|
if sections.contains(.nowPlaying), let item = player.currentItem {
|
2021-10-23 15:43:05 +05:30
|
|
|
Section(header: Text("Now Playing")) {
|
2021-10-06 01:50:09 +05:30
|
|
|
Button {
|
2021-12-19 22:47:04 +05:30
|
|
|
player.show()
|
2021-10-06 01:50:09 +05:30
|
|
|
} label: {
|
|
|
|
VideoBanner(video: item.video)
|
|
|
|
}
|
2021-12-03 01:49:10 +05:30
|
|
|
.contextMenu {
|
|
|
|
Button("Close Video") {
|
|
|
|
player.closeCurrentItem()
|
|
|
|
}
|
|
|
|
|
|
|
|
Button("Cancel", role: .cancel) {}
|
|
|
|
}
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
|
|
|
.onPlayPauseCommand(perform: player.togglePlay)
|
|
|
|
}
|
|
|
|
|
2021-11-03 04:32:02 +05:30
|
|
|
if sections.contains(.playingNext) {
|
|
|
|
Section(header: Text("Playing Next")) {
|
|
|
|
if player.queue.isEmpty {
|
2022-09-26 21:00:59 +05:30
|
|
|
Text("Queue is empty")
|
2021-11-03 04:32:02 +05:30
|
|
|
.padding([.vertical, .leading], 40)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
}
|
2021-10-23 15:43:05 +05:30
|
|
|
|
2021-11-03 04:32:02 +05:30
|
|
|
ForEach(player.queue) { item in
|
|
|
|
Button {
|
|
|
|
player.advanceToItem(item)
|
2021-12-19 22:47:04 +05:30
|
|
|
player.show()
|
2021-11-03 04:32:02 +05:30
|
|
|
} label: {
|
|
|
|
VideoBanner(video: item.video)
|
|
|
|
}
|
|
|
|
.contextMenu {
|
2022-01-03 00:29:57 +05:30
|
|
|
Button("Remove", role: .destructive) {
|
2021-11-03 04:32:02 +05:30
|
|
|
player.remove(item)
|
|
|
|
}
|
2022-01-03 00:29:57 +05:30
|
|
|
|
|
|
|
Button("Remove All", role: .destructive) {
|
|
|
|
player.removeQueueItems()
|
|
|
|
}
|
2021-11-03 04:32:02 +05:30
|
|
|
}
|
2021-10-23 15:43:05 +05:30
|
|
|
}
|
2021-11-03 04:32:02 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-21 02:35:40 +05:30
|
|
|
if sections.contains(.related), let video = player.currentVideo, !video.related.isEmpty {
|
|
|
|
Section(header: Text("Related")) {
|
|
|
|
ForEach(video.related) { video in
|
2021-11-03 04:32:02 +05:30
|
|
|
Button {
|
2022-08-21 02:35:40 +05:30
|
|
|
player.play(video)
|
2021-11-03 04:32:02 +05:30
|
|
|
} label: {
|
|
|
|
VideoBanner(video: video)
|
|
|
|
}
|
|
|
|
.contextMenu {
|
2022-08-21 02:35:40 +05:30
|
|
|
VideoContextMenuView(video: video)
|
2021-10-23 15:43:05 +05:30
|
|
|
}
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-14 03:35:19 +05:30
|
|
|
|
2021-12-05 01:05:41 +05:30
|
|
|
if sections.contains(.comments) {
|
2022-01-05 21:42:32 +05:30
|
|
|
if comments.disabled {
|
2022-09-28 21:15:05 +05:30
|
|
|
NoCommentsView(text: "Comments are disabled".localized(), systemImage: "xmark.circle.fill")
|
2022-01-05 21:42:32 +05:30
|
|
|
} else if comments.loaded && comments.all.isEmpty {
|
2022-09-28 21:15:05 +05:30
|
|
|
NoCommentsView(text: "No comments".localized(), systemImage: "0.circle.fill")
|
2022-01-05 21:42:32 +05:30
|
|
|
} else if !comments.loaded {
|
2022-11-26 00:01:48 +05:30
|
|
|
VStack {
|
2021-12-30 00:09:38 +05:30
|
|
|
PlaceholderProgressView()
|
2021-12-18 01:16:49 +05:30
|
|
|
.onAppear {
|
2022-11-13 23:22:15 +05:30
|
|
|
comments.loadIfNeeded()
|
2021-12-18 01:16:49 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Section {
|
|
|
|
ForEach(comments.all) { comment in
|
|
|
|
CommentView(comment: comment, repliesID: $repliesID)
|
|
|
|
}
|
2022-01-05 21:42:32 +05:30
|
|
|
if comments.nextPageAvailable {
|
|
|
|
Text("Scroll to load more...")
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
.padding(.leading)
|
|
|
|
.onAppear {
|
|
|
|
comments.loadNextPage()
|
|
|
|
}
|
|
|
|
}
|
2021-12-05 01:05:41 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-21 02:35:40 +05:30
|
|
|
|
|
|
|
if sections.contains(.chapters) {
|
|
|
|
if let video = player.currentVideo {
|
|
|
|
if video.chapters.isEmpty {
|
2022-09-28 21:15:05 +05:30
|
|
|
NoCommentsView(text: "No chapters information available".localized(), systemImage: "xmark.circle.fill")
|
2022-08-21 02:35:40 +05:30
|
|
|
} else {
|
|
|
|
Section(header: Text("Chapters")) {
|
|
|
|
ForEach(video.chapters) { chapter in
|
2023-11-29 00:35:04 +05:30
|
|
|
ChapterViewTVOS(chapter: chapter)
|
2023-04-22 23:36:30 +05:30
|
|
|
.padding(.horizontal, 40)
|
2022-08-21 02:35:40 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
2021-10-23 15:43:05 +05:30
|
|
|
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 20))
|
|
|
|
.padding(.vertical, 20)
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
2021-10-23 15:43:05 +05:30
|
|
|
.padding(.horizontal, inInfoViewController ? 40 : 0)
|
|
|
|
.listStyle(.grouped)
|
|
|
|
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 560, maxHeight: .infinity, alignment: .leading)
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
|
|
|
|
2021-12-27 02:44:46 +05:30
|
|
|
private var visibleWatches: [Watch] {
|
|
|
|
watches.filter { $0.videoID != player.currentVideo?.videoID }
|
|
|
|
}
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
struct NowPlayingView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2022-08-21 02:35:40 +05:30
|
|
|
NowPlayingView(sections: [.chapters])
|
2021-10-06 01:50:09 +05:30
|
|
|
.injectFixtureEnvironmentObjects()
|
2021-10-22 20:30:09 +05:30
|
|
|
|
|
|
|
NowPlayingView(inInfoViewController: true)
|
|
|
|
.injectFixtureEnvironmentObjects()
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
|
|
|
}
|