Skip to content

Commit 887c958

Browse files
codebutlerClaudeclaude
authored
fix: use composite key for CardInfo in HelpScreen grid (#244)
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 <claude@codebutler.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c116f05 commit 887c958

File tree

2 files changed

+6
-4
lines changed
  • app/src/commonMain/kotlin/com/codebutler/farebot/shared/ui/screen
  • transit/src/commonMain/kotlin/com/codebutler/farebot/transit

2 files changed

+6
-4
lines changed

app/src/commonMain/kotlin/com/codebutler/farebot/shared/ui/screen/HelpScreen.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,14 @@ fun ExploreContent(
280280
.padding(horizontal = 12.dp, vertical = 8.dp),
281281
)
282282
}
283-
items(cards, key = { it.nameRes.key }) { card ->
283+
items(cards, key = { it.uniqueKey }) { card ->
284284
CardImageTile(
285285
card = card,
286286
cardName = cardNames[card.nameRes.key] ?: "",
287287
isSupported = card.cardType in supportedCardTypes,
288288
isKeysRequired = card.keysRequired && card.keyBundle !in loadedKeyBundles,
289289
onTap = {
290-
selectedCardKey = card.nameRes.key
290+
selectedCardKey = card.uniqueKey
291291
},
292292
)
293293
}
@@ -337,7 +337,7 @@ fun ExploreContent(
337337
// Bottom sheet for selected card details
338338
val selectedCard =
339339
selectedCardKey?.let { key ->
340-
supportedCards.find { it.nameRes.key == key }
340+
supportedCards.find { it.uniqueKey == key }
341341
}
342342
if (selectedCard != null) {
343343
ModalBottomSheet(

transit/src/commonMain/kotlin/com/codebutler/farebot/transit/CardInfo.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@ data class CardInfo(
4141
/** Brand color as 0xRRGGBB (no alpha). Null if unknown — UI will use a theme-appropriate fallback. */
4242
val brandColor: Int?,
4343
val credits: List<String> = emptyList(),
44-
)
44+
) {
45+
val uniqueKey: String get() = "${nameRes.key}:${cardType.name}"
46+
}

0 commit comments

Comments
 (0)