Skip to content

Native Android client for Spotify, built with Jetpack Compose

Downloads: when an account's downloads put aside at its sign-out cannot be brought back at its sign-in, they stay put aside untouched and are tried again at the next sign-in, and the log says so, instead of an empty downloads folder being marked as that account's and the put-aside one never tried again [skip ci]

kota-zof32b5326f91a
diff --git a/base/app/src/main/java/com/music/spotui/data/offline/OfflineAccounts.kt b/base/app/src/main/java/com/music/spotui/data/offline/OfflineAccounts.kt
index 3e0bde9a..c4f4d67f 100644
--- a/base/app/src/main/java/com/music/spotui/data/offline/OfflineAccounts.kt
+++ b/base/app/src/main/java/com/music/spotui/data/offline/OfflineAccounts.kt
@@ -63,14 +63,19 @@ object OfflineAccounts {
// This account's stamp only goes on an emptied folder or its own: downloads that could not
// be moved keep their own account's stamp, never this one.
val cleared = if (owner != null) putAside(dir, parked(context, owner)) else dir.deleteRecursively()
- if (!cleared) return@withContext false
+ if (!cleared) return@withContext Claimed.NOT_CLEARED
val back = parked(context, key)
- if (back.isDirectory && !back.renameTo(dir)) Logbook.log("offline: this account's downloads could not be brought back")
+ // Not stamped when its own folder did not come back: an empty folder with its stamp would
+ // read as its downloads in place, and the folder put aside would never be tried again.
+ if (back.isDirectory && !(back.renameTo(dir) && dir.isDirectory)) return@withContext Claimed.NOT_BROUGHT_BACK
stamp(dir, key)
- true
+ Claimed.READY
}
- if (!ready) {
- Logbook.log("offline: the other account's downloads could not be put aside")
+ if (ready != Claimed.READY) {
+ Logbook.log(
+ if (ready == Claimed.NOT_CLEARED) "offline: the other account's downloads could not be put aside"
+ else "offline: this account's downloads could not be brought back; they stay put aside, tried again at the next sign-in"
+ )
reopen(context)
return@withLock
}
@@ -81,6 +86,8 @@ object OfflineAccounts {
Logbook.log("offline: this account's downloads in place (${OfflineStore.tracks.size} songs)")
}
+ private enum class Claimed { READY, NOT_CLEARED, NOT_BROUGHT_BACK }
+
/**
* Moves [dir] to [to]. A folder already there (left by an earlier sign-out that went wrong) is
* kept under another name rather than deleted. False when the move failed: [dir] is untouched.