address review: fix reveal anchoring and ID3v1 names

RevealNewFrontItem compared the post-anchor firstVisibleItemIndex against the
front threshold, so it only worked when the row was at index 0 and exactly one
item was prepended. Recover the pre-change position by subtracting the number
of items now before the old front, and cover the one-in and multi-prepend cases
with integration tests.

Adopt the canonical TagLib/mutagen names for two extended indices: 133 is
Worldbeat (was Negerpunk) and 148 is Abstract (was Christmas). Drop the unused
default on SongInfoDialog's genres argument.
This commit is contained in:
austinried
2026-10-04 00:30:07 +00:00
parent e8ac683b42
commit c3bfb612f8
6 changed files with 87 additions and 21 deletions
@@ -146,7 +146,7 @@ private val ID3V1_GENRES =
"Terror",
"Indie",
"Britpop",
"Negerpunk",
"Worldbeat",
"Polsk Punk",
"Beat",
"Christian Gangsta Rap",
@@ -161,7 +161,7 @@ private val ID3V1_GENRES =
"Anime",
"Jpop",
"Synthpop",
"Christmas",
"Abstract",
"Art Rock",
"Baroque",
"Bhangra",
@@ -36,7 +36,7 @@ fun SongInfoDialog(
localFile: File?,
streamEncoding: AudioEncoding?,
onDismiss: () -> Unit,
genres: List<String> = emptyList(),
genres: List<String>,
) {
val context = LocalContext.current
var encoding by remember(song.id, localFile) { mutableStateOf<AudioEncoding?>(null) }
@@ -535,13 +535,19 @@ private const val REVEAL_NEAR_FRONT = 1
internal fun shouldRevealNewFront(
previousKey: Any?,
firstKey: Any?,
insertedCount: Int,
firstVisibleItemIndex: Int,
): Boolean = firstKey != null && previousKey != null && previousKey != firstKey && firstVisibleItemIndex <= REVEAL_NEAR_FRONT
): Boolean =
firstKey != null &&
previousKey != null &&
previousKey != firstKey &&
insertedCount >= 0 &&
firstVisibleItemIndex - insertedCount <= REVEAL_NEAR_FRONT
/**
* Scrolls a row back to the front when a new first item appears while it is already at/near the
* start. The lazy layout anchors to the previously visible key, so an item that moves to the front
* after a play lands left of the viewport and is not revealed.
* start. The lazy layout anchors to the previously visible key, so a row at the start advances by
* the number of prepended items; subtracting that recovers the position the user was actually at.
*/
@Composable
internal fun <T> RevealNewFrontItem(
@@ -552,7 +558,11 @@ internal fun <T> RevealNewFrontItem(
val firstKey = items.firstOrNull()?.let(key)
var previous by remember { mutableStateOf<Any?>(null) }
LaunchedEffect(firstKey) {
if (shouldRevealNewFront(previous, firstKey, state.firstVisibleItemIndex)) state.animateScrollToItem(0)
val oldFront = previous
val inserted = if (oldFront != null) items.indexOfFirst { key(it) == oldFront } else -1
if (shouldRevealNewFront(oldFront, firstKey, inserted, state.firstVisibleItemIndex)) {
state.animateScrollToItem(0)
}
if (firstKey != null) previous = firstKey
}
}