Code review:

- Make birdex_species_preview_more a <plurals> 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.
This commit is contained in:
davotoula
2026-06-07 22:37:05 +02:00
parent 98ff13b83f
commit fba4b933b0
5 changed files with 12 additions and 15 deletions
@@ -1267,7 +1267,7 @@ private fun RenderNoteRow(
}
is BirdexEvent -> {
RenderBirdex(baseNote, makeItShort, accountViewModel)
RenderBirdex(baseNote)
}
is HighlightEvent -> {
@@ -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,
)
}
@@ -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) {
+4 -1
View File
@@ -3142,7 +3142,10 @@
<item quantity="one">Birdex · %1$d species</item>
<item quantity="other">Birdex · %1$d species</item>
</plurals>
<string name="birdex_species_preview_more">%1$s +%2$s more</string>
<plurals name="birdex_species_preview_more">
<item quantity="one">%1$s +%2$d more</item>
<item quantity="other">%1$s +%2$d more</item>
</plurals>
<string name="goal_amount_label">Goal amount (sats)</string>
<string name="goal_amount_placeholder">100000</string>
<string name="goal_description_label">Describe your goal</string>
@@ -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"
}
}