From f324bc6f1263f3fa01f866e4bd0ba8f1ab1d9df5 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Feb 2026 15:19:49 -0500 Subject: [PATCH] fix: use composite key for CardInfo in HelpScreen grid Multiple CardInfo entries can share the same nameRes (e.g., Troika has both MifareClassic and MifareUltralight variants). Using nameRes.key alone as the LazyVerticalGrid item key caused a duplicate key crash when scrolling. Add CardInfo.uniqueKey that combines nameRes.key with cardType.name, and use it for grid keys and card selection in HelpScreen. Co-Authored-By: Claude Opus 4.6 --- .../com/codebutler/farebot/shared/ui/screen/HelpScreen.kt | 6 +++--- .../kotlin/com/codebutler/farebot/transit/CardInfo.kt | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/commonMain/kotlin/com/codebutler/farebot/shared/ui/screen/HelpScreen.kt b/app/src/commonMain/kotlin/com/codebutler/farebot/shared/ui/screen/HelpScreen.kt index 589399692..a48861868 100644 --- a/app/src/commonMain/kotlin/com/codebutler/farebot/shared/ui/screen/HelpScreen.kt +++ b/app/src/commonMain/kotlin/com/codebutler/farebot/shared/ui/screen/HelpScreen.kt @@ -280,14 +280,14 @@ fun ExploreContent( .padding(horizontal = 12.dp, vertical = 8.dp), ) } - items(cards, key = { it.nameRes.key }) { card -> + items(cards, key = { it.uniqueKey }) { card -> CardImageTile( card = card, cardName = cardNames[card.nameRes.key] ?: "", isSupported = card.cardType in supportedCardTypes, isKeysRequired = card.keysRequired && card.keyBundle !in loadedKeyBundles, onTap = { - selectedCardKey = card.nameRes.key + selectedCardKey = card.uniqueKey }, ) } @@ -337,7 +337,7 @@ fun ExploreContent( // Bottom sheet for selected card details val selectedCard = selectedCardKey?.let { key -> - supportedCards.find { it.nameRes.key == key } + supportedCards.find { it.uniqueKey == key } } if (selectedCard != null) { ModalBottomSheet( diff --git a/transit/src/commonMain/kotlin/com/codebutler/farebot/transit/CardInfo.kt b/transit/src/commonMain/kotlin/com/codebutler/farebot/transit/CardInfo.kt index b09830e52..1de020ff1 100644 --- a/transit/src/commonMain/kotlin/com/codebutler/farebot/transit/CardInfo.kt +++ b/transit/src/commonMain/kotlin/com/codebutler/farebot/transit/CardInfo.kt @@ -41,4 +41,6 @@ data class CardInfo( /** Brand color as 0xRRGGBB (no alpha). Null if unknown — UI will use a theme-appropriate fallback. */ val brandColor: Int?, val credits: List = emptyList(), -) +) { + val uniqueKey: String get() = "${nameRes.key}:${cardType.name}" +}