mirror of
https://github.com/yattee/yattee.git
synced 2025-08-04 01:34:10 +00:00
Fix calculating progress on banner
This commit is contained in:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user