2022-08-21 02:35:40 +05:30
|
|
|
import Foundation
|
|
|
|
import SDWebImageSwiftUI
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct ChapterView: View {
|
|
|
|
var chapter: Chapter
|
|
|
|
|
2022-11-25 02:06:05 +05:30
|
|
|
var player = PlayerModel.shared
|
2022-08-21 02:35:40 +05:30
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
Button {
|
2022-08-28 22:48:49 +05:30
|
|
|
player.backend.seek(to: chapter.start, seekType: .userInteracted)
|
2022-08-21 02:35:40 +05:30
|
|
|
} label: {
|
2023-04-22 23:36:30 +05:30
|
|
|
Group {
|
|
|
|
#if os(tvOS)
|
|
|
|
horizontalChapter
|
|
|
|
#else
|
|
|
|
verticalChapter
|
|
|
|
#endif
|
2022-08-21 02:35:40 +05:30
|
|
|
}
|
|
|
|
.contentShape(Rectangle())
|
|
|
|
}
|
|
|
|
.buttonStyle(.plain)
|
|
|
|
}
|
|
|
|
|
2023-04-22 23:36:30 +05:30
|
|
|
var horizontalChapter: some View {
|
|
|
|
HStack(spacing: 12) {
|
|
|
|
if !chapter.image.isNil {
|
|
|
|
smallImage(chapter)
|
|
|
|
}
|
|
|
|
|
|
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
|
|
Text(chapter.title)
|
|
|
|
.font(.headline)
|
|
|
|
Text(chapter.start.formattedAsPlaybackTime(allowZero: true) ?? "")
|
|
|
|
.font(.system(.subheadline).monospacedDigit())
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
|
}
|
|
|
|
|
|
|
|
var verticalChapter: some View {
|
|
|
|
VStack(spacing: 12) {
|
|
|
|
if !chapter.image.isNil {
|
|
|
|
smallImage(chapter)
|
|
|
|
}
|
|
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
|
|
Text(chapter.title)
|
|
|
|
.lineLimit(2)
|
|
|
|
.multilineTextAlignment(.leading)
|
|
|
|
.font(.headline)
|
|
|
|
Text(chapter.start.formattedAsPlaybackTime(allowZero: true) ?? "")
|
|
|
|
.font(.system(.subheadline).monospacedDigit())
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
}
|
|
|
|
.frame(maxWidth: Self.thumbnailWidth, alignment: .leading)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-21 02:35:40 +05:30
|
|
|
@ViewBuilder func smallImage(_ chapter: Chapter) -> some View {
|
2022-11-10 23:41:19 +05:30
|
|
|
WebImage(url: chapter.image, options: [.lowPriority])
|
2022-09-12 01:03:08 +05:30
|
|
|
.resizable()
|
|
|
|
.placeholder {
|
|
|
|
ProgressView()
|
2022-08-21 02:35:40 +05:30
|
|
|
}
|
2022-09-12 01:03:08 +05:30
|
|
|
.indicator(.activity)
|
2023-04-22 23:36:30 +05:30
|
|
|
.frame(width: Self.thumbnailWidth, height: Self.thumbnailHeight)
|
2022-09-12 01:03:08 +05:30
|
|
|
#if os(tvOS)
|
|
|
|
.mask(RoundedRectangle(cornerRadius: 12))
|
|
|
|
#else
|
|
|
|
.mask(RoundedRectangle(cornerRadius: 6))
|
|
|
|
#endif
|
2022-08-21 02:35:40 +05:30
|
|
|
}
|
|
|
|
|
2023-04-22 23:36:30 +05:30
|
|
|
static var thumbnailWidth: Double {
|
|
|
|
250
|
|
|
|
}
|
|
|
|
|
|
|
|
static var thumbnailHeight: Double {
|
|
|
|
thumbnailWidth / 1.7777
|
2022-08-21 02:35:40 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ChapterView_Preview: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
ChapterView(chapter: .init(title: "Chapter", start: 30))
|
|
|
|
.injectFixtureEnvironmentObjects()
|
|
|
|
}
|
|
|
|
}
|