diff --git a/feature/monster-registration/android/src/main/kotlin/br/alexandregpereira/hunter/monster/registration/ui/form/MonsterAbilityDescriptionForm.kt b/feature/monster-registration/android/src/main/kotlin/br/alexandregpereira/hunter/monster/registration/ui/form/MonsterAbilityDescriptionForm.kt index 93eda686..8a5efd86 100644 --- a/feature/monster-registration/android/src/main/kotlin/br/alexandregpereira/hunter/monster/registration/ui/form/MonsterAbilityDescriptionForm.kt +++ b/feature/monster-registration/android/src/main/kotlin/br/alexandregpereira/hunter/monster/registration/ui/form/MonsterAbilityDescriptionForm.kt @@ -39,7 +39,7 @@ internal fun MonsterAbilityDescriptionForm( label = stringResource(R.string.monster_registration_description), multiline = true, onValueChange = { newValue -> - onChanged(newAbilityDescriptions.changeAt(index) { copy(name = newValue) }) + onChanged(newAbilityDescriptions.changeAt(index) { copy(description = newValue) }) } ) diff --git a/feature/monster-registration/android/src/main/kotlin/br/alexandregpereira/hunter/monster/registration/ui/form/MonsterSpeedValuesForm.kt b/feature/monster-registration/android/src/main/kotlin/br/alexandregpereira/hunter/monster/registration/ui/form/MonsterSpeedValuesForm.kt index 301d1ec1..aa98d288 100644 --- a/feature/monster-registration/android/src/main/kotlin/br/alexandregpereira/hunter/monster/registration/ui/form/MonsterSpeedValuesForm.kt +++ b/feature/monster-registration/android/src/main/kotlin/br/alexandregpereira/hunter/monster/registration/ui/form/MonsterSpeedValuesForm.kt @@ -6,8 +6,10 @@ import androidx.compose.ui.res.stringResource import br.alexandregpereira.hunter.domain.model.Monster import br.alexandregpereira.hunter.domain.model.SpeedType import br.alexandregpereira.hunter.monster.registration.R +import br.alexandregpereira.hunter.monster.registration.ui.changeAt +import br.alexandregpereira.hunter.ui.compose.AppTextField import br.alexandregpereira.hunter.ui.compose.Form -import br.alexandregpereira.hunter.ui.compose.FormField +import br.alexandregpereira.hunter.ui.compose.PickerField @Composable internal fun MonsterSpeedValuesForm( @@ -17,42 +19,63 @@ internal fun MonsterSpeedValuesForm( ) { val speedValues = monster.speed.values val types = speedValues.map { it.type } - val options = SpeedType.entries.filterNot { types.contains(it) }.map { it.name } + val options = SpeedType.entries.filterNot { types.contains(it) } + val optionsStrings = options.map { it.toTypeState().getString() } + val newSpeedValues = speedValues.toMutableList() Form( modifier = modifier, title = stringResource(R.string.monster_registration_speed), - formFields = monster.speed.values.map { speedValue -> - listOf( - FormField.Picker( - key = "${speedValue.type.name}-type", - label = stringResource(R.string.monster_registration_speed_type), - value = speedValue.type.name, - options = options, - ), - FormField.Text( - key = "${speedValue.type.name}-name", - label = speedValue.type.name, - value = speedValue.valueFormatted, - ) + ) { + monster.speed.values.mapIndexed { index, speedValue -> + val name = speedValue.type.toTypeState().getString() + PickerField( + value = name, + label = stringResource(R.string.monster_registration_speed_type), + options = optionsStrings, + onValueChange = { optionIndex -> + onMonsterChanged( + monster.copy( + speed = monster.speed.copy( + values = newSpeedValues.changeAt(index) { + copy( + type = options[optionIndex], + ) + } + ) + ) + ) + } ) - }.reduceOrNull { acc, texts -> acc + texts } ?: emptyList(), - onFormChanged = { field -> - val newSpeedValues = speedValues.toMutableList() - val index = newSpeedValues.indexOfFirst { field.key.startsWith(it.type.name) } - if (index != -1) { - when (field.key) { - "${newSpeedValues[index].type.name}-type" -> { - newSpeedValues[index] = newSpeedValues[index].copy( - type = SpeedType.valueOf(field.stringValue), + + AppTextField( + text = speedValue.valueFormatted, + label = name, + onValueChange = { newValue -> + onMonsterChanged( + monster.copy( + speed = monster.speed.copy( + values = newSpeedValues.changeAt(index) { + copy(valueFormatted = newValue) + } + ) ) - } - "${newSpeedValues[index].type.name}-name" -> { - newSpeedValues[index] = newSpeedValues[index].copy(valueFormatted = field.stringValue) - } + ) } - onMonsterChanged(monster.copy(speed = monster.speed.copy(values = newSpeedValues))) - } - }, - ) -} \ No newline at end of file + ) + } + } +} + +private enum class SpeedTypeState(val stringRes: Int) { + BURROW(R.string.monster_registration_speed_type_burrow), + CLIMB(R.string.monster_registration_speed_type_climb), + FLY(R.string.monster_registration_speed_type_fly), + WALK(R.string.monster_registration_speed_type_walk), + SWIM(R.string.monster_registration_speed_type_swim), +} + +private fun SpeedType.toTypeState() = SpeedTypeState.valueOf(name) + +@Composable +private fun SpeedTypeState.getString() = stringResource(stringRes) diff --git a/feature/monster-registration/android/src/main/res/values-pt-rBR/strings.xml b/feature/monster-registration/android/src/main/res/values-pt-rBR/strings.xml index b9859afc..ed461b75 100644 --- a/feature/monster-registration/android/src/main/res/values-pt-rBR/strings.xml +++ b/feature/monster-registration/android/src/main/res/values-pt-rBR/strings.xml @@ -83,4 +83,10 @@ Reações Ações Lendárias Cor de Fundo da Imagem + + Deslocamento + Voo + Natação + Escalagem + Escavação \ No newline at end of file diff --git a/feature/monster-registration/android/src/main/res/values/strings.xml b/feature/monster-registration/android/src/main/res/values/strings.xml index d9b2693f..9f61030e 100644 --- a/feature/monster-registration/android/src/main/res/values/strings.xml +++ b/feature/monster-registration/android/src/main/res/values/strings.xml @@ -83,4 +83,10 @@ Reactions Legendary Actions Image Background Color + + Speed + Fly + Swim + Climb + Burrow \ No newline at end of file