From ac7dad2ab8534de46ea65317f115c1b59d869a61 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Tue, 23 May 2023 18:00:33 +0200 Subject: [PATCH] Fix #450 --- Model/Watch.swift | 5 +++++ Shared/Videos/VideoBanner.swift | 23 ++++++++++++++++------- Shared/Videos/VideoCell.swift | 6 +----- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Model/Watch.swift b/Model/Watch.swift index 8773c065..a3e62f30 100644 --- a/Model/Watch.swift +++ b/Model/Watch.swift @@ -7,6 +7,7 @@ import Foundation final class Watch: NSManagedObject, Identifiable { @Default(.watchedThreshold) private var watchedThreshold @Default(.saveHistory) private var saveHistory + @Default(.showWatchingProgress) private var showWatchingProgress } extension Watch { @@ -102,4 +103,8 @@ extension Watch { return Video(app: app ?? AccountsModel.shared.current?.app ?? .local, instanceURL: instanceURL, videoID: videoID) } + + var isShowingProgress: Bool { + saveHistory && showWatchingProgress && (finished || progress > 0) + } } diff --git a/Shared/Videos/VideoBanner.swift b/Shared/Videos/VideoBanner.swift index f4f2e7c4..d6f1141b 100644 --- a/Shared/Videos/VideoBanner.swift +++ b/Shared/Videos/VideoBanner.swift @@ -37,14 +37,22 @@ struct VideoBanner: View { var body: some View { HStack(alignment: .top, spacing: 12) { - VStack(alignment: .trailing, spacing: 2) { - smallThumbnail + ZStack(alignment: .bottom) { + VStack(alignment: .trailing, spacing: 2) { + smallThumbnail - if !timeOnThumbnail, let timeLabel { - Text(timeLabel) - .font(.caption.monospacedDigit()) - .foregroundColor(.secondary) + if !timeOnThumbnail, let timeLabel { + Text(timeLabel) + .font(.caption.monospacedDigit()) + .foregroundColor(.secondary) + } } + .layoutPriority(1) + + ProgressView(value: watch?.progress ?? 44, total: 100) + .frame(maxHeight: 4) + .progressViewStyle(LinearProgressViewStyle(tint: Color("AppRedColor"))) + .opacity(watch?.isShowingProgress ?? false ? 1 : 0) } VStack(alignment: .leading, spacing: 2) { @@ -193,6 +201,7 @@ struct VideoBanner: View { if timeOnThumbnail { timeView + .offset(y: watch?.isShowingProgress ?? false ? -4 : 0) } } .frame(width: thumbnailWidth, height: thumbnailHeight) @@ -279,7 +288,7 @@ struct VideoBanner: View { struct VideoBanner_Previews: PreviewProvider { static var previews: some View { - VStack(spacing: 2) { + ScrollView { VideoBanner(video: Video.fixture, playbackTime: CMTime(seconds: 400, preferredTimescale: 10000)) VideoBanner(video: Video.fixtureUpcomingWithoutPublishedOrViews) VideoBanner(video: .local(URL(string: "https://apple.com/a/directory/of/video+that+has+very+long+title+that+will+likely.mp4")!)) diff --git a/Shared/Videos/VideoCell.swift b/Shared/Videos/VideoCell.swift index 04e3e963..e86cab9f 100644 --- a/Shared/Videos/VideoCell.swift +++ b/Shared/Videos/VideoCell.swift @@ -359,10 +359,6 @@ struct VideoCell: View { (!timeOnThumbnail && !videoDuration.isNil) } - private var showProgressView: Bool { - saveHistory && showWatchingProgress && ((watch?.finished ?? false) || watch?.progress ?? 0 > 0) - } - private var thumbnail: some View { ZStack(alignment: .leading) { ZStack(alignment: .bottomLeading) { @@ -380,7 +376,7 @@ struct VideoCell: View { #else .offset(x: 0, y: -3) #endif - .opacity(showProgressView ? 1 : 0) + .opacity(watch?.isShowingProgress ?? false ? 1 : 0) } VStack {