Fix calculating progress on banner

This commit is contained in:
Arkadiusz Fal 2022-11-19 14:11:04 +01:00
parent cda6dc8b9b
commit 35c553cd05
2 changed files with 13 additions and 2 deletions

View File

@ -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 {

View File

@ -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 {