2022-06-18 18:09:49 +05:30
|
|
|
import Foundation
|
|
|
|
import SDWebImageSwiftUI
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct ChaptersView: View {
|
2022-11-25 02:06:05 +05:30
|
|
|
@ObservedObject private var player = PlayerModel.shared
|
2023-11-21 19:55:22 +05:30
|
|
|
@Binding var expand: Bool
|
2022-06-18 18:09:49 +05:30
|
|
|
|
2023-04-22 23:36:30 +05:30
|
|
|
var chapters: [Chapter] {
|
|
|
|
player.videoForDisplay?.chapters ?? []
|
|
|
|
}
|
|
|
|
|
2023-04-24 15:38:58 +05:30
|
|
|
var chaptersHaveImages: Bool {
|
|
|
|
chapters.allSatisfy { $0.image != nil }
|
|
|
|
}
|
|
|
|
|
2022-06-18 18:09:49 +05:30
|
|
|
var body: some View {
|
2023-11-27 16:43:51 +05:30
|
|
|
if !chapters.isEmpty {
|
2023-11-27 18:48:43 +05:30
|
|
|
if chaptersHaveImages {
|
2023-11-27 16:43:51 +05:30
|
|
|
#if os(tvOS)
|
|
|
|
List {
|
|
|
|
Section {
|
2023-04-24 15:38:58 +05:30
|
|
|
ForEach(chapters) { chapter in
|
|
|
|
ChapterView(chapter: chapter)
|
|
|
|
}
|
|
|
|
}
|
2023-11-27 16:43:51 +05:30
|
|
|
.listRowBackground(Color.clear)
|
2023-04-24 15:38:58 +05:30
|
|
|
}
|
2023-11-27 16:43:51 +05:30
|
|
|
.listStyle(.plain)
|
|
|
|
#else
|
2023-11-27 18:48:43 +05:30
|
|
|
ScrollView(.horizontal) {
|
|
|
|
LazyHStack(spacing: 20) {
|
2023-11-28 21:15:36 +05:30
|
|
|
ForEach(Array(chapters.indices), id: \.self) { index in
|
|
|
|
let chapter = chapters[index]
|
|
|
|
let nextChapterStart: Double? = index < chapters.count - 1 ? chapters[index + 1].start : nil
|
|
|
|
ChapterView(chapter: chapter, nextChapterStart: nextChapterStart, chapterIndex: index)
|
2023-11-27 16:43:51 +05:30
|
|
|
}
|
2023-04-22 23:36:30 +05:30
|
|
|
}
|
2023-11-27 18:48:43 +05:30
|
|
|
.padding(.horizontal, 15)
|
2023-04-22 23:36:30 +05:30
|
|
|
}
|
2023-11-27 16:43:51 +05:30
|
|
|
#endif
|
2023-11-27 18:48:43 +05:30
|
|
|
} else if expand {
|
|
|
|
Section {
|
2023-11-28 21:15:36 +05:30
|
|
|
ForEach(Array(chapters.indices), id: \.self) { index in
|
|
|
|
let chapter = chapters[index]
|
|
|
|
let nextChapterStart: Double? = index < chapters.count - 1 ? chapters[index + 1].start : nil
|
|
|
|
ChapterView(chapter: chapter, nextChapterStart: nextChapterStart, chapterIndex: index)
|
2023-11-27 18:48:43 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding(.horizontal)
|
2023-11-27 16:43:51 +05:30
|
|
|
} else {
|
|
|
|
#if os(iOS)
|
|
|
|
Button(action: {
|
|
|
|
self.expand.toggle()
|
|
|
|
}) {
|
|
|
|
contents
|
|
|
|
}
|
|
|
|
#else
|
2023-11-26 19:45:30 +05:30
|
|
|
contents
|
2023-11-27 16:43:51 +05:30
|
|
|
#endif
|
|
|
|
}
|
2023-11-26 19:45:30 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var contents: some View {
|
|
|
|
Section {
|
2023-11-28 21:15:36 +05:30
|
|
|
ForEach(Array(chapters.prefix(3).indices), id: \.self) { index in
|
|
|
|
let chapter = chapters[index]
|
|
|
|
let nextChapterStart: Double? = index < chapters.count - 1 ? chapters[index + 1].start : nil
|
|
|
|
ChapterView(chapter: chapter, nextChapterStart: nextChapterStart, chapterIndex: index)
|
2023-11-26 19:45:30 +05:30
|
|
|
.allowsHitTesting(expand)
|
|
|
|
.opacity(index == 0 ? 1.0 : 0.3)
|
2023-11-21 19:55:22 +05:30
|
|
|
}
|
2022-06-25 05:09:29 +05:30
|
|
|
}
|
2023-11-26 19:45:30 +05:30
|
|
|
.padding(.horizontal)
|
2022-06-18 18:09:49 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-21 02:35:40 +05:30
|
|
|
struct ChaptersView_Previews: PreviewProvider {
|
2022-06-18 18:09:49 +05:30
|
|
|
static var previews: some View {
|
2023-11-21 19:55:22 +05:30
|
|
|
ChaptersView(expand: .constant(false))
|
2022-06-18 18:09:49 +05:30
|
|
|
.injectFixtureEnvironmentObjects()
|
|
|
|
}
|
|
|
|
}
|