fix(tracking): close early scrobble sessions

This commit is contained in:
tapframe 2026-07-25 13:04:33 +05:30
parent d8ffd18c4d
commit 44fc3fa62f
2 changed files with 57 additions and 1 deletions

View file

@ -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,

View file

@ -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",