fix: avoid syncing beat metadata twice when returning from Now Playing -> Library

This commit is contained in:
2026-05-31 11:53:20 +02:00
parent f7c5b932e9
commit 19bbccf244
4 changed files with 24 additions and 2 deletions

View File

@@ -453,6 +453,22 @@ class LockstepViewModel(
}
}
/** Set before popping Now Playing; [consumeSuppressNextLibraryMetadataSync] skips one Library batch sync. */
@Volatile
private var suppressNextLibraryMetadataSync = false
fun suppressNextLibraryMetadataSync() {
suppressNextLibraryMetadataSync = true
}
fun consumeSuppressNextLibraryMetadataSync(): Boolean {
if (!suppressNextLibraryMetadataSync) {
return false
}
suppressNextLibraryMetadataSync = false
return true
}
suspend fun syncPendingMetadata(): String? {
val token = spotifyAccessToken.value
if (token.isNullOrBlank()) {

View File

@@ -116,7 +116,10 @@ fun LockstepAppNavHost(
playlistId = playlistId,
playback = playback,
viewModel = viewModel,
onBack = { navController.popBackStack() },
onBack = {
viewModel.suppressNextLibraryMetadataSync()
navController.popBackStack()
},
)
}
composable(

View File

@@ -2,6 +2,7 @@ package at.lockstep.player.ui
import android.Manifest
import android.content.pm.PackageManager
import androidx.activity.compose.BackHandler
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.layout.Arrangement
@@ -169,6 +170,7 @@ fun NowPlayingRoute(
modifier: Modifier = Modifier,
) {
val context = LocalContext.current
BackHandler(onBack = onBack)
val collectRunData by viewModel.collectRunData.collectAsStateWithLifecycle()
val collector = remember { RunDataCollector(context) }
val runSessionFolder = remember { RunDataStorage.newRunSessionFolderName() }

View File

@@ -49,10 +49,11 @@ fun LibraryScreen(
LaunchedEffect(token) {
if (token.isNullOrBlank()) return@LaunchedEffect
val skipMetadataSync = viewModel.consumeSuppressNextLibraryMetadataSync()
val errors =
listOfNotNull(
viewModel.syncJukeboxIfToken(),
viewModel.syncPendingMetadata(),
if (skipMetadataSync) null else viewModel.syncPendingMetadata(),
)
if (errors.isNotEmpty()) {
Toast.makeText(context, errors.joinToString("\n"), Toast.LENGTH_LONG).show()