diff --git a/sources/domain/pokemon/src/main/java/io/github/lexadiky/pdx/domain/pokemon/entity/PokemonSpeciesDetails.kt b/sources/domain/pokemon/src/main/java/io/github/lexadiky/pdx/domain/pokemon/entity/PokemonSpeciesDetails.kt index 7b03bb28..9c98df78 100644 --- a/sources/domain/pokemon/src/main/java/io/github/lexadiky/pdx/domain/pokemon/entity/PokemonSpeciesDetails.kt +++ b/sources/domain/pokemon/src/main/java/io/github/lexadiky/pdx/domain/pokemon/entity/PokemonSpeciesDetails.kt @@ -4,5 +4,7 @@ data class PokemonSpeciesDetails( val name: String, val localeName: String, val primaryVariety: PokemonDetails, - val varieties: List + val varieties: List, + val isLegendary: Boolean, + val isMythical: Boolean ) diff --git a/sources/domain/pokemon/src/main/java/io/github/lexadiky/pdx/domain/pokemon/usecase/GetPokemonSpeciesDetailsUseCase.kt b/sources/domain/pokemon/src/main/java/io/github/lexadiky/pdx/domain/pokemon/usecase/GetPokemonSpeciesDetailsUseCase.kt index 9584ad74..388c4eff 100644 --- a/sources/domain/pokemon/src/main/java/io/github/lexadiky/pdx/domain/pokemon/usecase/GetPokemonSpeciesDetailsUseCase.kt +++ b/sources/domain/pokemon/src/main/java/io/github/lexadiky/pdx/domain/pokemon/usecase/GetPokemonSpeciesDetailsUseCase.kt @@ -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) @@ -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 ) } diff --git a/sources/features/pokemon-details/src/main/java/io/github/lexadiky/pdx/feature/pokemon/details/PokemonDetailsState.kt b/sources/features/pokemon-details/src/main/java/io/github/lexadiky/pdx/feature/pokemon/details/PokemonDetailsState.kt index 4fbab5de..2c8fcbfe 100644 --- a/sources/features/pokemon-details/src/main/java/io/github/lexadiky/pdx/feature/pokemon/details/PokemonDetailsState.kt +++ b/sources/features/pokemon-details/src/main/java/io/github/lexadiky/pdx/feature/pokemon/details/PokemonDetailsState.kt @@ -35,5 +35,9 @@ internal data class PokemonDetailsState( val types: List get() = selectedVariety?.types.orEmpty() - val dimensions: List = extractDimensions(selectedVariety) + val dimensions: List = extractDimensions( + pokemonSpeciesDetails, + selectedVariety, + false + ) } diff --git a/sources/features/pokemon-details/src/main/java/io/github/lexadiky/pdx/feature/pokemon/details/subpage/info/InfoSubPageViewModel.kt b/sources/features/pokemon-details/src/main/java/io/github/lexadiky/pdx/feature/pokemon/details/subpage/info/InfoSubPageViewModel.kt index a8bdc682..669857a9 100644 --- a/sources/features/pokemon-details/src/main/java/io/github/lexadiky/pdx/feature/pokemon/details/subpage/info/InfoSubPageViewModel.kt +++ b/sources/features/pokemon-details/src/main/java/io/github/lexadiky/pdx/feature/pokemon/details/subpage/info/InfoSubPageViewModel.kt @@ -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) ) } } diff --git a/sources/features/pokemon-details/src/main/java/io/github/lexadiky/pdx/feature/pokemon/details/utils/PokemonDimensionUtils.kt b/sources/features/pokemon-details/src/main/java/io/github/lexadiky/pdx/feature/pokemon/details/utils/PokemonDimensionUtils.kt index 5bc7670b..15380292 100644 --- a/sources/features/pokemon-details/src/main/java/io/github/lexadiky/pdx/feature/pokemon/details/utils/PokemonDimensionUtils.kt +++ b/sources/features/pokemon-details/src/main/java/io/github/lexadiky/pdx/feature/pokemon/details/utils/PokemonDimensionUtils.kt @@ -1,6 +1,9 @@ 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 @@ -8,22 +11,46 @@ 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 = buildList { +internal fun extractDimensions( + species: PokemonSpeciesDetails?, + details: PokemonDetails?, + addMythicalOrLegendaryInfo: Boolean, +): List = 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) + ) + ) + } + } } \ No newline at end of file diff --git a/sources/features/pokemon-details/src/main/res/values/strings.xml b/sources/features/pokemon-details/src/main/res/values/strings.xml index cb0a7384..694ef8e8 100644 --- a/sources/features/pokemon-details/src/main/res/values/strings.xml +++ b/sources/features/pokemon-details/src/main/res/values/strings.xml @@ -8,6 +8,8 @@ %s kg %s m + Legendary + Mythical Total Archetype