From 53e1b08956588df71b9131508ab14c3bc1dbf431 Mon Sep 17 00:00:00 2001 From: cranci1 <100066266+cranci1@users.noreply.github.com> Date: Tue, 18 Mar 2025 15:29:55 +0100 Subject: [PATCH] forgot about continue watching should work? --- Sora/Views/LibraryView/LibraryView.swift | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Sora/Views/LibraryView/LibraryView.swift b/Sora/Views/LibraryView/LibraryView.swift index 87087c0..877f38b 100644 --- a/Sora/Views/LibraryView/LibraryView.swift +++ b/Sora/Views/LibraryView/LibraryView.swift @@ -205,6 +205,8 @@ struct ContinueWatchingCell: View { var markAsWatched: () -> Void var removeItem: () -> Void + @State private var currentProgress: Double = 0.0 + var body: some View { Button(action: { if UserDefaults.standard.string(forKey: "externalPlayer") == "Default" { @@ -271,7 +273,7 @@ struct ContinueWatchingCell: View { .blur(radius: 3) .frame(height: 30) - ProgressView(value: item.progress) + ProgressView(value: currentProgress) .progressViewStyle(LinearProgressViewStyle(tint: .white)) .padding(.horizontal, 8) .scaleEffect(x: 1, y: 1.5, anchor: .center) @@ -302,5 +304,22 @@ struct ContinueWatchingCell: View { Label("Remove Item", systemImage: "trash") } } + .onAppear { + updateProgress() + } + .onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification)) { _ in + updateProgress() + } + } + + private func updateProgress() { + let lastPlayedTime = UserDefaults.standard.double(forKey: "lastPlayedTime_\(item.fullUrl)") + let totalTime = UserDefaults.standard.double(forKey: "totalTime_\(item.fullUrl)") + + if totalTime > 0 { + currentProgress = lastPlayedTime / totalTime + } else { + currentProgress = item.progress + } } }