2022-04-17 15:04:26 +05:30
|
|
|
import CoreMedia
|
2021-07-28 04:10:04 +05:30
|
|
|
import Defaults
|
2021-10-22 04:59:10 +05:30
|
|
|
import SDWebImageSwiftUI
|
2021-07-28 02:56:52 +05:30
|
|
|
import SwiftUI
|
|
|
|
|
2021-10-22 04:59:10 +05:30
|
|
|
struct VideoCell: View {
|
2022-12-11 21:49:21 +05:30
|
|
|
var id: String?
|
2021-12-27 02:44:46 +05:30
|
|
|
private var video: Video
|
2021-10-06 01:50:09 +05:30
|
|
|
|
2022-08-26 05:08:04 +05:30
|
|
|
@Environment(\.horizontalCells) private var horizontalCells
|
2022-05-29 23:56:56 +05:30
|
|
|
@Environment(\.inChannelView) private var inChannelView
|
2022-08-26 05:08:04 +05:30
|
|
|
@Environment(\.navigationStyle) private var navigationStyle
|
2021-07-28 04:10:04 +05:30
|
|
|
|
|
|
|
#if os(iOS)
|
|
|
|
@Environment(\.verticalSizeClass) private var verticalSizeClass
|
|
|
|
#endif
|
|
|
|
|
2022-12-09 05:45:19 +05:30
|
|
|
@ObservedObject private var thumbnails = ThumbnailsModel.shared
|
2021-07-28 04:10:04 +05:30
|
|
|
|
2021-11-05 04:55:51 +05:30
|
|
|
@Default(.channelOnThumbnail) private var channelOnThumbnail
|
|
|
|
@Default(.timeOnThumbnail) private var timeOnThumbnail
|
2022-01-06 20:26:59 +05:30
|
|
|
@Default(.roundedThumbnails) private var roundedThumbnails
|
2021-12-27 02:44:46 +05:30
|
|
|
@Default(.saveHistory) private var saveHistory
|
|
|
|
@Default(.showWatchingProgress) private var showWatchingProgress
|
|
|
|
@Default(.watchedVideoStyle) private var watchedVideoStyle
|
2022-01-03 01:09:19 +05:30
|
|
|
@Default(.watchedVideoBadgeColor) private var watchedVideoBadgeColor
|
2021-12-27 02:44:46 +05:30
|
|
|
@Default(.watchedVideoPlayNowBehavior) private var watchedVideoPlayNowBehavior
|
2021-11-05 04:55:51 +05:30
|
|
|
|
2022-09-01 03:30:28 +05:30
|
|
|
private var navigation: NavigationModel { .shared }
|
|
|
|
private var player: PlayerModel { .shared }
|
|
|
|
|
2021-12-27 02:44:46 +05:30
|
|
|
@FetchRequest private var watchRequest: FetchedResults<Watch>
|
2021-10-06 01:50:09 +05:30
|
|
|
|
2022-12-11 21:49:21 +05:30
|
|
|
init(id: String? = nil, video: Video) {
|
|
|
|
self.id = id
|
2021-12-27 02:44:46 +05:30
|
|
|
self.video = video
|
|
|
|
_watchRequest = video.watchFetchRequest
|
|
|
|
}
|
2021-10-28 22:44:55 +05:30
|
|
|
|
2021-12-27 02:44:46 +05:30
|
|
|
var body: some View {
|
2022-08-13 20:16:45 +05:30
|
|
|
Button(action: playAction) {
|
|
|
|
content
|
2022-08-26 05:08:04 +05:30
|
|
|
#if os(tvOS)
|
2022-12-14 17:26:47 +05:30
|
|
|
.frame(width: 580, height: channelOnThumbnail ? 470 : 500)
|
2022-08-26 05:08:04 +05:30
|
|
|
#endif
|
2021-07-28 04:10:04 +05:30
|
|
|
}
|
2021-12-27 02:44:46 +05:30
|
|
|
.opacity(contentOpacity)
|
2022-08-26 05:08:04 +05:30
|
|
|
#if os(tvOS)
|
|
|
|
.buttonStyle(.card)
|
|
|
|
#else
|
|
|
|
.buttonStyle(.plain)
|
|
|
|
#endif
|
|
|
|
.contentShape(RoundedRectangle(cornerRadius: thumbnailRoundingCornerRadius))
|
|
|
|
.contextMenu {
|
|
|
|
VideoContextMenuView(video: video)
|
|
|
|
}
|
2022-12-11 21:49:21 +05:30
|
|
|
.id(id ?? video.videoID)
|
2021-08-02 04:31:24 +05:30
|
|
|
}
|
2021-07-28 04:10:04 +05:30
|
|
|
|
2022-01-06 20:26:59 +05:30
|
|
|
private var thumbnailRoundingCornerRadius: Double {
|
|
|
|
#if os(tvOS)
|
|
|
|
return Double(12)
|
|
|
|
#else
|
|
|
|
return Double(roundedThumbnails ? 12 : 0)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-12-27 02:44:46 +05:30
|
|
|
private func playAction() {
|
2022-04-17 15:04:26 +05:30
|
|
|
DispatchQueue.main.async {
|
|
|
|
guard video.videoID != Video.fixtureID else {
|
|
|
|
return
|
2021-12-27 02:44:46 +05:30
|
|
|
}
|
|
|
|
|
2022-06-08 02:57:48 +05:30
|
|
|
if player.musicMode {
|
|
|
|
player.toggleMusicMode()
|
|
|
|
}
|
|
|
|
|
2022-04-17 15:04:26 +05:30
|
|
|
if watchingNow {
|
|
|
|
if !player.playingInPictureInPicture {
|
|
|
|
player.show()
|
|
|
|
}
|
2021-12-27 02:44:46 +05:30
|
|
|
|
2022-04-17 15:04:26 +05:30
|
|
|
if !playNowContinues {
|
2022-08-28 22:48:49 +05:30
|
|
|
player.backend.seek(to: .zero, seekType: .userInteracted)
|
2022-04-17 15:04:26 +05:30
|
|
|
}
|
2021-12-27 02:44:46 +05:30
|
|
|
|
2022-04-17 15:04:26 +05:30
|
|
|
player.play()
|
2021-12-27 02:44:46 +05:30
|
|
|
|
2022-04-17 15:04:26 +05:30
|
|
|
return
|
|
|
|
}
|
2021-12-27 02:44:46 +05:30
|
|
|
|
2022-04-17 15:04:26 +05:30
|
|
|
var playAt: CMTime?
|
2021-12-27 02:44:46 +05:30
|
|
|
|
2022-05-29 19:08:48 +05:30
|
|
|
if saveHistory,
|
|
|
|
playNowContinues,
|
2022-04-17 15:04:26 +05:30
|
|
|
!watch.isNil,
|
|
|
|
!watch!.finished
|
|
|
|
{
|
|
|
|
playAt = .secondsInDefaultTimescale(watch!.stoppedAt)
|
|
|
|
}
|
|
|
|
|
2022-05-22 02:28:11 +05:30
|
|
|
player.avPlayerBackend.startPictureInPictureOnPlay = player.playingInPictureInPicture
|
|
|
|
|
2022-05-29 03:11:23 +05:30
|
|
|
player.play(video, at: playAt)
|
2022-04-17 15:04:26 +05:30
|
|
|
}
|
2021-12-27 02:44:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
private var playNowContinues: Bool {
|
|
|
|
watchedVideoPlayNowBehavior == .continue
|
|
|
|
}
|
|
|
|
|
|
|
|
private var watch: Watch? {
|
|
|
|
watchRequest.first
|
|
|
|
}
|
|
|
|
|
|
|
|
private var finished: Bool {
|
|
|
|
watch?.finished ?? false
|
|
|
|
}
|
|
|
|
|
|
|
|
private var watchingNow: Bool {
|
|
|
|
player.currentVideo == video
|
|
|
|
}
|
|
|
|
|
|
|
|
private var content: some View {
|
2021-09-01 02:47:50 +05:30
|
|
|
VStack {
|
2021-09-27 03:58:42 +05:30
|
|
|
#if os(iOS)
|
|
|
|
if verticalSizeClass == .compact, !horizontalCells {
|
|
|
|
horizontalRow
|
|
|
|
.padding(.vertical, 4)
|
|
|
|
} else {
|
2021-09-01 02:47:50 +05:30
|
|
|
verticalRow
|
2021-09-27 03:58:42 +05:30
|
|
|
}
|
|
|
|
#else
|
|
|
|
verticalRow
|
|
|
|
#endif
|
2021-09-01 02:47:50 +05:30
|
|
|
}
|
|
|
|
#if os(macOS)
|
2021-12-20 05:06:12 +05:30
|
|
|
.background(Color.secondaryBackground)
|
2021-09-01 02:47:50 +05:30
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-12-27 02:44:46 +05:30
|
|
|
private var contentOpacity: Double {
|
|
|
|
guard saveHistory,
|
|
|
|
!watch.isNil,
|
2022-01-03 01:09:19 +05:30
|
|
|
watchedVideoStyle == .decreasedOpacity || watchedVideoStyle == .both
|
2021-12-27 02:44:46 +05:30
|
|
|
else {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
return watch!.finished ? 0.5 : 1
|
|
|
|
}
|
|
|
|
|
2021-09-29 19:59:17 +05:30
|
|
|
#if os(iOS)
|
2021-12-27 02:44:46 +05:30
|
|
|
private var horizontalRow: some View {
|
2021-09-29 19:59:17 +05:30
|
|
|
HStack(alignment: .top, spacing: 2) {
|
|
|
|
Section {
|
|
|
|
#if os(tvOS)
|
2021-11-06 02:23:43 +05:30
|
|
|
thumbnailImage
|
2021-09-29 19:59:17 +05:30
|
|
|
#else
|
|
|
|
thumbnail
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
.frame(maxWidth: 320)
|
2021-07-28 04:10:04 +05:30
|
|
|
|
2021-09-29 19:59:17 +05:30
|
|
|
VStack(alignment: .leading, spacing: 0) {
|
2022-11-11 23:49:48 +05:30
|
|
|
videoDetail(video.displayTitle, lineLimit: 5)
|
2021-09-29 19:59:17 +05:30
|
|
|
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
|
2021-07-28 04:10:04 +05:30
|
|
|
|
2022-12-14 17:26:47 +05:30
|
|
|
HStack(spacing: Constants.channelDetailsStackSpacing) {
|
2022-12-14 04:37:32 +05:30
|
|
|
if !inChannelView,
|
|
|
|
let video,
|
2022-12-14 21:50:24 +05:30
|
|
|
let url = video.channel.thumbnailURLOrCached,
|
|
|
|
video != .fixture
|
2022-12-14 04:37:32 +05:30
|
|
|
{
|
2022-12-14 17:26:47 +05:30
|
|
|
ChannelLinkView(channel: video.channel) {
|
|
|
|
ThumbnailView(url: url)
|
|
|
|
.frame(width: Constants.channelThumbnailSize, height: Constants.channelThumbnailSize)
|
|
|
|
.clipShape(Circle())
|
|
|
|
}
|
2022-12-14 04:37:32 +05:30
|
|
|
}
|
2022-12-14 17:26:47 +05:30
|
|
|
|
2022-12-14 04:37:32 +05:30
|
|
|
if !channelOnThumbnail, !inChannelView {
|
2022-12-14 17:26:47 +05:30
|
|
|
ChannelLinkView(channel: video.channel) {
|
|
|
|
channelLabel(badge: false)
|
|
|
|
}
|
2022-12-14 04:37:32 +05:30
|
|
|
}
|
2021-11-05 04:55:51 +05:30
|
|
|
}
|
2021-07-28 04:10:04 +05:30
|
|
|
|
2021-09-29 19:59:17 +05:30
|
|
|
if additionalDetailsAvailable {
|
|
|
|
Spacer()
|
2021-09-19 02:06:42 +05:30
|
|
|
|
2021-11-05 04:55:51 +05:30
|
|
|
HStack(spacing: 15) {
|
2021-09-29 19:59:17 +05:30
|
|
|
if let date = video.publishedDate {
|
|
|
|
VStack {
|
|
|
|
Image(systemName: "calendar")
|
2021-11-05 04:55:51 +05:30
|
|
|
.frame(height: 15)
|
2021-09-29 19:59:17 +05:30
|
|
|
Text(date)
|
|
|
|
}
|
2021-09-19 02:06:42 +05:30
|
|
|
}
|
2021-07-28 04:10:04 +05:30
|
|
|
|
2021-10-23 04:34:03 +05:30
|
|
|
if video.views > 0 {
|
2021-09-29 19:59:17 +05:30
|
|
|
VStack {
|
|
|
|
Image(systemName: "eye")
|
2021-11-05 04:55:51 +05:30
|
|
|
.frame(height: 15)
|
2021-09-29 19:59:17 +05:30
|
|
|
Text(video.viewsCount!)
|
|
|
|
}
|
2021-09-19 02:06:42 +05:30
|
|
|
}
|
2021-11-05 04:55:51 +05:30
|
|
|
|
2022-12-04 16:37:06 +05:30
|
|
|
if !timeOnThumbnail, let time = videoDuration {
|
2021-11-05 04:55:51 +05:30
|
|
|
VStack {
|
|
|
|
Image(systemName: "clock")
|
|
|
|
.frame(height: 15)
|
|
|
|
Text(time)
|
|
|
|
}
|
|
|
|
}
|
2021-09-19 02:06:42 +05:30
|
|
|
}
|
2021-09-29 19:59:17 +05:30
|
|
|
.foregroundColor(.secondary)
|
2021-09-19 02:06:42 +05:30
|
|
|
}
|
|
|
|
}
|
2021-09-29 19:59:17 +05:30
|
|
|
.padding()
|
|
|
|
.frame(minHeight: 180)
|
2021-07-28 04:10:04 +05:30
|
|
|
|
2021-09-29 19:59:17 +05:30
|
|
|
#if os(tvOS)
|
2022-12-04 16:37:06 +05:30
|
|
|
if let time = videoDuration || video.live || video.upcoming {
|
2021-08-03 02:40:22 +05:30
|
|
|
Spacer()
|
|
|
|
|
2022-11-26 00:01:48 +05:30
|
|
|
VStack {
|
2021-09-29 19:59:17 +05:30
|
|
|
Spacer()
|
|
|
|
|
2022-12-04 16:37:06 +05:30
|
|
|
if let time = videoDuration {
|
2021-09-29 19:59:17 +05:30
|
|
|
HStack(spacing: 4) {
|
|
|
|
Image(systemName: "clock")
|
|
|
|
Text(time)
|
|
|
|
.fontWeight(.bold)
|
|
|
|
}
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
} else if video.live {
|
|
|
|
DetailBadge(text: "Live", style: .outstanding)
|
|
|
|
} else if video.upcoming {
|
|
|
|
DetailBadge(text: "Upcoming", style: .informational)
|
2021-08-03 02:40:22 +05:30
|
|
|
}
|
2021-08-02 04:31:24 +05:30
|
|
|
|
2021-09-29 19:59:17 +05:30
|
|
|
Spacer()
|
|
|
|
}
|
2021-10-23 04:34:03 +05:30
|
|
|
.lineLimit(1)
|
2021-08-03 02:40:22 +05:30
|
|
|
}
|
2021-09-29 19:59:17 +05:30
|
|
|
#endif
|
|
|
|
}
|
2021-07-28 04:10:04 +05:30
|
|
|
}
|
2021-09-29 19:59:17 +05:30
|
|
|
#endif
|
2021-07-28 04:10:04 +05:30
|
|
|
|
2022-12-04 16:37:06 +05:30
|
|
|
private var videoDuration: String? {
|
|
|
|
let length = video.length.isZero ? watch?.videoDuration : video.length
|
|
|
|
return length?.formattedAsPlaybackTime()
|
|
|
|
}
|
|
|
|
|
2021-12-27 02:44:46 +05:30
|
|
|
private var verticalRow: some View {
|
2021-09-19 02:06:42 +05:30
|
|
|
VStack(alignment: .leading, spacing: 0) {
|
2021-08-02 04:31:24 +05:30
|
|
|
thumbnail
|
2021-07-28 04:10:04 +05:30
|
|
|
|
2021-09-25 13:48:22 +05:30
|
|
|
VStack(alignment: .leading, spacing: 0) {
|
2021-11-05 04:55:51 +05:30
|
|
|
Group {
|
|
|
|
VStack(alignment: .leading, spacing: 0) {
|
2022-11-11 23:49:48 +05:30
|
|
|
videoDetail(video.displayTitle, lineLimit: 2)
|
2021-11-05 04:55:51 +05:30
|
|
|
#if os(tvOS)
|
|
|
|
.frame(minHeight: 60, alignment: .top)
|
|
|
|
#elseif os(macOS)
|
2022-12-14 17:26:47 +05:30
|
|
|
.frame(minHeight: 35, alignment: .top)
|
2021-11-05 04:55:51 +05:30
|
|
|
#else
|
2022-12-14 17:26:47 +05:30
|
|
|
.frame(minHeight: 43, alignment: .top)
|
2021-11-05 04:55:51 +05:30
|
|
|
#endif
|
2022-08-08 22:56:51 +05:30
|
|
|
if !channelOnThumbnail, !inChannelView {
|
2022-12-14 17:26:47 +05:30
|
|
|
ChannelLinkView(channel: video.channel) {
|
|
|
|
HStack(spacing: Constants.channelDetailsStackSpacing) {
|
2022-12-14 21:50:24 +05:30
|
|
|
if let url = video.channel.thumbnailURLOrCached,
|
|
|
|
video != .fixture
|
|
|
|
{
|
2022-12-14 17:26:47 +05:30
|
|
|
ThumbnailView(url: url)
|
|
|
|
.frame(width: Constants.channelThumbnailSize, height: Constants.channelThumbnailSize)
|
|
|
|
.clipShape(Circle())
|
|
|
|
}
|
|
|
|
|
|
|
|
channelLabel(badge: false)
|
|
|
|
}
|
|
|
|
}
|
2021-11-05 04:55:51 +05:30
|
|
|
}
|
|
|
|
}
|
2021-11-08 03:57:09 +05:30
|
|
|
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
|
2021-11-05 04:55:51 +05:30
|
|
|
}
|
2021-08-02 04:31:24 +05:30
|
|
|
#if os(tvOS)
|
2021-11-08 21:59:35 +05:30
|
|
|
.frame(minHeight: channelOnThumbnail ? 80 : 120, alignment: .top)
|
2021-08-03 02:40:22 +05:30
|
|
|
#elseif os(macOS)
|
2022-12-14 17:26:47 +05:30
|
|
|
.frame(minHeight: channelOnThumbnail ? 52 : 75, alignment: .top)
|
2021-08-03 02:40:22 +05:30
|
|
|
#else
|
2022-12-14 17:26:47 +05:30
|
|
|
.frame(minHeight: channelOnThumbnail ? 50 : 70, alignment: .top)
|
2021-08-02 04:31:24 +05:30
|
|
|
#endif
|
2021-10-06 01:50:09 +05:30
|
|
|
.padding(.bottom, 4)
|
2021-07-28 04:10:04 +05:30
|
|
|
|
2021-11-02 03:26:18 +05:30
|
|
|
HStack(spacing: 8) {
|
2022-12-14 17:26:47 +05:30
|
|
|
if channelOnThumbnail,
|
|
|
|
!inChannelView,
|
2022-12-14 04:37:32 +05:30
|
|
|
let video,
|
2022-12-14 21:50:24 +05:30
|
|
|
let url = video.channel.thumbnailURLOrCached,
|
|
|
|
video != .fixture
|
2022-12-14 04:37:32 +05:30
|
|
|
{
|
2022-12-14 17:26:47 +05:30
|
|
|
ChannelLinkView(channel: video.channel) {
|
|
|
|
ThumbnailView(url: url)
|
|
|
|
.frame(width: Constants.channelThumbnailSize, height: Constants.channelThumbnailSize)
|
|
|
|
.clipShape(Circle())
|
|
|
|
}
|
2022-12-14 04:37:32 +05:30
|
|
|
}
|
|
|
|
|
2021-11-02 03:26:18 +05:30
|
|
|
if let date = video.publishedDate {
|
2021-11-05 04:55:51 +05:30
|
|
|
HStack(spacing: 2) {
|
|
|
|
Text(date)
|
|
|
|
.allowsTightening(true)
|
|
|
|
}
|
2021-11-02 03:26:18 +05:30
|
|
|
}
|
2021-09-19 02:06:42 +05:30
|
|
|
|
2021-11-02 03:26:18 +05:30
|
|
|
if video.views > 0 {
|
2021-11-05 04:55:51 +05:30
|
|
|
HStack(spacing: 2) {
|
|
|
|
Image(systemName: "eye")
|
|
|
|
Text(video.viewsCount!)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-28 19:57:01 +05:30
|
|
|
if let time, !timeOnThumbnail {
|
2021-11-05 04:55:51 +05:30
|
|
|
Spacer()
|
|
|
|
|
|
|
|
HStack(spacing: 2) {
|
|
|
|
Text(time)
|
|
|
|
}
|
2021-09-14 02:11:16 +05:30
|
|
|
}
|
2021-07-28 04:10:04 +05:30
|
|
|
}
|
2021-11-05 04:55:51 +05:30
|
|
|
.lineLimit(1)
|
2021-11-02 03:26:18 +05:30
|
|
|
.foregroundColor(.secondary)
|
2022-12-14 17:26:47 +05:30
|
|
|
.frame(maxWidth: .infinity, minHeight: 35, alignment: .topLeading)
|
2021-09-25 13:48:22 +05:30
|
|
|
#if os(tvOS)
|
|
|
|
.padding(.bottom, 10)
|
|
|
|
#endif
|
2021-07-28 04:10:04 +05:30
|
|
|
}
|
2021-09-19 02:06:42 +05:30
|
|
|
.padding(.top, 4)
|
|
|
|
.frame(minWidth: 0, maxWidth: .infinity, alignment: .topLeading)
|
2021-08-02 04:31:24 +05:30
|
|
|
#if os(tvOS)
|
2022-08-26 05:08:04 +05:30
|
|
|
.padding(.horizontal, horizontalCells ? 10 : 20)
|
2021-08-02 04:31:24 +05:30
|
|
|
#endif
|
2021-07-28 04:10:04 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-11 17:08:57 +05:30
|
|
|
@ViewBuilder private func channelLabel(badge: Bool = true) -> some View {
|
|
|
|
if badge {
|
|
|
|
DetailBadge(text: video.author, style: .prominent)
|
|
|
|
.foregroundColor(.primary)
|
|
|
|
} else {
|
|
|
|
Text(video.channel.name)
|
|
|
|
.fontWeight(.semibold)
|
|
|
|
.foregroundColor(.secondary)
|
2022-03-27 16:20:36 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-27 02:44:46 +05:30
|
|
|
private var additionalDetailsAvailable: Bool {
|
|
|
|
video.publishedDate != nil || video.views != 0 ||
|
2022-12-04 16:37:06 +05:30
|
|
|
(!timeOnThumbnail && !videoDuration.isNil)
|
2021-07-28 04:10:04 +05:30
|
|
|
}
|
|
|
|
|
2021-12-27 02:44:46 +05:30
|
|
|
private var thumbnail: some View {
|
2021-08-01 03:40:56 +05:30
|
|
|
ZStack(alignment: .leading) {
|
2021-12-27 02:44:46 +05:30
|
|
|
ZStack(alignment: .bottomLeading) {
|
|
|
|
thumbnailImage
|
|
|
|
if saveHistory, showWatchingProgress, watch?.progress ?? 0 > 0 {
|
|
|
|
ProgressView(value: watch!.progress, total: 100)
|
2022-01-03 01:09:19 +05:30
|
|
|
.progressViewStyle(LinearProgressViewStyle(tint: Color("AppRedColor")))
|
2021-12-27 02:44:46 +05:30
|
|
|
#if os(tvOS)
|
|
|
|
.padding(.horizontal, 16)
|
|
|
|
#else
|
|
|
|
.padding(.horizontal, 10)
|
|
|
|
#endif
|
|
|
|
#if os(macOS)
|
|
|
|
.offset(x: 0, y: 4)
|
|
|
|
#else
|
|
|
|
.offset(x: 0, y: -3)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2021-07-28 04:10:04 +05:30
|
|
|
|
|
|
|
VStack {
|
|
|
|
HStack(alignment: .top) {
|
|
|
|
if video.live {
|
|
|
|
DetailBadge(text: "Live", style: .outstanding)
|
|
|
|
} else if video.upcoming {
|
|
|
|
DetailBadge(text: "Upcoming", style: .informational)
|
|
|
|
}
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
|
2022-08-08 22:56:51 +05:30
|
|
|
if channelOnThumbnail, !inChannelView {
|
2022-12-14 17:26:47 +05:30
|
|
|
ChannelLinkView(channel: video.channel) {
|
|
|
|
channelLabel()
|
|
|
|
}
|
2021-11-05 04:55:51 +05:30
|
|
|
}
|
2021-07-28 04:10:04 +05:30
|
|
|
}
|
2021-12-27 02:44:46 +05:30
|
|
|
#if os(tvOS)
|
|
|
|
.padding(16)
|
|
|
|
#else
|
2021-07-28 04:10:04 +05:30
|
|
|
.padding(10)
|
2021-12-27 02:44:46 +05:30
|
|
|
#endif
|
2021-07-28 04:10:04 +05:30
|
|
|
|
|
|
|
Spacer()
|
|
|
|
|
2022-11-26 00:01:48 +05:30
|
|
|
HStack {
|
2021-12-27 02:44:46 +05:30
|
|
|
if saveHistory,
|
2022-09-01 00:54:46 +05:30
|
|
|
watchedVideoStyle.isShowingBadge,
|
2021-12-27 02:44:46 +05:30
|
|
|
watch?.finished ?? false
|
|
|
|
{
|
|
|
|
Image(systemName: "checkmark.circle.fill")
|
2022-01-03 01:09:19 +05:30
|
|
|
.foregroundColor(Color(
|
|
|
|
watchedVideoBadgeColor == .colorSchemeBased ? "WatchProgressBarColor" :
|
|
|
|
watchedVideoBadgeColor == .red ? "AppRedColor" : "AppBlueColor"
|
|
|
|
))
|
2021-12-27 02:44:46 +05:30
|
|
|
.background(Color.white)
|
|
|
|
.clipShape(Circle())
|
|
|
|
#if os(tvOS)
|
|
|
|
.font(.system(size: 40))
|
|
|
|
#else
|
|
|
|
.font(.system(size: 30))
|
|
|
|
#endif
|
|
|
|
}
|
2021-07-28 04:10:04 +05:30
|
|
|
Spacer()
|
|
|
|
|
2021-12-27 02:44:46 +05:30
|
|
|
if timeOnThumbnail,
|
|
|
|
!video.live,
|
2022-09-28 19:57:01 +05:30
|
|
|
let time
|
2021-12-27 02:44:46 +05:30
|
|
|
{
|
2021-07-28 04:10:04 +05:30
|
|
|
DetailBadge(text: time, style: .prominent)
|
|
|
|
}
|
|
|
|
}
|
2021-12-27 02:44:46 +05:30
|
|
|
#if os(tvOS)
|
|
|
|
.padding(16)
|
|
|
|
#else
|
2021-07-28 04:10:04 +05:30
|
|
|
.padding(10)
|
2021-12-27 02:44:46 +05:30
|
|
|
#endif
|
2021-07-28 04:10:04 +05:30
|
|
|
}
|
2021-10-23 04:34:03 +05:30
|
|
|
.lineLimit(1)
|
2021-07-28 04:10:04 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-27 02:44:46 +05:30
|
|
|
private var thumbnailImage: some View {
|
2021-10-25 03:56:25 +05:30
|
|
|
Group {
|
2022-12-11 05:21:21 +05:30
|
|
|
ThumbnailView(url: thumbnails.best(video))
|
2022-09-12 00:51:50 +05:30
|
|
|
|
2022-09-12 01:03:08 +05:30
|
|
|
#if os(tvOS)
|
|
|
|
.frame(minHeight: 320)
|
|
|
|
#endif
|
2021-10-25 03:56:25 +05:30
|
|
|
}
|
2022-01-06 20:26:59 +05:30
|
|
|
.mask(RoundedRectangle(cornerRadius: thumbnailRoundingCornerRadius))
|
2021-10-25 03:56:25 +05:30
|
|
|
.modifier(AspectRatioModifier())
|
2021-07-28 04:10:04 +05:30
|
|
|
}
|
|
|
|
|
2021-12-27 02:44:46 +05:30
|
|
|
private var time: String? {
|
2022-12-04 16:37:06 +05:30
|
|
|
guard var videoTime = videoDuration else {
|
2021-12-27 02:44:46 +05:30
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if !saveHistory || !showWatchingProgress || watch?.finished ?? false {
|
|
|
|
return videoTime
|
|
|
|
}
|
|
|
|
|
|
|
|
if let stoppedAt = watch?.stoppedAt,
|
|
|
|
stoppedAt.isFinite,
|
|
|
|
let stoppedAtFormatted = stoppedAt.formattedAsPlaybackTime()
|
|
|
|
{
|
2022-03-27 16:20:36 +05:30
|
|
|
if (watch?.videoDuration ?? 0) > 0 {
|
2021-12-27 02:44:46 +05:30
|
|
|
videoTime = watch!.videoDuration.formattedAsPlaybackTime() ?? "?"
|
|
|
|
}
|
|
|
|
return "\(stoppedAtFormatted) / \(videoTime)"
|
|
|
|
}
|
|
|
|
|
|
|
|
return videoTime
|
|
|
|
}
|
|
|
|
|
|
|
|
private func videoDetail(_ text: String, lineLimit: Int = 1) -> some View {
|
2021-07-28 04:10:04 +05:30
|
|
|
Text(text)
|
2021-08-02 04:31:24 +05:30
|
|
|
.fontWeight(.bold)
|
2021-07-28 04:10:04 +05:30
|
|
|
.lineLimit(lineLimit)
|
|
|
|
.truncationMode(.middle)
|
2021-07-28 02:56:52 +05:30
|
|
|
}
|
2021-08-03 02:40:22 +05:30
|
|
|
|
2021-09-19 02:06:42 +05:30
|
|
|
struct AspectRatioModifier: ViewModifier {
|
|
|
|
@Environment(\.horizontalCells) private var horizontalCells
|
|
|
|
|
|
|
|
func body(content: Content) -> some View {
|
|
|
|
Group {
|
|
|
|
if horizontalCells {
|
|
|
|
content
|
|
|
|
} else {
|
|
|
|
content
|
2021-12-27 02:44:46 +05:30
|
|
|
.aspectRatio(
|
|
|
|
VideoPlayerView.defaultAspectRatio,
|
|
|
|
contentMode: .fill
|
|
|
|
)
|
2021-09-19 02:06:42 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-28 02:56:52 +05:30
|
|
|
}
|
2021-10-22 04:59:10 +05:30
|
|
|
|
2021-10-23 04:34:03 +05:30
|
|
|
struct VideoCell_Preview: PreviewProvider {
|
2021-10-22 04:59:10 +05:30
|
|
|
static var previews: some View {
|
|
|
|
Group {
|
|
|
|
VideoCell(video: Video.fixture)
|
|
|
|
}
|
2021-11-05 04:55:51 +05:30
|
|
|
#if os(macOS)
|
2021-11-08 21:59:35 +05:30
|
|
|
.frame(maxWidth: 300, maxHeight: 250)
|
2021-11-05 04:55:51 +05:30
|
|
|
#elseif os(iOS)
|
2022-12-14 04:37:32 +05:30
|
|
|
.frame(maxWidth: 600, maxHeight: 200)
|
2021-11-05 04:55:51 +05:30
|
|
|
#endif
|
2021-10-22 04:59:10 +05:30
|
|
|
.injectFixtureEnvironmentObjects()
|
|
|
|
}
|
|
|
|
}
|