diff --git a/composeApp/src/commonMain/kotlin/com/nuvio/app/features/player/PlayerScreenRuntimePlaybackActions.kt b/composeApp/src/commonMain/kotlin/com/nuvio/app/features/player/PlayerScreenRuntimePlaybackActions.kt index 33bcf36f4..6939aba1b 100644 --- a/composeApp/src/commonMain/kotlin/com/nuvio/app/features/player/PlayerScreenRuntimePlaybackActions.kt +++ b/composeApp/src/commonMain/kotlin/com/nuvio/app/features/player/PlayerScreenRuntimePlaybackActions.kt @@ -187,7 +187,10 @@ private fun PlayerScreenRuntime.emitTrackingScrobbleTerminal( internal fun PlayerScreenRuntime.emitStopScrobbleForCurrentProgress() { val progressPercent = currentPlaybackProgressPercent() - if (progressPercent >= 1f && progressPercent < 80f) { + if (!shouldSendStopScrobble(hasRequestedScrobbleStartForCurrentItem, progressPercent)) { + return + } + if (progressPercent < 80f) { emitTrackingScrobbleStop(progressPercent) return } @@ -198,6 +201,11 @@ internal fun PlayerScreenRuntime.emitStopScrobbleForCurrentProgress() { } } +internal fun shouldSendStopScrobble( + hasActiveScrobble: Boolean, + progressPercent: Float, +): Boolean = hasActiveScrobble || progressPercent >= 80f + internal fun shouldUpdateTrackingScrobbleAfterSeek( hasActiveScrobble: Boolean, progressPercent: Float, diff --git a/composeApp/src/commonTest/kotlin/com/nuvio/app/features/player/PlayerScreenRuntimeStateTest.kt b/composeApp/src/commonTest/kotlin/com/nuvio/app/features/player/PlayerScreenRuntimeStateTest.kt index 608c48680..0b8f720ba 100644 --- a/composeApp/src/commonTest/kotlin/com/nuvio/app/features/player/PlayerScreenRuntimeStateTest.kt +++ b/composeApp/src/commonTest/kotlin/com/nuvio/app/features/player/PlayerScreenRuntimeStateTest.kt @@ -45,6 +45,54 @@ class PlayerScreenRuntimeStateTest { ) } + @Test + fun stopScrobble_closesActiveSessionBelowOnePercent() { + assertTrue( + shouldSendStopScrobble( + hasActiveScrobble = true, + progressPercent = 0f, + ), + ) + assertTrue( + shouldSendStopScrobble( + hasActiveScrobble = true, + progressPercent = 0.5f, + ), + ) + } + + @Test + fun stopScrobble_skipsEarlyProgressWithoutActiveSession() { + assertFalse( + shouldSendStopScrobble( + hasActiveScrobble = false, + progressPercent = 0.5f, + ), + ) + assertFalse( + shouldSendStopScrobble( + hasActiveScrobble = false, + progressPercent = 79.99f, + ), + ) + } + + @Test + fun stopScrobble_allowsCompletionWithoutActiveSession() { + assertTrue( + shouldSendStopScrobble( + hasActiveScrobble = false, + progressPercent = 80f, + ), + ) + assertTrue( + shouldSendStopScrobble( + hasActiveScrobble = false, + progressPercent = 100f, + ), + ) + } + private fun testPlayerScreenArgs() = PlayerScreenArgs( profileId = 1, title = "Title",