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