queue: suppress shuffled context removal

This commit is contained in:
austinried
2026-11-14 12:03:42 +00:00
parent 04dba5ef76
commit ddc6811c34
2 changed files with 115 additions and 11 deletions
@@ -490,10 +490,15 @@ fun QueueScreen(
) )
}, },
onClick = { onPlay(row.position) }, onClick = { onPlay(row.position) },
onRemove = { onRemove =
onRemove(row.position) if (enabled) {
showUndo(queueRemoved) {
}, onRemove(row.position)
showUndo(queueRemoved)
}
} else {
null
},
) )
} }
} }
@@ -579,7 +584,7 @@ private fun QueueRowItem(
coverArt: (String?, Boolean) -> CoverArtRef?, coverArt: (String?, Boolean) -> CoverArtRef?,
dragHandle: Modifier?, dragHandle: Modifier?,
onClick: () -> Unit, onClick: () -> Unit,
onRemove: () -> Unit, onRemove: (() -> Unit)?,
) { ) {
SongRow( SongRow(
song = row.song.song, song = row.song.song,
@@ -588,12 +593,14 @@ private fun QueueRowItem(
isPlaying = isPlaying, isPlaying = isPlaying,
trailingContent = { trailingContent = {
Row(verticalAlignment = Alignment.CenterVertically) { Row(verticalAlignment = Alignment.CenterVertically) {
IconButton(onClick = onRemove) { if (onRemove != null) {
Icon( IconButton(onClick = onRemove) {
imageVector = Icons.Rounded.Close, Icon(
contentDescription = stringResource(R.string.queue_remove), imageVector = Icons.Rounded.Close,
modifier = Modifier.size(20.dp), contentDescription = stringResource(R.string.queue_remove),
) modifier = Modifier.size(20.dp),
)
}
} }
if (dragHandle != null) { if (dragHandle != null) {
Box(modifier = Modifier.size(40.dp).then(dragHandle), contentAlignment = Alignment.Center) { Box(modifier = Modifier.size(40.dp).then(dragHandle), contentAlignment = Alignment.Center) {
@@ -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<ComponentActivity>()
@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,
)
}