Fix updating video watches

This commit is contained in:
Arkadiusz Fal 2022-12-04 12:07:06 +01:00
parent 210f28da37
commit 82cd08d44e
2 changed files with 19 additions and 11 deletions

View File

@ -58,7 +58,7 @@ extension PlayerModel {
let results = try? backgroundContext.fetch(watchFetchRequest) let results = try? backgroundContext.fetch(watchFetchRequest)
backgroundContext.perform { [weak self] in backgroundContext.perform { [weak self] in
guard let self else { guard let self, finished || self.backend.isPlaying else {
return return
} }
@ -74,13 +74,16 @@ extension PlayerModel {
watch = results?.first watch = results?.first
} }
if let seconds = self.playerItemDuration?.seconds { let duration = self.playerTime.duration.seconds
watch.videoDuration = seconds if duration.isFinite, duration > 0 {
watch.videoDuration = duration
} }
if finished { if watch.finished {
watch.stoppedAt = watch.videoDuration if !finished, self.resetWatchedStatusOnPlaying, seconds.isFinite, seconds > 0 {
} else if self.resetWatchedStatusOnPlaying, seconds.isFinite, seconds > 0 { watch.stoppedAt = seconds
}
} else if seconds.isFinite, seconds > 0 {
watch.stoppedAt = seconds watch.stoppedAt = seconds
} }

View File

@ -187,7 +187,7 @@ struct VideoCell: View {
} }
} }
if !timeOnThumbnail, let time = video.length.formattedAsPlaybackTime() { if !timeOnThumbnail, let time = videoDuration {
VStack { VStack {
Image(systemName: "clock") Image(systemName: "clock")
.frame(height: 15) .frame(height: 15)
@ -202,13 +202,13 @@ struct VideoCell: View {
.frame(minHeight: 180) .frame(minHeight: 180)
#if os(tvOS) #if os(tvOS)
if let time = video.length.formattedAsPlaybackTime() || video.live || video.upcoming { if let time = videoDuration || video.live || video.upcoming {
Spacer() Spacer()
VStack { VStack {
Spacer() Spacer()
if let time = video.length.formattedAsPlaybackTime() { if let time = videoDuration {
HStack(spacing: 4) { HStack(spacing: 4) {
Image(systemName: "clock") Image(systemName: "clock")
Text(time) Text(time)
@ -230,6 +230,11 @@ struct VideoCell: View {
} }
#endif #endif
private var videoDuration: String? {
let length = video.length.isZero ? watch?.videoDuration : video.length
return length?.formattedAsPlaybackTime()
}
private var verticalRow: some View { private var verticalRow: some View {
VStack(alignment: .leading, spacing: 0) { VStack(alignment: .leading, spacing: 0) {
thumbnail thumbnail
@ -332,7 +337,7 @@ struct VideoCell: View {
private var additionalDetailsAvailable: Bool { private var additionalDetailsAvailable: Bool {
video.publishedDate != nil || video.views != 0 || video.publishedDate != nil || video.views != 0 ||
(!timeOnThumbnail && !video.length.formattedAsPlaybackTime().isNil) (!timeOnThumbnail && !videoDuration.isNil)
} }
private var thumbnail: some View { private var thumbnail: some View {
@ -438,7 +443,7 @@ struct VideoCell: View {
} }
private var time: String? { private var time: String? {
guard var videoTime = video.length.formattedAsPlaybackTime() else { guard var videoTime = videoDuration else {
return nil return nil
} }