Native Android client for Spotify, built with Jetpack Compose
Kotlin ad-freeadblockandroidjetpack-composekotlinlyricsmusic-playermusic-videomyspotispotifyspotify-adblockerspotify-clientspotify-connectspotui
Queue: the carried row an opaque card through the drop; an edit made while the page is rebuilt waits for its queue
kota-zo82d30b207100
diff --git a/base/app/src/main/java/com/music/spotui/di/SongPlayer.kt b/base/app/src/main/java/com/music/spotui/di/SongPlayer.ktindex 23b35ae6..b81438ae 100644--- a/base/app/src/main/java/com/music/spotui/di/SongPlayer.kt+++ b/base/app/src/main/java/com/music/spotui/di/SongPlayer.kt@@ -2838,6 +2838,21 @@ object SongPlayer {all.firstOrNull { it.uri == item.uri && (item.uid.isBlank() || it.uid == item.uid) } ?: all.firstOrNull { it.uri == item.uri }}+ /**+ * [item] in the page's queue, waited for when the page does not list it yet: an edit made while+ * the page is rebuilt (just after an install or a "player never started" reload, log 04/11+ * 19:10) found no queue and was dropped without a word, the row then going back.+ */+ private suspend fun liveItem(item: QueueItem): app.myspoti.api.NowPlaying? {+ apiItem(item)?.let { return it }+ val q = kotlinx.coroutines.withTimeoutOrNull(QUEUE_READY_MS) {+ api.player.queue.first { q -> q != null && (q.queued + q.nextUp).any { it.uri == item.uri } }+ } ?: return null.also { app.myspoti.host.android.Logbook.log("queue edit: ${item.uri} not in the page's queue, edit dropped") }+ val all = q.queued + q.nextUp+ return all.firstOrNull { it.uri == item.uri && it.uid == item.uid } ?: all.firstOrNull { it.uri == item.uri }+ }+ private const val QUEUE_READY_MS = 12_000L+/*** Queue edits, one at a time and each after Spotify has shown the one before. Sent together* they raced in the Web Player: "move up into the queue" (add + remove) lost its remove and@@ -2972,8 +2987,8 @@ object SongPlayer {}// Read when the edit runs, after the ones before it: never a row id that has gone stale.queueCommand {- val a = apiItem(item) ?: return@queueCommand- val b = apiItem(target) ?: return@queueCommand+ val a = liveItem(item) ?: return@queueCommand+ val b = liveItem(target) ?: return@queueCommandval before = api.player.queue.valueapi.player.moveInQueue(a, b, after)awaitQueue { it !== before }@@ -2995,7 +3010,7 @@ object SongPlayer {return}queueCommand {- val a = apiItem(item) ?: return@queueCommand+ val a = liveItem(item) ?: return@queueCommandval first = apiQueue?.queued?.firstOrNull()api.player.removeFromQueue(listOf(a))awaitQueue { q -> q.nextUp.none { it.uid == a.uid } }@@ -3015,7 +3030,7 @@ object SongPlayer {if (item.provider == LOCAL) { localIndex(item)?.let(LocalPlayer::remove); return }_queue.value = _queue.value.let { q -> q.copy(queued = q.queued - item, nextUp = q.nextUp - item) }queueCommand {- val a = apiItem(item) ?: return@queueCommand+ val a = liveItem(item) ?: return@queueCommandapi.player.removeFromQueue(listOf(a))awaitQueue { q -> (q.queued + q.nextUp).none { it.uid == a.uid && it.uri == a.uri } }}diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/lyrics/ImmersiveQueuePanel.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/lyrics/ImmersiveQueuePanel.ktindex 1c26dc31..22025d36 100644--- a/base/app/src/main/java/com/music/spotui/ui/immersive/lyrics/ImmersiveQueuePanel.kt+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/lyrics/ImmersiveQueuePanel.kt@@ -321,6 +321,10 @@ fun ImmersiveQueuePanel(modifier: Modifier = Modifier, contentPadding: PaddingVaprivate data class QRow(val key: String, val item: SongPlayer.QueueItem, val queued: Boolean, val index: Int)private const val SLOW_REPORT_MS = 3_000L+/** The carried row's card, opaque. */+private val CARRIED_ROW = Color(0xFF2C2C30)+/** How long the card stays after the drop: the row's spring back to its slot. */+private const val LIFT_SETTLE_MS = 450Lprivate const val HEADING_NEXT = "heading-next"/** The panel's flat order of keys: the queued rows, the context's heading (when it has rows), its rows. */@@ -363,6 +367,12 @@ private fun QueueEntry(row: QRow, removed: SnapshotStateList<String>, dragging:false}})+ // Carried, and for the moment it settles after the drop: an opaque card. A see-through one let+ // the titles of the rows it passed over show through it (seen in a recording, 04/11 19:10).+ var lifted by remember { mutableStateOf(false) }+ LaunchedEffect(dragging) {+ if (dragging) lifted = true else if (lifted) { delay(LIFT_SETTLE_MS); lifted = false }+ }SwipeToDismissBox(state = dismiss,enableDismissFromStartToEnd = false,@@ -370,7 +380,7 @@ private fun QueueEntry(row: QRow, removed: SnapshotStateList<String>, dragging:gesturesEnabled = !dragging,modifier = Modifier.clip(RoundedCornerShape(14.dp))- .background(if (dragging) Color.Black.copy(alpha = 0.45f) else Color.Transparent),+ .background(if (lifted) CARRIED_ROW else Color.Transparent),backgroundContent = {// Drawn only while swiping: the row is transparent, so at rest this × showed// through behind the drag handle.