TitleCastCredits.kt
composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/ui/screens/detail/TitleCastCredits.kt
1package eu.friedcutlet.yokan.ui.screens.detail23import androidx.compose.foundation.layout.Arrangement4import androidx.compose.foundation.layout.Column5import androidx.compose.foundation.layout.PaddingValues6import androidx.compose.foundation.layout.fillMaxWidth7import androidx.compose.foundation.layout.padding8import androidx.compose.foundation.layout.size9import androidx.compose.foundation.layout.width10import androidx.compose.foundation.lazy.LazyRow11import androidx.compose.foundation.lazy.itemsIndexed12import androidx.compose.material3.MaterialTheme13import androidx.compose.material3.Text14import androidx.compose.runtime.Composable15import androidx.compose.runtime.remember16import androidx.compose.ui.Modifier17import androidx.compose.ui.semantics.semantics18import androidx.compose.ui.text.font.FontWeight19import androidx.compose.ui.text.style.TextOverflow20import androidx.compose.ui.unit.dp21import eu.friedcutlet.yokan.domain.TitleCredit22import eu.friedcutlet.yokan.ui.components.CoverImage23import org.jetbrains.compose.resources.stringResource24import yokan.composeapp.generated.resources.Res25import yokan.composeapp.generated.resources.detail_cast26import yokan.composeapp.generated.resources.detail_cast_character2728@Composable29internal fun TitleCastCredits(cast: List<TitleCredit>, modifier: Modifier = Modifier) {30 if (cast.isEmpty()) return31 Column(modifier.fillMaxWidth().padding(vertical = 12.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {32 Text(stringResource(Res.string.detail_cast), style = MaterialTheme.typography.titleMedium, modifier = Modifier.padding(horizontal = 16.dp))33 LazyRow(34 contentPadding = PaddingValues(horizontal = 16.dp),35 horizontalArrangement = Arrangement.spacedBy(16.dp),36 ) {37 // Position also disambiguates repeated credits supplied by older backups/sources.38 itemsIndexed(cast, key = { index, credit -> "$index:${credit.name}:${credit.role}:${credit.character}" }, contentType = { _, _ -> "credit" }) { _, credit ->39 val initials = remember(credit.name) {40 credit.name.split(' ').filter(String::isNotBlank).take(2).joinToString("") { it.take(1) }.uppercase()41 }42 Column(Modifier.width(144.dp).semantics(mergeDescendants = true) {}, verticalArrangement = Arrangement.spacedBy(4.dp)) {43 CoverImage(credit.imageUrl, contentDescription = null, fallbackInitials = initials,44 shape = MaterialTheme.shapes.small, modifier = Modifier.size(64.dp, 80.dp))45 Text(credit.name, style = MaterialTheme.typography.bodyMedium, fontWeight = FontWeight.Medium,46 minLines = 2, maxLines = 2, overflow = TextOverflow.Ellipsis)47 Text(credit.character?.let { stringResource(Res.string.detail_cast_character, it) }.orEmpty(),48 style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant,49 minLines = 2, maxLines = 2, overflow = TextOverflow.Ellipsis)50 Text(credit.role.orEmpty(), style = MaterialTheme.typography.bodySmall,51 color = MaterialTheme.colorScheme.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis)52 }53 }54 }55 }56}57