Add name of pokemon under its image

This commit is contained in:
Joren 2024-04-29 18:00:35 +02:00
parent 9ee9d5af0e
commit 8419c74f5f
Signed by untrusted user who does not match committer: Joren
GPG Key ID: 280E33DFBC0F1B55

View File

@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items import androidx.compose.foundation.lazy.grid.items
@ -62,6 +63,7 @@ fun PokeSearch(pokeSearchViewModel: PokeSearchViewModel) {
if (results.isNotEmpty()) { if (results.isNotEmpty()) {
LazyVerticalGrid( LazyVerticalGrid(
columns = GridCells.Adaptive(150.dp), columns = GridCells.Adaptive(150.dp),
verticalArrangement = Arrangement.spacedBy(10.dp)
) { ) {
items(items = results, key = { pokemon -> pokemon.id }) { pokemon -> items(items = results, key = { pokemon -> pokemon.id }) { pokemon ->
PokemonCard(pokemon) PokemonCard(pokemon)
@ -84,14 +86,29 @@ fun PokemonCard(pokemon: PokemonDetails) {
.padding(4.dp) .padding(4.dp)
.fillMaxWidth() .fillMaxWidth()
.aspectRatio(1f) .aspectRatio(1f)
) {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Bottom
) { ) {
AsyncImage( AsyncImage(
model = ImageRequest.Builder(context = LocalContext.current).data(pokemon.sprites.other.officialArtwork.frontDefault) model = ImageRequest.Builder(context = LocalContext.current).data(pokemon.sprites.other.officialArtwork.frontDefault)
.crossfade(true).build(), .crossfade(true).build(),
contentDescription = pokemon.name, contentDescription = pokemon.name,
contentScale = ContentScale.Crop, contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxWidth() modifier = Modifier
.fillMaxWidth()
.weight(1f)
) )
Text(
text = pokemon.name.replace("-", " "),
style = MaterialTheme.typography.bodySmall,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 8.dp, vertical = 4.dp) // Adjust padding as needed
.wrapContentSize(Alignment.Center)
)
}
} }
} }