From ddc6811c344b474d64af28efda4bf9c3ca30d933 Mon Sep 17 00:00:00 2001 From: austinried <4966622+austinried@users.noreply.github.com> Date: Sat, 14 Nov 2026 01:43:39 +0000 Subject: [PATCH] queue: suppress shuffled context removal --- .../com/subtracks/ui/playback/QueueScreen.kt | 29 +++--- .../subtracks/ui/playback/QueueScreenTest.kt | 97 +++++++++++++++++++ 2 files changed, 115 insertions(+), 11 deletions(-) create mode 100644 app/src/test/kotlin/com/subtracks/ui/playback/QueueScreenTest.kt diff --git a/app/src/main/kotlin/com/subtracks/ui/playback/QueueScreen.kt b/app/src/main/kotlin/com/subtracks/ui/playback/QueueScreen.kt index 9c3ed189..80c57015 100644 --- a/app/src/main/kotlin/com/subtracks/ui/playback/QueueScreen.kt +++ b/app/src/main/kotlin/com/subtracks/ui/playback/QueueScreen.kt @@ -490,10 +490,15 @@ fun QueueScreen( ) }, onClick = { onPlay(row.position) }, - onRemove = { - onRemove(row.position) - showUndo(queueRemoved) - }, + onRemove = + if (enabled) { + { + onRemove(row.position) + showUndo(queueRemoved) + } + } else { + null + }, ) } } @@ -579,7 +584,7 @@ private fun QueueRowItem( coverArt: (String?, Boolean) -> CoverArtRef?, dragHandle: Modifier?, onClick: () -> Unit, - onRemove: () -> Unit, + onRemove: (() -> Unit)?, ) { SongRow( song = row.song.song, @@ -588,12 +593,14 @@ private fun QueueRowItem( isPlaying = isPlaying, trailingContent = { Row(verticalAlignment = Alignment.CenterVertically) { - IconButton(onClick = onRemove) { - Icon( - imageVector = Icons.Rounded.Close, - contentDescription = stringResource(R.string.queue_remove), - modifier = Modifier.size(20.dp), - ) + if (onRemove != null) { + IconButton(onClick = onRemove) { + Icon( + imageVector = Icons.Rounded.Close, + contentDescription = stringResource(R.string.queue_remove), + modifier = Modifier.size(20.dp), + ) + } } if (dragHandle != null) { Box(modifier = Modifier.size(40.dp).then(dragHandle), contentAlignment = Alignment.Center) { diff --git a/app/src/test/kotlin/com/subtracks/ui/playback/QueueScreenTest.kt b/app/src/test/kotlin/com/subtracks/ui/playback/QueueScreenTest.kt new file mode 100644 index 00000000..70916fc5 --- /dev/null +++ b/app/src/test/kotlin/com/subtracks/ui/playback/QueueScreenTest.kt @@ -0,0 +1,97 @@ +package com.subtracks.ui.playback + +import androidx.activity.ComponentActivity +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.junit4.v2.createAndroidComposeRule +import androidx.compose.ui.test.onNodeWithContentDescription +import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.test.performClick +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.subtracks.data.model.AlbumSongItem +import com.subtracks.data.model.Song +import com.subtracks.ui.theme.SubtracksTheme +import org.junit.Assert.assertEquals +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.annotation.GraphicsMode + +@RunWith(AndroidJUnit4::class) +@GraphicsMode(GraphicsMode.Mode.NATIVE) +class QueueScreenTest { + @get:Rule + val composeRule = createAndroidComposeRule() + + @Test + fun shuffledContextRowsDoNotExposeRemoval() { + render(row(upNext = false), shuffle = true) + + composeRule.onNodeWithContentDescription("Remove from queue").assertDoesNotExist() + composeRule.onNodeWithText("Removed from queue").assertDoesNotExist() + } + + @Test + fun shuffledUpNextRowsStillRemoveAndShowUndo() { + var removed: Long? = null + render(row(upNext = true), shuffle = true, onRemove = { removed = it }) + + composeRule.onNodeWithContentDescription("Remove from queue").performClick() + + assertEquals(0L, removed) + composeRule.onNodeWithText("Removed from queue").assertIsDisplayed() + composeRule.onNodeWithText("Undo").assertIsDisplayed() + } + + private fun render( + row: QueueRow, + shuffle: Boolean, + onRemove: (Long) -> Unit = {}, + ) { + composeRule.setContent { + SubtracksTheme { + QueueScreen( + rows = listOf(row), + ready = true, + currentPosition = null, + currentSongId = null, + shuffle = shuffle, + coverArt = { _, _ -> null }, + onBack = {}, + onPlay = {}, + onRemove = onRemove, + onReorder = { _, _ -> }, + onMove = { _, _ -> false }, + onLoadOlder = {}, + onLoadNewer = {}, + onUndo = {}, + ) + } + } + } + + private fun row(upNext: Boolean) = + QueueRow( + id = 0, + position = 0, + song = + AlbumSongItem( + song = + Song( + sourceId = 1, + id = "s1", + albumId = "al1", + artistId = "ar1", + title = "Song", + album = "Album", + artist = "Artist", + duration = 100, + track = 1, + disc = 1, + starred = null, + genre = null, + ), + coverArt = null, + ), + upNext = upNext, + ) +}