From fba4b933b0e3f6ff4ebf9ffdcb8d2ec6e4d9e260 Mon Sep 17 00:00:00 2001 From: davotoula Date: Sun, 7 Jun 2026 22:16:29 +0200 Subject: [PATCH] Code review: - Make birdex_species_preview_more a keyed on the remaining count - Bound the species preview with maxLines=2 - Hoist the joined-names remember out of the conditional (stable slot). - Drop the unused accountViewModel parameter - BirdexEvent.speciesCount() derives from speciesNames().size instead of re-scanning tags - remember() the joined species-name string so it is not rebuilt on every recomposition. --- .../vitorpamplona/amethyst/ui/note/NoteCompose.kt | 2 +- .../amethyst/ui/note/types/Birdex.kt | 15 +++++---------- .../screen/loggedIn/threadview/ThreadFeedView.kt | 2 +- amethyst/src/main/res/values/strings.xml | 5 ++++- .../quartz/experimental/birdstar/BirdexEvent.kt | 3 +-- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt index dbb4a20e1d..b33649a6a0 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/NoteCompose.kt @@ -1267,7 +1267,7 @@ private fun RenderNoteRow( } is BirdexEvent -> { - RenderBirdex(baseNote, makeItShort, accountViewModel) + RenderBirdex(baseNote) } is HighlightEvent -> { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Birdex.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Birdex.kt index 8346a62aed..5237134276 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Birdex.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Birdex.kt @@ -34,8 +34,6 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.model.Note -import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel -import com.vitorpamplona.amethyst.ui.stringRes import com.vitorpamplona.amethyst.ui.theme.placeholderText import com.vitorpamplona.amethyst.ui.theme.replyModifier import com.vitorpamplona.quartz.experimental.birdstar.BirdexEvent @@ -50,19 +48,16 @@ private const val SPECIES_PREVIEW_LIMIT = 6 * bounded regardless of how many species a Birdex holds, we show the count and a * short preview of scientific names with a "+N more" suffix — no images, no * expansion, no network calls. The card is identical in the feed and the opened - * view (it ignores [makeItShort]). + * view, so it takes no makeItShort flag. */ @Composable -fun RenderBirdex( - baseNote: Note, - makeItShort: Boolean, - accountViewModel: AccountViewModel, -) { +fun RenderBirdex(baseNote: Note) { val noteEvent = baseNote.event as? BirdexEvent ?: return val names = remember(noteEvent) { noteEvent.speciesNames() } val preview = remember(names) { names.take(SPECIES_PREVIEW_LIMIT) } val remaining = names.size - preview.size + val joined = remember(preview) { preview.joinToString(", ") } Column(MaterialTheme.colorScheme.replyModifier.padding(10.dp)) { Text( @@ -72,16 +67,16 @@ fun RenderBirdex( if (preview.isNotEmpty()) { Spacer(Modifier.height(6.dp)) - val joined = preview.joinToString(", ") Text( text = if (remaining > 0) { - stringRes(R.string.birdex_species_preview_more, joined, remaining.toString()) + pluralStringResource(R.plurals.birdex_species_preview_more, remaining, joined, remaining) } else { joined }, style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.placeholderText, + maxLines = 2, overflow = TextOverflow.Ellipsis, ) } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/threadview/ThreadFeedView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/threadview/ThreadFeedView.kt index 689c8391a9..2de99d5f54 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/threadview/ThreadFeedView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/threadview/ThreadFeedView.kt @@ -772,7 +772,7 @@ private fun FullBleedNoteCompose( } else if (noteEvent is FundraiserEvent) { RenderFundraiser(baseNote, makeItShort = false, accountViewModel, nav) } else if (noteEvent is BirdexEvent) { - RenderBirdex(baseNote, makeItShort = false, accountViewModel) + RenderBirdex(baseNote) } else if (noteEvent is RepostEvent || noteEvent is GenericRepostEvent) { RenderRepost(baseNote, quotesLeft = 3, backgroundColor, accountViewModel, nav) } else if (noteEvent is RelayDiscoveryEvent) { diff --git a/amethyst/src/main/res/values/strings.xml b/amethyst/src/main/res/values/strings.xml index 400852fb5f..debeb95ff7 100644 --- a/amethyst/src/main/res/values/strings.xml +++ b/amethyst/src/main/res/values/strings.xml @@ -3142,7 +3142,10 @@ Birdex · %1$d species Birdex · %1$d species - %1$s +%2$s more + + %1$s +%2$d more + %1$s +%2$d more + Goal amount (sats) 100000 Describe your goal diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/experimental/birdstar/BirdexEvent.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/experimental/birdstar/BirdexEvent.kt index 4b170db4b8..e147d4c556 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/experimental/birdstar/BirdexEvent.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/experimental/birdstar/BirdexEvent.kt @@ -59,13 +59,12 @@ class BirdexEvent( fun speciesNames() = tags.mapValueTagged("n") { it } /** Number of collected species (one `n` tag per species). */ - fun speciesCount() = tags.count { it.size > 1 && it[0] == "n" } + fun speciesCount() = speciesNames().size /** Publisher-provided human-readable summary, from the `alt` tag (may be null). */ fun summary() = tags.firstTagValue("alt") companion object { const val KIND = 12473 - const val ALT_DESCRIPTION = "A Birdex species collection" } }