Skip to content

Commit

Permalink
added legendary pokemon info to details
Browse files Browse the repository at this point in the history
  • Loading branch information
lexa-diky committed Mar 11, 2023
1 parent 8d7adca commit 703fa36
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ data class PokemonSpeciesDetails(
val name: String,
val localeName: String,
val primaryVariety: PokemonDetails,
val varieties: List<PokemonDetails>
val varieties: List<PokemonDetails>,
val isLegendary: Boolean,
val isMythical: Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class GetPokemonSpeciesDetailsUseCase(
name = species.name,
localeName = localeName,
primaryVariety = mapPokemonDetails(defaultVariety),
isLegendary = species.isLegendary,
isMythical = species.isMythical,
varieties = species.varieties.map {
async {
pokeApiClient.pokemon.get(it).bind(::identity)
Expand All @@ -63,18 +65,18 @@ class GetPokemonSpeciesDetailsUseCase(
Error
}

private fun mapPokemonDetails(defaultVariety: Pokemon): PokemonDetails {
val stats = defaultVariety.stats.associate { slot ->
private fun mapPokemonDetails(variety: Pokemon): PokemonDetails {
val stats = variety.stats.associate { slot ->
slot.stat.asPokemonStat() to slot.baseStat
}
return PokemonDetails(
name = defaultVariety.name,
types = defaultVariety.types.map { it.type.asType() },
sprites = extractSprites(defaultVariety),
name = variety.name,
types = variety.types.map { it.type.asType() },
sprites = extractSprites(variety),
stats = stats,
archetype = makeArchetype(stats),
height = defaultVariety.height.toDouble() / POKEMON_DIMENSION_MODIFIER,
weight = defaultVariety.weight.toDouble() / POKEMON_DIMENSION_MODIFIER
height = variety.height.toDouble() / POKEMON_DIMENSION_MODIFIER,
weight = variety.weight.toDouble() / POKEMON_DIMENSION_MODIFIER
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,9 @@ internal data class PokemonDetailsState(

val types: List<PokemonType> get() = selectedVariety?.types.orEmpty()

val dimensions: List<PokemonPhysicalDimension> = extractDimensions(selectedVariety)
val dimensions: List<PokemonPhysicalDimension> = extractDimensions(
pokemonSpeciesDetails,
selectedVariety,
false
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal class InfoSubPageViewModel(
is Either.Left -> state.copy(error = UIError.default())
is Either.Right -> state.copy(
descriptions = data.value.toData(),
dimensions = extractDimensions(pokemon)
dimensions = extractDimensions(species, pokemon, true)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,56 @@
package io.github.lexadiky.pdx.feature.pokemon.details.utils

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Star
import io.github.lexadiky.pdx.domain.pokemon.entity.PokemonDetails
import io.github.lexadiky.pdx.domain.pokemon.entity.PokemonSpeciesDetails
import io.github.lexadiky.pdx.feature.pokemon.details.entitiy.PokemonPhysicalDimension
import io.github.lexadiky.pdx.lib.resources.image.ImageResource
import io.github.lexadiky.pdx.lib.resources.image.from
import io.github.lexadiky.pdx.lib.resources.string.StringResource
import io.github.lexadiky.pdx.lib.resources.string.format
import io.github.lexadiky.pdx.lib.resources.string.from
import io.github.lexadiky.pdx.lib.uikit.R
import io.github.lexadiky.pdx.ui.uikit.resources.from

internal fun extractDimensions(details: PokemonDetails?): List<PokemonPhysicalDimension> = buildList {
internal fun extractDimensions(
species: PokemonSpeciesDetails?,
details: PokemonDetails?,
addMythicalOrLegendaryInfo: Boolean,
): List<PokemonPhysicalDimension> = buildList {
details ?: return@buildList
species ?: return@buildList

add(
PokemonPhysicalDimension(
icon = ImageResource.from(R.drawable.uikit_ic_height),
label = StringResource.from(io.github.lexadiky.pdx.feature.pokemon.details.R.string.feature_pokemon_details_dimension_height)
.format(details.height)
)
icon = ImageResource.from(R.drawable.uikit_ic_height),
label = StringResource.from(io.github.lexadiky.pdx.feature.pokemon.details.R.string.feature_pokemon_details_dimension_height)
.format(details.height)
)
)
add(
PokemonPhysicalDimension(
icon = ImageResource.from(R.drawable.uikit_ic_scale),
label = StringResource.from(io.github.lexadiky.pdx.feature.pokemon.details.R.string.feature_pokemon_details_dimension_weight)
.format(details.weight)
)
icon = ImageResource.from(R.drawable.uikit_ic_scale),
label = StringResource.from(io.github.lexadiky.pdx.feature.pokemon.details.R.string.feature_pokemon_details_dimension_weight)
.format(details.weight)
)
)

if (addMythicalOrLegendaryInfo) {
if (species.isLegendary) {
add(
PokemonPhysicalDimension(
icon = ImageResource.from(Icons.Default.Star),
label = StringResource.from(io.github.lexadiky.pdx.feature.pokemon.details.R.string.feature_pokemon_details_dimension_is_legendary)
)
)
} else if (species.isMythical) {
add(
PokemonPhysicalDimension(
icon = ImageResource.from(Icons.Default.Star),
label = StringResource.from(io.github.lexadiky.pdx.feature.pokemon.details.R.string.feature_pokemon_details_dimension_is_mythical)
)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

<string name="feature_pokemon_details_dimension_weight">%s kg</string>
<string name="feature_pokemon_details_dimension_height">%s m</string>
<string name="feature_pokemon_details_dimension_is_legendary">Legendary</string>
<string name="feature_pokemon_details_dimension_is_mythical">Mythical</string>

<string name="feature_pokemon_details_section_stats_total_value">Total</string>
<string name="feature_pokemon_details_section_stats_archetype">Archetype</string>
Expand Down

0 comments on commit 703fa36

Please sign in to comment.