Skip to content

Instantly share code, notes, and snippets.

@bleszerd
Created September 27, 2021 22:28
Show Gist options
  • Select an option

  • Save bleszerd/e11468371cd1bee2d29d6cd6bf76ed2a to your computer and use it in GitHub Desktop.

Select an option

Save bleszerd/e11468371cd1bee2d29d6cd6bf76ed2a to your computer and use it in GitHub Desktop.

Revisions

  1. bleszerd created this gist Sep 27, 2021.
    76 changes: 76 additions & 0 deletions PokedexEntry.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,76 @@
    @ExperimentalCoilApi
    @Composable
    fun PokedexEntry(
    entry: PokedexListEntry,
    navController: NavController,
    modifier: Modifier = Modifier,
    viewModel: PokemonListViewModel = hiltViewModel()
    ) {
    val defaultDominantColor = MaterialTheme.colors.surface.toArgb()
    var dominantColor by rememberSaveable {
    mutableStateOf(defaultDominantColor)
    }

    Box(
    contentAlignment = Center,
    modifier = modifier
    .shadow(5.dp, RoundedCornerShape(10.dp))
    .clip(RoundedCornerShape(10.dp))
    .aspectRatio(1f)
    .background(
    Brush.verticalGradient(
    listOf(
    Color(dominantColor),
    Color(defaultDominantColor),
    )
    )
    )
    .clickable {
    navController.navigate(
    "pokemon_detail_screen/${dominantColor}/${entry.pokemonName}"
    )
    }
    ) {
    Column {
    Image(
    painter = rememberImagePainter(
    data = entry.imageUrl,
    builder = {
    crossfade(true)
    transformations(
    object : Transformation {
    override fun key(): String {
    return entry.imageUrl
    }

    override suspend fun transform(
    pool: BitmapPool,
    input: Bitmap,
    size: coil.size.Size
    ): Bitmap {
    viewModel.calcDominantColor(input) { color ->
    dominantColor = color.toArgb()
    }
    return input
    }
    }
    )
    }
    ),
    contentDescription = entry.pokemonName,
    modifier = Modifier
    .size(120.dp)
    .align(CenterHorizontally),
    )

    Text(
    text = entry.pokemonName,
    fontFamily = RobotoCondensed,
    fontSize = 20.sp,
    textAlign = TextAlign.Center,
    modifier = Modifier
    .fillMaxWidth()
    )
    }
    }
    }