From f4d2fdd3f705a3e5a0430ee3bcf8de0f7ab0f873 Mon Sep 17 00:00:00 2001 From: Barnabas Balogh Date: Sun, 5 Jul 2026 08:02:28 +0000 Subject: [PATCH] fix(player): persist previous item progress before updating position snapshot Reorder the position/duration snapshot in ProgressManager.bind() so stopSession() reads the previous item's last-known position instead of the next item's seek target. Fixes the offline Room database being written with 0% progress on item transitions. --- .../hu/bbara/purefin/core/player/manager/ProgressManager.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/hu/bbara/purefin/core/player/manager/ProgressManager.kt b/core/src/main/java/hu/bbara/purefin/core/player/manager/ProgressManager.kt index 246ee710..a367af4d 100644 --- a/core/src/main/java/hu/bbara/purefin/core/player/manager/ProgressManager.kt +++ b/core/src/main/java/hu/bbara/purefin/core/player/manager/ProgressManager.kt @@ -43,8 +43,6 @@ class ProgressManager @Inject constructor( combine(playbackState, progress, metadata) { state, prog, meta -> Triple(state, prog, meta) }.collect { (state, prog, meta) -> - lastPositionMs = prog.positionMs - lastDurationMs = prog.durationMs isPaused = !state.isPlaying val mediaId = meta.mediaId?.let { runCatching { UUID.fromString(it) }.getOrNull() } val nextPlaybackReportContext = meta.playbackReportContext @@ -53,6 +51,9 @@ class ProgressManager @Inject constructor( stopSession() } + lastPositionMs = prog.positionMs + lastDurationMs = prog.durationMs + if (activeItemId == null && mediaId != null && !state.isEnded) { startSession(mediaId, prog.positionMs, nextPlaybackReportContext) } else if (activeItemId == mediaId) {