From 35c553cd0541d94b8985989ccc55bce369c53981 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sat, 19 Nov 2022 14:11:04 +0100 Subject: [PATCH] Fix calculating progress on banner --- Model/Player/PlayerQueueItem.swift | 2 +- Shared/Videos/VideoBanner.swift | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Model/Player/PlayerQueueItem.swift b/Model/Player/PlayerQueueItem.swift index fa2c13ad..763d239b 100644 --- a/Model/Player/PlayerQueueItem.swift +++ b/Model/Player/PlayerQueueItem.swift @@ -42,7 +42,7 @@ struct PlayerQueueItem: Hashable, Identifiable, Defaults.Serializable { return false } - return duration - seconds <= 20 + return (seconds / duration) * 100 > Double(Defaults[.watchedThreshold]) } var hasDetailsLoaded: Bool { diff --git a/Shared/Videos/VideoBanner.swift b/Shared/Videos/VideoBanner.swift index b4fed9bc..2a6b7bd8 100644 --- a/Shared/Videos/VideoBanner.swift +++ b/Shared/Videos/VideoBanner.swift @@ -1,4 +1,5 @@ import CoreMedia +import Defaults import Foundation import SDWebImageSwiftUI import SwiftUI @@ -169,13 +170,19 @@ struct VideoBanner: View { private var progressView: some View { Group { if !playbackTime.isNil, !(video?.live ?? false) { - ProgressView(value: progressViewValue, total: progressViewTotal) + ProgressView(value: watchValue, total: progressViewTotal) .progressViewStyle(.linear) .frame(maxWidth: thumbnailWidth) } } } + private var watchValue: Double { + if finished { return progressViewTotal } + + return progressViewValue + } + private var progressViewValue: Double { guard videoDuration != 0 else { return 1 } return [playbackTime?.seconds, videoDuration].compactMap { $0 }.min() ?? 0 @@ -185,6 +192,10 @@ struct VideoBanner: View { guard videoDuration != 0 else { return 1 } return videoDuration ?? video?.length ?? 1 } + + private var finished: Bool { + (progressViewValue / progressViewTotal) * 100 > Double(Defaults[.watchedThreshold]) + } } struct VideoBanner_Previews: PreviewProvider {