feat: fetch tracks on-demand, logout button
This commit is contained in:
@@ -128,7 +128,7 @@ class LockstepViewModel(
|
||||
app.setSpotifyAccessTokenForApi(token)
|
||||
return withContext(Dispatchers.IO) {
|
||||
try {
|
||||
app.playlistRepository.syncInitial()
|
||||
app.playlistRepository.syncDelta(false)
|
||||
null
|
||||
} catch (e: LockstepApiException) {
|
||||
e.message ?: "Sync failed"
|
||||
@@ -138,6 +138,27 @@ class LockstepViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun syncPlaylistDetailForLibraryOpen(playlistId: String): String? {
|
||||
val token = spotifyAccessToken.value
|
||||
if (token.isNullOrBlank()) {
|
||||
return "Not signed in"
|
||||
}
|
||||
app.setSpotifyAccessTokenForApi(token)
|
||||
return withContext(Dispatchers.IO) {
|
||||
if (app.playlistRepository.getTracks(playlistId).isNotEmpty()) {
|
||||
return@withContext null
|
||||
}
|
||||
try {
|
||||
app.playlistRepository.syncPlaylistDetail(playlistId)
|
||||
null
|
||||
} catch (e: LockstepApiException) {
|
||||
e.message ?: "Load failed"
|
||||
} catch (e: IOException) {
|
||||
e.message ?: "Load failed"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun completeOnboarding() {
|
||||
viewModelScope.launch {
|
||||
prefs.setOnboardingComplete(true)
|
||||
@@ -150,6 +171,14 @@ class LockstepViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
/** Clears the Spotify token and shows the first-run flow again so you can sign in with a fresh token. */
|
||||
fun logoutSpotifyAndRestartOnboarding() {
|
||||
viewModelScope.launch {
|
||||
prefs.setSpotifyAccessToken(null)
|
||||
prefs.setOnboardingComplete(false)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun upsertPairing(
|
||||
playlistId: String,
|
||||
trackId: String,
|
||||
|
||||
Reference in New Issue
Block a user