2022-09-01 16:51:59 +00:00
|
|
|
import CachedAsyncImage
|
2022-08-20 21:05:40 +00:00
|
|
|
import Foundation
|
|
|
|
import SDWebImageSwiftUI
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct ChapterView: View {
|
|
|
|
var chapter: Chapter
|
|
|
|
|
|
|
|
@EnvironmentObject<PlayerModel> private var player
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
Button {
|
2022-08-28 17:18:49 +00:00
|
|
|
player.backend.seek(to: chapter.start, seekType: .userInteracted)
|
2022-08-20 21:05:40 +00:00
|
|
|
} label: {
|
|
|
|
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)
|
|
|
|
.contentShape(Rectangle())
|
|
|
|
}
|
|
|
|
.buttonStyle(.plain)
|
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder func smallImage(_ chapter: Chapter) -> some View {
|
2022-09-01 23:19:30 +00:00
|
|
|
Group {
|
|
|
|
if #available(iOS 15, macOS 12, *) {
|
|
|
|
CachedAsyncImage(url: chapter.image) { image in
|
|
|
|
image
|
|
|
|
.resizable()
|
|
|
|
} placeholder: {
|
|
|
|
Rectangle().foregroundColor(Color("PlaceholderColor"))
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
WebImage(url: chapter.image)
|
2022-08-31 19:24:46 +00:00
|
|
|
.resizable()
|
2022-09-01 23:19:30 +00:00
|
|
|
.placeholder {
|
|
|
|
ProgressView()
|
|
|
|
}
|
|
|
|
.indicator(.activity)
|
2022-08-20 21:05:40 +00:00
|
|
|
}
|
2022-08-31 19:24:46 +00:00
|
|
|
}
|
2022-09-01 23:19:30 +00:00
|
|
|
#if os(tvOS)
|
|
|
|
.frame(width: thumbnailWidth, height: 140)
|
|
|
|
.mask(RoundedRectangle(cornerRadius: 12))
|
|
|
|
#else
|
|
|
|
.frame(width: thumbnailWidth, height: 60)
|
|
|
|
.mask(RoundedRectangle(cornerRadius: 6))
|
|
|
|
#endif
|
2022-08-20 21:05:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private var thumbnailWidth: Double {
|
|
|
|
#if os(tvOS)
|
|
|
|
250
|
|
|
|
#else
|
|
|
|
100
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ChapterView_Preview: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
ChapterView(chapter: .init(title: "Chapter", start: 30))
|
|
|
|
.injectFixtureEnvironmentObjects()
|
|
|
|
}
|
|
|
|
}
|