This commit is contained in:
Francesco 2025-06-02 16:32:53 +02:00
parent 41953477a5
commit 0857ab3024

View file

@ -115,6 +115,19 @@ struct MediaInfoView: View {
return Double(watchedCount) / Double(episodeLinks.count)
}
private var latestProgressEpisode: (progress: Double, title: String)? {
for ep in episodeLinks.reversed() {
let lastPlayedTime = UserDefaults.standard.double(forKey: "lastPlayedTime_\(ep.href)")
let totalTime = UserDefaults.standard.double(forKey: "totalTime_\(ep.href)")
if totalTime > 0 {
let progress = lastPlayedTime / totalTime
return (progress, "Episode \(ep.number)")
}
}
return nil
}
@State private var continueWatchingText: String = "Start Watching"
var body: some View {
@ -589,13 +602,15 @@ struct MediaInfoView: View {
@ViewBuilder
private var playAndBookmarkSection: some View {
HStack(spacing: 12) {
ZStack {
ZStack(alignment: .leading) {
GeometryReader { geometry in
let width = geometry.size.width
let progress = watchingProgress
let progress = latestProgressEpisode?.progress ?? 0.0
RoundedRectangle(cornerRadius: 25)
.fill(Color.accentColor.opacity(0.25))
.frame(width: width, height: 48)
RoundedRectangle(cornerRadius: 25)
.fill(Color.accentColor)
.frame(width: width * CGFloat(progress), height: 48)
@ -608,7 +623,7 @@ struct MediaInfoView: View {
HStack(spacing: 8) {
Image(systemName: "play.fill")
.foregroundColor(colorScheme == .dark ? .black : .white)
Text(continueWatchingText)
Text(latestProgressEpisode?.title ?? "Start Watching")
.font(.system(size: 16, weight: .medium))
.foregroundColor(colorScheme == .dark ? .black : .white)
}
@ -620,7 +635,6 @@ struct MediaInfoView: View {
}
.disabled(isFetchingEpisode)
}
.frame(height: 48)
.clipShape(RoundedRectangle(cornerRadius: 25))
.overlay(
RoundedRectangle(cornerRadius: 25)