From 5ab9c824318b780a8ca4fc96f1c51e83072b4822 Mon Sep 17 00:00:00 2001 From: sh1mj1 <7wlgns@gmail.com> Date: Fri, 6 Dec 2024 17:17:07 +0900 Subject: [PATCH 01/20] =?UTF-8?q?feat(ProgressBarAnimation):=20from=20?= =?UTF-8?q?=EC=97=90=EC=84=9C=20to=20=EA=B9=8C=EC=A7=80=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EB=A0=88=EC=8A=A4=EB=B0=94=EC=9D=98=20?= =?UTF-8?q?=EC=95=A0=EB=8B=88=EB=A9=94=EC=9D=B4=EC=85=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/view/ProgressBarAnimation.kt | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 android/app/src/main/java/poke/rogue/helper/presentation/util/view/ProgressBarAnimation.kt diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/util/view/ProgressBarAnimation.kt b/android/app/src/main/java/poke/rogue/helper/presentation/util/view/ProgressBarAnimation.kt new file mode 100644 index 000000000..844a9f741 --- /dev/null +++ b/android/app/src/main/java/poke/rogue/helper/presentation/util/view/ProgressBarAnimation.kt @@ -0,0 +1,28 @@ +package poke.rogue.helper.presentation.util.view + +import android.view.animation.Animation +import android.view.animation.Transformation +import android.widget.ProgressBar + +class ProgressBarAnimation( + private val progressBar: ProgressBar, + private val from: Float, + private val to: Float, +) : Animation() { + override fun applyTransformation( + interpolatedTime: Float, + t: Transformation?, + ) { + super.applyTransformation(interpolatedTime, t) + val value = from + to * interpolatedTime + progressBar.progress = value.toInt() + progressBar.apply { + progress = value.toInt() + } + } +} + +fun ProgressBar.animation( + from: Float, + to: Float, +): ProgressBarAnimation = ProgressBarAnimation(this, from, to) From 69a118d58e30dbcc6a2d31042870bb610969c707 Mon Sep 17 00:00:00 2001 From: sh1mj1 <7wlgns@gmail.com> Date: Fri, 6 Dec 2024 17:21:02 +0900 Subject: [PATCH 02/20] =?UTF-8?q?feat(PokemonStatAdapter):=20progressBar?= =?UTF-8?q?=20=EC=97=90=20=EC=95=A0=EB=8B=88=EB=A9=94=EC=9D=B4=EC=85=98=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dex/detail/stat/PokemonStatAdapter.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/stat/PokemonStatAdapter.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/stat/PokemonStatAdapter.kt index e4095751a..f4bac9eaf 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/stat/PokemonStatAdapter.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/stat/PokemonStatAdapter.kt @@ -7,6 +7,7 @@ import androidx.recyclerview.widget.RecyclerView.ViewHolder import poke.rogue.helper.databinding.ItemStatBinding import poke.rogue.helper.presentation.dex.model.StatUiModel import poke.rogue.helper.presentation.util.view.ItemDiffCallback +import poke.rogue.helper.presentation.util.view.animation class PokemonStatAdapter : ListAdapter(statComparator) { @@ -33,6 +34,17 @@ class PokemonStatAdapter : ViewHolder(binding.root) { fun bind(stat: StatUiModel) { binding.stat = stat + binding.progressBarStat.apply { + startAnimation( + animation(from = 0f, to = stat.amount.toFloat()).apply { + duration = ANIMATION_DURATION + }, + ) + } + } + + companion object { + private const val ANIMATION_DURATION: Long = 800 } } From f5986fa5d77ba652b978ea584fbb781c5d9d61ee Mon Sep 17 00:00:00 2001 From: sh1mj1 <7wlgns@gmail.com> Date: Fri, 6 Dec 2024 17:51:51 +0900 Subject: [PATCH 03/20] =?UTF-8?q?feat(strings.xml):=20=EC=8A=A4=ED=83=AF?= =?UTF-8?q?=20=EB=9D=BC=EB=B2=A8=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 포켓로그 인 게임에서 보여주는 것으로 정의한다 --- android/app/src/main/res/values-ko-rKR/strings.xml | 9 +++++++++ android/app/src/main/res/values/strings.xml | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/res/values-ko-rKR/strings.xml b/android/app/src/main/res/values-ko-rKR/strings.xml index 66cc4e0f1..f9673b52a 100644 --- a/android/app/src/main/res/values-ko-rKR/strings.xml +++ b/android/app/src/main/res/values-ko-rKR/strings.xml @@ -96,6 +96,15 @@ 상대 포켓몬으로 내 포켓몬으로 + + Max.HP + Attack + DEFENSE + Sp.Atk + Sp.Def + Speed + Base Stat + 레벨 기술명 diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index 70c569e80..473fbe903 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -83,7 +83,6 @@ By Special Defense By HP - Base Stats @@ -97,6 +96,15 @@ As Opponent Pokémon As My Pokémon + + Max.HP + Attack + Defense + Sp.Atk + Sp.Def + Speed + Base Stat + Level Move From 01551dc64ac877adf2a3546cb75ff863496884c9 Mon Sep 17 00:00:00 2001 From: sh1mj1 <7wlgns@gmail.com> Date: Fri, 6 Dec 2024 17:53:26 +0900 Subject: [PATCH 04/20] =?UTF-8?q?refactor(StatUiModel):=20=EA=B5=AD?= =?UTF-8?q?=EC=A0=9C=ED=99=94=EB=A5=BC=20=EC=9C=84=ED=95=B4=20name=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=ED=8D=BC=ED=8B=B0=EB=A5=BC=20@StringRes=20In?= =?UTF-8?q?t=20=EB=A1=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dex/detail/PokemonDetailUiState.kt | 9 +- .../dex/detail/stat/PokemonStatAdapter.kt | 8 +- .../model/{StatUiModel.kt => StatUiModel2.kt} | 90 +++++++++++++++++-- android/app/src/main/res/layout/item_stat.xml | 2 +- .../dex/detail/PokemonDetailViewModelTest.kt | 16 ++-- 5 files changed, 99 insertions(+), 26 deletions(-) rename android/app/src/main/java/poke/rogue/helper/presentation/dex/model/{StatUiModel.kt => StatUiModel2.kt} (52%) diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailUiState.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailUiState.kt index 1d3551dab..36c915a5a 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailUiState.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailUiState.kt @@ -8,14 +8,15 @@ import poke.rogue.helper.presentation.dex.model.EvolutionsUiModel import poke.rogue.helper.presentation.dex.model.PokemonBiomeUiModel import poke.rogue.helper.presentation.dex.model.PokemonDetailAbilityUiModel import poke.rogue.helper.presentation.dex.model.PokemonUiModel -import poke.rogue.helper.presentation.dex.model.StatUiModel +import poke.rogue.helper.presentation.dex.model.StatUiModel2 import poke.rogue.helper.presentation.dex.model.toPokemonDetailUi import poke.rogue.helper.presentation.dex.model.toUi +import poke.rogue.helper.presentation.dex.model.toUi2 sealed interface PokemonDetailUiState { data class Success( val pokemon: PokemonUiModel, - val stats: List, + val stats: List, val abilities: List, val evolutions: EvolutionsUiModel, val skills: PokemonDetailSkills, @@ -30,7 +31,7 @@ sealed interface PokemonDetailUiState { fun PokemonDetail.toUi(allBiomes: List): PokemonDetailUiState.Success = PokemonDetailUiState.Success( pokemon = pokemon.toUi(), - stats = stats.map(Stat::toUi), + stats = stats.map(Stat::toUi2), abilities = abilities.toPokemonDetailUi(), evolutions = evolutions.toUi(), skills = skills, @@ -42,7 +43,7 @@ fun PokemonDetail.toUi(allBiomes: List): PokemonDetailUiState.Success = fun PokemonDetail.toUi(): PokemonDetailUiState.Success = PokemonDetailUiState.Success( pokemon = pokemon.toUi(), - stats = stats.map(Stat::toUi), + stats = stats.map(Stat::toUi2), abilities = abilities.toPokemonDetailUi(), evolutions = evolutions.toUi(), skills = skills, diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/stat/PokemonStatAdapter.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/stat/PokemonStatAdapter.kt index f4bac9eaf..2f433d6d6 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/stat/PokemonStatAdapter.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/stat/PokemonStatAdapter.kt @@ -5,12 +5,12 @@ import android.view.ViewGroup import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView.ViewHolder import poke.rogue.helper.databinding.ItemStatBinding -import poke.rogue.helper.presentation.dex.model.StatUiModel +import poke.rogue.helper.presentation.dex.model.StatUiModel2 import poke.rogue.helper.presentation.util.view.ItemDiffCallback import poke.rogue.helper.presentation.util.view.animation class PokemonStatAdapter : - ListAdapter(statComparator) { + ListAdapter(statComparator) { override fun onCreateViewHolder( parent: ViewGroup, viewType: Int, @@ -32,7 +32,7 @@ class PokemonStatAdapter : class PokemonStatViewHolder(private val binding: ItemStatBinding) : ViewHolder(binding.root) { - fun bind(stat: StatUiModel) { + fun bind(stat: StatUiModel2) { binding.stat = stat binding.progressBarStat.apply { startAnimation( @@ -50,7 +50,7 @@ class PokemonStatAdapter : companion object { private val statComparator = - ItemDiffCallback( + ItemDiffCallback( onItemsTheSame = { oldItem, newItem -> oldItem.name == newItem.name }, onContentsTheSame = { oldItem, newItem -> oldItem == newItem }, ) diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/model/StatUiModel.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/model/StatUiModel2.kt similarity index 52% rename from android/app/src/main/java/poke/rogue/helper/presentation/dex/model/StatUiModel.kt rename to android/app/src/main/java/poke/rogue/helper/presentation/dex/model/StatUiModel2.kt index 152570032..597417879 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/model/StatUiModel.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/dex/model/StatUiModel2.kt @@ -1,10 +1,11 @@ package poke.rogue.helper.presentation.dex.model import androidx.annotation.ColorRes +import androidx.annotation.StringRes import poke.rogue.helper.R import poke.rogue.helper.data.model.Stat -data class StatUiModel( +data class StatUiModel2( val name: String, val amount: Int, val limit: Int, @@ -14,10 +15,10 @@ data class StatUiModel( get() = amount * 100 / limit } -fun Stat.toUi() = +fun Stat.toUi2() = when (name) { "hp" -> - StatUiModel( + StatUiModel2( name = "HP", amount = amount, limit = MAX_HP_LIMIT, @@ -25,7 +26,7 @@ fun Stat.toUi() = ) "attack" -> - StatUiModel( + StatUiModel2( name = "공격", amount = amount, limit = MAX_ATTACK_LIMIT, @@ -33,7 +34,7 @@ fun Stat.toUi() = ) "defense" -> - StatUiModel( + StatUiModel2( name = "방어", amount = amount, limit = MAX_DEFENSE_LIMIT, @@ -41,7 +42,7 @@ fun Stat.toUi() = ) "specialAttack" -> - StatUiModel( + StatUiModel2( name = "특수공격", amount = amount, limit = MAX_SPECIAL_ATTACK_LIMIT, @@ -49,7 +50,7 @@ fun Stat.toUi() = ) "specialDefense" -> - StatUiModel( + StatUiModel2( name = "특수방어", amount = amount, limit = MAX_SPECIAL_DEFENSE_LIMIT, @@ -57,7 +58,7 @@ fun Stat.toUi() = ) "speed" -> - StatUiModel( + StatUiModel2( name = "스피드", amount = amount, limit = MAX_SPEED_LIMIT, @@ -65,7 +66,7 @@ fun Stat.toUi() = ) "total" -> - StatUiModel( + StatUiModel2( name = "종족값", amount = amount, limit = MAX_TOTAL_LIMIT, @@ -82,3 +83,74 @@ private const val MAX_SPECIAL_ATTACK_LIMIT = 194 private const val MAX_SPECIAL_DEFENSE_LIMIT = 250 private const val MAX_SPEED_LIMIT = 200 private const val MAX_TOTAL_LIMIT = 800 + +data class StatUiModel( + @StringRes val name: Int, + val amount: Int, + val limit: Int, + @ColorRes val color: Int = 0, +) { + val progress: Int + get() = amount * 100 / limit +} + +fun Stat.toUi(): StatUiModel = + when (name) { + "hp" -> + StatUiModel( + name = R.string.pokemon_stat_hp, + amount = amount, + limit = MAX_HP_LIMIT, + color = R.color.stat_hp, + ) + + "attack" -> + StatUiModel( + name = R.string.pokemon_stat_attack, + amount = amount, + limit = MAX_ATTACK_LIMIT, + color = R.color.stat_attack, + ) + + "defense" -> + StatUiModel( + name = R.string.pokemon_stat_defense, + amount = amount, + limit = MAX_DEFENSE_LIMIT, + color = R.color.stat_defense, + ) + + "specialAttack" -> + StatUiModel( + name = R.string.pokemon_stat_special_attack, + amount = amount, + limit = MAX_SPECIAL_ATTACK_LIMIT, + color = R.color.stat_special_attack, + ) + + "specialDefense" -> + StatUiModel( + name = R.string.pokemon_stat_special_defense, + amount = amount, + limit = MAX_SPECIAL_DEFENSE_LIMIT, + color = R.color.stat_special_defense, + ) + + "speed" -> + StatUiModel( + name = R.string.pokemon_stat_speed, + amount = amount, + limit = MAX_SPEED_LIMIT, + color = R.color.stat_speed, + ) + + "total" -> + StatUiModel( + name = R.string.pokemon_stat_base_stat, + amount = amount, + limit = MAX_TOTAL_LIMIT, + color = R.color.stat_total, + ) + + else -> error("Unknown stat name: $name") + } diff --git a/android/app/src/main/res/layout/item_stat.xml b/android/app/src/main/res/layout/item_stat.xml index 5727cc2f5..5502b1a71 100644 --- a/android/app/src/main/res/layout/item_stat.xml +++ b/android/app/src/main/res/layout/item_stat.xml @@ -6,7 +6,7 @@ + type="poke.rogue.helper.presentation.dex.model.StatUiModel2" /> Date: Fri, 6 Dec 2024 18:34:44 +0900 Subject: [PATCH 05/20] =?UTF-8?q?feat(ko-rKR-strings):=20pokemon=20stat=20?= =?UTF-8?q?=ED=95=9C=EA=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/app/src/main/res/values-ko-rKR/strings.xml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/android/app/src/main/res/values-ko-rKR/strings.xml b/android/app/src/main/res/values-ko-rKR/strings.xml index f9673b52a..a0cf5a3b9 100644 --- a/android/app/src/main/res/values-ko-rKR/strings.xml +++ b/android/app/src/main/res/values-ko-rKR/strings.xml @@ -97,13 +97,13 @@ 내 포켓몬으로 - Max.HP - Attack - DEFENSE - Sp.Atk - Sp.Def - Speed - Base Stat + HP + 공격 + 방어 + 특수공격 + 특수방어 + 스피드 + 종족값 레벨 From 41c8f12b37d174478dc72c4afe55e179caf52ab6 Mon Sep 17 00:00:00 2001 From: sh1mj1 <7wlgns@gmail.com> Date: Fri, 6 Dec 2024 18:44:46 +0900 Subject: [PATCH 06/20] =?UTF-8?q?refactor(StatUiModel):=20name=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=8D=BC=ED=8B=B0=EA=B0=80=20Int?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기존의 StatuiModel2 삭제 --- .../dex/detail/PokemonDetailUiState.kt | 9 +- .../dex/detail/stat/PokemonStatAdapter.kt | 8 +- .../presentation/dex/model/StatUiModel2.kt | 87 ++----------------- android/app/src/main/res/layout/item_stat.xml | 10 +-- .../dex/detail/PokemonDetailViewModelTest.kt | 16 ++-- 5 files changed, 29 insertions(+), 101 deletions(-) diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailUiState.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailUiState.kt index 36c915a5a..1d3551dab 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailUiState.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailUiState.kt @@ -8,15 +8,14 @@ import poke.rogue.helper.presentation.dex.model.EvolutionsUiModel import poke.rogue.helper.presentation.dex.model.PokemonBiomeUiModel import poke.rogue.helper.presentation.dex.model.PokemonDetailAbilityUiModel import poke.rogue.helper.presentation.dex.model.PokemonUiModel -import poke.rogue.helper.presentation.dex.model.StatUiModel2 +import poke.rogue.helper.presentation.dex.model.StatUiModel import poke.rogue.helper.presentation.dex.model.toPokemonDetailUi import poke.rogue.helper.presentation.dex.model.toUi -import poke.rogue.helper.presentation.dex.model.toUi2 sealed interface PokemonDetailUiState { data class Success( val pokemon: PokemonUiModel, - val stats: List, + val stats: List, val abilities: List, val evolutions: EvolutionsUiModel, val skills: PokemonDetailSkills, @@ -31,7 +30,7 @@ sealed interface PokemonDetailUiState { fun PokemonDetail.toUi(allBiomes: List): PokemonDetailUiState.Success = PokemonDetailUiState.Success( pokemon = pokemon.toUi(), - stats = stats.map(Stat::toUi2), + stats = stats.map(Stat::toUi), abilities = abilities.toPokemonDetailUi(), evolutions = evolutions.toUi(), skills = skills, @@ -43,7 +42,7 @@ fun PokemonDetail.toUi(allBiomes: List): PokemonDetailUiState.Success = fun PokemonDetail.toUi(): PokemonDetailUiState.Success = PokemonDetailUiState.Success( pokemon = pokemon.toUi(), - stats = stats.map(Stat::toUi2), + stats = stats.map(Stat::toUi), abilities = abilities.toPokemonDetailUi(), evolutions = evolutions.toUi(), skills = skills, diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/stat/PokemonStatAdapter.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/stat/PokemonStatAdapter.kt index 2f433d6d6..f4bac9eaf 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/stat/PokemonStatAdapter.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/stat/PokemonStatAdapter.kt @@ -5,12 +5,12 @@ import android.view.ViewGroup import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView.ViewHolder import poke.rogue.helper.databinding.ItemStatBinding -import poke.rogue.helper.presentation.dex.model.StatUiModel2 +import poke.rogue.helper.presentation.dex.model.StatUiModel import poke.rogue.helper.presentation.util.view.ItemDiffCallback import poke.rogue.helper.presentation.util.view.animation class PokemonStatAdapter : - ListAdapter(statComparator) { + ListAdapter(statComparator) { override fun onCreateViewHolder( parent: ViewGroup, viewType: Int, @@ -32,7 +32,7 @@ class PokemonStatAdapter : class PokemonStatViewHolder(private val binding: ItemStatBinding) : ViewHolder(binding.root) { - fun bind(stat: StatUiModel2) { + fun bind(stat: StatUiModel) { binding.stat = stat binding.progressBarStat.apply { startAnimation( @@ -50,7 +50,7 @@ class PokemonStatAdapter : companion object { private val statComparator = - ItemDiffCallback( + ItemDiffCallback( onItemsTheSame = { oldItem, newItem -> oldItem.name == newItem.name }, onContentsTheSame = { oldItem, newItem -> oldItem == newItem }, ) diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/model/StatUiModel2.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/model/StatUiModel2.kt index 597417879..f7c9ef294 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/model/StatUiModel2.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/dex/model/StatUiModel2.kt @@ -5,85 +5,6 @@ import androidx.annotation.StringRes import poke.rogue.helper.R import poke.rogue.helper.data.model.Stat -data class StatUiModel2( - val name: String, - val amount: Int, - val limit: Int, - @ColorRes val color: Int = 0, -) { - val progress: Int - get() = amount * 100 / limit -} - -fun Stat.toUi2() = - when (name) { - "hp" -> - StatUiModel2( - name = "HP", - amount = amount, - limit = MAX_HP_LIMIT, - color = R.color.stat_hp, - ) - - "attack" -> - StatUiModel2( - name = "공격", - amount = amount, - limit = MAX_ATTACK_LIMIT, - color = R.color.stat_attack, - ) - - "defense" -> - StatUiModel2( - name = "방어", - amount = amount, - limit = MAX_DEFENSE_LIMIT, - color = R.color.stat_defense, - ) - - "specialAttack" -> - StatUiModel2( - name = "특수공격", - amount = amount, - limit = MAX_SPECIAL_ATTACK_LIMIT, - color = R.color.stat_special_attack, - ) - - "specialDefense" -> - StatUiModel2( - name = "특수방어", - amount = amount, - limit = MAX_SPECIAL_DEFENSE_LIMIT, - color = R.color.stat_special_defense, - ) - - "speed" -> - StatUiModel2( - name = "스피드", - amount = amount, - limit = MAX_SPEED_LIMIT, - color = R.color.stat_speed, - ) - - "total" -> - StatUiModel2( - name = "종족값", - amount = amount, - limit = MAX_TOTAL_LIMIT, - color = R.color.stat_total, - ) - - else -> error("Unknown stat name: $name") - } - -private const val MAX_HP_LIMIT = 255 -private const val MAX_ATTACK_LIMIT = 190 -private const val MAX_DEFENSE_LIMIT = 250 -private const val MAX_SPECIAL_ATTACK_LIMIT = 194 -private const val MAX_SPECIAL_DEFENSE_LIMIT = 250 -private const val MAX_SPEED_LIMIT = 200 -private const val MAX_TOTAL_LIMIT = 800 - data class StatUiModel( @StringRes val name: Int, val amount: Int, @@ -154,3 +75,11 @@ fun Stat.toUi(): StatUiModel = else -> error("Unknown stat name: $name") } + +private const val MAX_HP_LIMIT = 255 +private const val MAX_ATTACK_LIMIT = 190 +private const val MAX_DEFENSE_LIMIT = 250 +private const val MAX_SPECIAL_ATTACK_LIMIT = 194 +private const val MAX_SPECIAL_DEFENSE_LIMIT = 250 +private const val MAX_SPEED_LIMIT = 200 +private const val MAX_TOTAL_LIMIT = 800 diff --git a/android/app/src/main/res/layout/item_stat.xml b/android/app/src/main/res/layout/item_stat.xml index 5502b1a71..7e0c3e9cd 100644 --- a/android/app/src/main/res/layout/item_stat.xml +++ b/android/app/src/main/res/layout/item_stat.xml @@ -6,7 +6,7 @@ + type="poke.rogue.helper.presentation.dex.model.StatUiModel" /> @@ -28,7 +28,7 @@ android:text="@{stat.name}" android:textSize="@dimen/pokemon_stat_text_size" tools:ignore="SpUsage" - tools:text="HPD" /> + tools:text="Base stat sdf" /> diff --git a/android/app/src/test/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModelTest.kt b/android/app/src/test/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModelTest.kt index 6950e528a..c6a40c258 100644 --- a/android/app/src/test/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModelTest.kt +++ b/android/app/src/test/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModelTest.kt @@ -17,7 +17,7 @@ import poke.rogue.helper.data.model.PokemonSkill import poke.rogue.helper.presentation.dex.model.EvolutionsUiModel import poke.rogue.helper.presentation.dex.model.PokemonDetailAbilityUiModel import poke.rogue.helper.presentation.dex.model.PokemonUiModel -import poke.rogue.helper.presentation.dex.model.StatUiModel2 +import poke.rogue.helper.presentation.dex.model.StatUiModel import poke.rogue.helper.presentation.dex.model.toUi import poke.rogue.helper.presentation.di.testViewModelModule import poke.rogue.helper.presentation.type.model.TypeUiModel @@ -76,13 +76,13 @@ class PokemonDetailViewModelTest : KoinTest { ), stats = listOf( - StatUiModel2("HP", 45, 255, R.color.stat_hp), - StatUiModel2("공격", 49, 190, R.color.stat_attack), - StatUiModel2("방어", 49, 250, R.color.stat_defense), - StatUiModel2("특수공격", 65, 194, R.color.stat_special_attack), - StatUiModel2("특수방어", 65, 250, R.color.stat_special_defense), - StatUiModel2("스피드", 45, 200, R.color.stat_speed), - StatUiModel2("종족값", 318, 800, R.color.stat_total), + StatUiModel(100, 45, 255, R.color.stat_hp), + StatUiModel(200, 49, 190, R.color.stat_attack), + StatUiModel(300, 49, 250, R.color.stat_defense), + StatUiModel(400, 65, 194, R.color.stat_special_attack), + StatUiModel(500, 65, 250, R.color.stat_special_defense), + StatUiModel(600, 45, 200, R.color.stat_speed), + StatUiModel(700, 318, 800, R.color.stat_total), ), abilities = listOf( From e3fda63a3397b9456d49f8a1c2987160e280429b Mon Sep 17 00:00:00 2001 From: sh1mj1 <7wlgns@gmail.com> Date: Fri, 6 Dec 2024 18:45:21 +0900 Subject: [PATCH 07/20] chore(PokemonDetailUiState): remove useless function --- .../presentation/dex/detail/PokemonDetailUiState.kt | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailUiState.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailUiState.kt index 1d3551dab..a1af25492 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailUiState.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailUiState.kt @@ -1,6 +1,5 @@ package poke.rogue.helper.presentation.dex.detail -import poke.rogue.helper.data.model.Biome import poke.rogue.helper.data.model.PokemonDetail import poke.rogue.helper.data.model.PokemonDetailSkills import poke.rogue.helper.data.model.Stat @@ -27,18 +26,6 @@ sealed interface PokemonDetailUiState { data object IsLoading : PokemonDetailUiState } -fun PokemonDetail.toUi(allBiomes: List): PokemonDetailUiState.Success = - PokemonDetailUiState.Success( - pokemon = pokemon.toUi(), - stats = stats.map(Stat::toUi), - abilities = abilities.toPokemonDetailUi(), - evolutions = evolutions.toUi(), - skills = skills, - height = height.toFloat(), - weight = weight.toFloat(), - biomes = biomes.toUi(), - ) - fun PokemonDetail.toUi(): PokemonDetailUiState.Success = PokemonDetailUiState.Success( pokemon = pokemon.toUi(), From cdc6658e5b3c9bc511052fe03ae330aad7795e23 Mon Sep 17 00:00:00 2001 From: sh1mj1 <7wlgns@gmail.com> Date: Fri, 6 Dec 2024 18:49:13 +0900 Subject: [PATCH 08/20] =?UTF-8?q?fix(item=5Ftype=5Fresult.xml):=20?= =?UTF-8?q?=EB=82=B4=20=ED=83=80=EC=9E=85=20=EC=83=81=EC=84=B1=20=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=EB=8A=94=20visible=20=EC=9D=B4=20=EC=95=84=EB=8B=8C?= =?UTF-8?q?=20invisible=20=EB=B0=94=EC=9D=B8=EB=94=A9=20=EC=96=B4=EB=8C=91?= =?UTF-8?q?=ED=84=B0=EB=A5=BC=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/app/src/main/res/layout/item_type_result.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/app/src/main/res/layout/item_type_result.xml b/android/app/src/main/res/layout/item_type_result.xml index 33499dc59..93f4b6301 100644 --- a/android/app/src/main/res/layout/item_type_result.xml +++ b/android/app/src/main/res/layout/item_type_result.xml @@ -17,7 +17,7 @@ Date: Fri, 6 Dec 2024 19:22:07 +0900 Subject: [PATCH 09/20] =?UTF-8?q?fix(PokemonDetailViewModel):=20=EC=A7=84?= =?UTF-8?q?=ED=99=94=EC=B2=B4=EA=B0=80=20=EA=B0=99=EC=9D=80=20=ED=8F=AC?= =?UTF-8?q?=EC=BC=93=EB=AA=AC=EC=9D=B4=EB=A9=B4=20=EC=84=A0=ED=83=9D?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../helper/presentation/dex/detail/PokemonDetailViewModel.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt index 6e5cf406d..867937269 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt @@ -24,7 +24,8 @@ class PokemonDetailViewModel( ) : ErrorHandleViewModel(logger), PokemonDetailNavigateHandler { - private val _uiState: MutableStateFlow = MutableStateFlow(PokemonDetailUiState.IsLoading) + private val _uiState: MutableStateFlow = + MutableStateFlow(PokemonDetailUiState.IsLoading) val uiState = _uiState.asStateFlow() val isLoading: StateFlow = @@ -73,6 +74,8 @@ class PokemonDetailViewModel( override fun navigateToPokemonDetail(pokemonId: String) { viewModelScope.launch { + if (pokemonUiModel().id == pokemonId) return@launch + _navigateToPokemonDetailEvent.emit(pokemonId) } } From 09f0a0f9a827a0dd4078fe8d22e6c4e2954709dc Mon Sep 17 00:00:00 2001 From: sh1mj1 <7wlgns@gmail.com> Date: Fri, 6 Dec 2024 19:52:43 +0900 Subject: [PATCH 10/20] =?UTF-8?q?feat(PokemonEvolutionEvent):=20=ED=8F=AC?= =?UTF-8?q?=EC=BC=93=EB=AA=AC=20=EC=A7=84=ED=99=94=EC=B2=B4=20=ED=81=B4?= =?UTF-8?q?=EB=A6=AD=20=EC=9D=B4=EB=B2=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/dex/detail/PokemonEvolutionEvent.kt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonEvolutionEvent.kt diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonEvolutionEvent.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonEvolutionEvent.kt new file mode 100644 index 000000000..cfe0f1f78 --- /dev/null +++ b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonEvolutionEvent.kt @@ -0,0 +1,7 @@ +package poke.rogue.helper.presentation.dex.detail + +sealed class PokemonEvolutionEvent { + data class NavigateToPokemonDetail(val pokemonId: String) : PokemonEvolutionEvent() + + data class SameWithCurrentPokemon(val pokemonName: String) : PokemonEvolutionEvent() +} From 544be67e433a49837bf062854babcc69c0fb97ed Mon Sep 17 00:00:00 2001 From: sh1mj1 <7wlgns@gmail.com> Date: Fri, 6 Dec 2024 19:53:27 +0900 Subject: [PATCH 11/20] =?UTF-8?q?refactor(PokemonDetailViewModel):=20?= =?UTF-8?q?=EC=A7=84=ED=99=94=EC=B2=B4=20=ED=81=B4=EB=A6=AD=EC=8B=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 현재 화면과 같은 포켓몬이면 토스트 메시지 다른 포켓몬이면 화면 이동 --- .../dex/detail/PokemonDetailActivity.kt | 12 ++++++++---- .../dex/detail/PokemonDetailViewModel.kt | 16 ++++++++++------ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt index aad815650..06d9b898b 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt @@ -22,6 +22,7 @@ import poke.rogue.helper.presentation.type.view.TypeChip import poke.rogue.helper.presentation.util.context.startActivity import poke.rogue.helper.presentation.util.context.stringArrayOf import poke.rogue.helper.presentation.util.context.stringOf +import poke.rogue.helper.presentation.util.context.toast import poke.rogue.helper.presentation.util.repeatOnStarted import poke.rogue.helper.presentation.util.view.dp import poke.rogue.helper.presentation.util.view.loadImageWithProgress @@ -88,7 +89,7 @@ class PokemonDetailActivity : observeNavigateToHomeEvent() observeNavigateToAbilityDetailEvent() observeNavigateToBiomeDetailEvent() - observeNavigateToPokemonDetailEvent() + observePokemonEvolutionEvent() observeNavigateToBattleEvent() } @@ -137,10 +138,13 @@ class PokemonDetailActivity : } } - private fun observeNavigateToPokemonDetailEvent() { + private fun observePokemonEvolutionEvent() { repeatOnStarted { - viewModel.navigateToPokemonDetailEvent.collect { pokemonId -> - startActivity(intent(this, pokemonId)) + viewModel.evolutionsEvent.collect { event -> + when (event) { + is PokemonEvolutionEvent.NavigateToPokemonDetail -> startActivity(intent(this, event.pokemonId)) + is PokemonEvolutionEvent.SameWithCurrentPokemon -> toast("너가 그 ${event.pokemonName} 이잖아.") + } } } } diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt index 867937269..b8a7517a2 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt @@ -41,12 +41,12 @@ class PokemonDetailViewModel( private val _navigateToHomeEvent = MutableEventFlow() val navigateToHomeEvent = _navigateToHomeEvent.asEventFlow() - private val _navigateToPokemonDetailEvent = MutableEventFlow() - val navigateToPokemonDetailEvent = _navigateToPokemonDetailEvent.asEventFlow() - private val _navigateToBattleEvent = MutableEventFlow() val navigateToBattleEvent = _navigateToBattleEvent.asEventFlow() + private val _evolutionsEvent = MutableEventFlow() + val evolutionsEvent = _evolutionsEvent.asEventFlow() + fun updatePokemonDetail(pokemonId: String?) { requireNotNull(pokemonId) { "Pokemon ID must not be null" } viewModelScope.launch { @@ -74,9 +74,13 @@ class PokemonDetailViewModel( override fun navigateToPokemonDetail(pokemonId: String) { viewModelScope.launch { - if (pokemonUiModel().id == pokemonId) return@launch - - _navigateToPokemonDetailEvent.emit(pokemonId) + pokemonUiModel().let { pokemon -> + if (pokemon.id == pokemonId) { + _evolutionsEvent.emit(PokemonEvolutionEvent.SameWithCurrentPokemon(pokemon.name)) + return@launch + } + _evolutionsEvent.emit(PokemonEvolutionEvent.NavigateToPokemonDetail(pokemonId)) + } } } From f5f91a429210d5e0dde6154ef7329212e4fc2b06 Mon Sep 17 00:00:00 2001 From: sh1mj1 <7wlgns@gmail.com> Date: Fri, 6 Dec 2024 19:59:21 +0900 Subject: [PATCH 12/20] =?UTF-8?q?feat(PokemonDetailActivity):=20=ED=98=84?= =?UTF-8?q?=EC=9E=AC=20=ED=99=94=EB=A9=B4=EA=B3=BC=20=EA=B0=99=EC=9D=80=20?= =?UTF-8?q?=ED=8F=AC=EC=BC=93=EB=AA=AC=EC=9D=B4=EB=A9=B4=20=EB=B3=B4?= =?UTF-8?q?=EC=97=AC=EC=A3=BC=EB=8A=94=20=ED=86=A0=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=EB=A5=BC=20=EC=A7=80=EC=97=AD?= =?UTF-8?q?=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../helper/presentation/dex/detail/PokemonDetailActivity.kt | 5 ++++- android/app/src/main/res/values-ko-rKR/strings.xml | 1 + android/app/src/main/res/values/strings.xml | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt index 06d9b898b..e3fe1f7c8 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt @@ -143,7 +143,10 @@ class PokemonDetailActivity : viewModel.evolutionsEvent.collect { event -> when (event) { is PokemonEvolutionEvent.NavigateToPokemonDetail -> startActivity(intent(this, event.pokemonId)) - is PokemonEvolutionEvent.SameWithCurrentPokemon -> toast("너가 그 ${event.pokemonName} 이잖아.") + is PokemonEvolutionEvent.SameWithCurrentPokemon -> + toast( + this.stringOf(R.string.pokemon_detail_evolution_same_with_current_pokemon_message, event.pokemonName), + ) } } } diff --git a/android/app/src/main/res/values-ko-rKR/strings.xml b/android/app/src/main/res/values-ko-rKR/strings.xml index 66cc4e0f1..fcb3008fa 100644 --- a/android/app/src/main/res/values-ko-rKR/strings.xml +++ b/android/app/src/main/res/values-ko-rKR/strings.xml @@ -118,6 +118,7 @@ 진화 체인이 없는 포켓몬입니다. 레벨 %d + 현재 화면의 포켓몬이 $s 입니다. 특성 도감 diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index 70c569e80..68b24d51e 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -118,7 +118,7 @@ This Pokémon has no evolution chain. Level %d - + This is the current Pokémon on the screen: %s. Ability Dex Search by Ability name. From e7513df36b42f12f5f4238264a034df82daacb03 Mon Sep 17 00:00:00 2001 From: sh1mj1 <7wlgns@gmail.com> Date: Fri, 6 Dec 2024 20:23:15 +0900 Subject: [PATCH 13/20] =?UTF-8?q?feat(PokemonDetailViewModel):=20=ED=99=88?= =?UTF-8?q?,=20=ED=8A=B9=EC=84=B1=20=EC=83=81=EC=84=B8,=20=EB=B0=94?= =?UTF-8?q?=EC=9D=B4=EC=98=B4=20=EC=83=81=EC=84=B8=20=EB=84=A4=EB=B9=84?= =?UTF-8?q?=EA=B2=8C=EC=9D=B4=EC=85=98=20=EC=9D=B4=EB=B2=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dex/detail/PokemonDetailViewModel.kt | 19 +++++++++ .../dex/detail/PokemonDetailViewModelTest.kt | 42 +++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt index b8a7517a2..e92b31c92 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt @@ -44,6 +44,9 @@ class PokemonDetailViewModel( private val _navigateToBattleEvent = MutableEventFlow() val navigateToBattleEvent = _navigateToBattleEvent.asEventFlow() + private val _navigationEvent = MutableEventFlow() + val navigationEvent = _navigationEvent.asEventFlow() + private val _evolutionsEvent = MutableEventFlow() val evolutionsEvent = _evolutionsEvent.asEventFlow() @@ -56,19 +59,25 @@ class PokemonDetailViewModel( override fun navigateToAbilityDetail(abilityId: String) { viewModelScope.launch { + // TODO: REMOVE _navigationToAbilityDetailEvent.emit(abilityId) + _navigationEvent.emit(NavigationEvent.ToAbilityDetail(abilityId)) } } override fun navigateToBiomeDetail(biomeId: String) { viewModelScope.launch { + // TODO: REMOVE _navigationToBiomeDetailEvent.emit(biomeId) + _navigationEvent.emit(NavigationEvent.ToBiomeDetail(biomeId)) } } override fun navigateToHome() { viewModelScope.launch { + // TODO: REMOVE _navigateToHomeEvent.emit(true) + _navigationEvent.emit(NavigationEvent.ToHome) } } @@ -104,4 +113,14 @@ class PokemonDetailViewModel( uiState .filterIsInstance() .first().pokemon + + sealed interface NavigationEvent { + data class ToAbilityDetail(val id: String) : NavigationEvent + + data class ToBiomeDetail(val id: String) : NavigationEvent + + data object ToHome : NavigationEvent + + data object NONE : NavigationEvent + } } diff --git a/android/app/src/test/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModelTest.kt b/android/app/src/test/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModelTest.kt index 7b6d69710..0e020dce8 100644 --- a/android/app/src/test/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModelTest.kt +++ b/android/app/src/test/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModelTest.kt @@ -103,4 +103,46 @@ class PokemonDetailViewModelTest : KoinTest { biomes = PokemonBiome.DUMMYS.toUi(), ) } + + @Test + fun `홈으로 이동한다`() = + runTest { + // when + viewModel.navigateToHome() + + // then + val event = + viewModel.navigationEvent.first { + it !is PokemonDetailViewModel.NavigationEvent.NONE + } + event shouldBe PokemonDetailViewModel.NavigationEvent.ToHome + } + + @Test + fun `특성 상세로 이동한다`() = + runTest { + // when + viewModel.navigateToAbilityDetail("10") + + // then + val event = + viewModel.navigationEvent.first { + it !is PokemonDetailViewModel.NavigationEvent.NONE + } + event shouldBe PokemonDetailViewModel.NavigationEvent.ToAbilityDetail("10") + } + + @Test + fun `바이옴 상세로 이동한다`() = + runTest { + // when + viewModel.navigateToBiomeDetail("10") + + // then + val event = + viewModel.navigationEvent.first { + it !is PokemonDetailViewModel.NavigationEvent.NONE + } + event shouldBe PokemonDetailViewModel.NavigationEvent.ToBiomeDetail("10") + } } From aa9db64889a32638117221faa8922375a9fea1c1 Mon Sep 17 00:00:00 2001 From: sh1mj1 <7wlgns@gmail.com> Date: Fri, 6 Dec 2024 20:24:50 +0900 Subject: [PATCH 14/20] =?UTF-8?q?refactor(PokemonDetailViewModel,=20Activi?= =?UTF-8?q?ty):=20=ED=99=88,=20=ED=8A=B9=EC=84=B1=20=EC=83=81=EC=84=B8,=20?= =?UTF-8?q?=EB=B0=94=EC=9D=B4=EC=98=B4=20=EC=83=81=EC=84=B8=20=EB=84=A4?= =?UTF-8?q?=EB=B9=84=EA=B2=8C=EC=9D=B4=EC=85=98=20=EC=9D=B4=EB=B2=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dex/detail/PokemonDetailActivity.kt | 56 +++++++++++-------- .../dex/detail/PokemonDetailViewModel.kt | 17 +----- 2 files changed, 33 insertions(+), 40 deletions(-) diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt index e3fe1f7c8..41739e151 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt @@ -86,9 +86,7 @@ class PokemonDetailActivity : private fun initObservers() { observePokemonDetailUi() - observeNavigateToHomeEvent() - observeNavigateToAbilityDetailEvent() - observeNavigateToBiomeDetailEvent() + observeNavigationEvent() observePokemonEvolutionEvent() observeNavigateToBattleEvent() } @@ -112,28 +110,28 @@ class PokemonDetailActivity : } } - private fun observeNavigateToHomeEvent() { - repeatOnStarted { - viewModel.navigateToHomeEvent.collect { - if (it) { - startActivity(HomeActivity.intent(this)) - } - } - } - } - private fun observeNavigateToAbilityDetailEvent() { + private fun observeNavigationEvent() { repeatOnStarted { - viewModel.navigationToAbilityDetailEvent.collect { abilityId -> - startActivity(AbilityActivity.intent(this, abilityId)) - } - } - } + viewModel.navigationEvent.collect { event -> + when (event) { + is PokemonDetailViewModel.NavigationEvent.ToAbilityDetail -> + startActivity( + AbilityActivity.intent(this, event.id), + ) - private fun observeNavigateToBiomeDetailEvent() { - repeatOnStarted { - viewModel.navigationToBiomeDetailEvent.collect { biomeId -> - startActivity(BiomeDetailActivity.intent(this, biomeId)) + is PokemonDetailViewModel.NavigationEvent.ToBiomeDetail -> + startActivity( + BiomeDetailActivity.intent(this, event.id), + ) + + is PokemonDetailViewModel.NavigationEvent.ToHome -> + startActivity( + HomeActivity.intent(this), + ) + + PokemonDetailViewModel.NavigationEvent.NONE -> return@collect + } } } } @@ -142,10 +140,20 @@ class PokemonDetailActivity : repeatOnStarted { viewModel.evolutionsEvent.collect { event -> when (event) { - is PokemonEvolutionEvent.NavigateToPokemonDetail -> startActivity(intent(this, event.pokemonId)) + is PokemonEvolutionEvent.NavigateToPokemonDetail -> + startActivity( + intent( + this, + event.pokemonId, + ), + ) + is PokemonEvolutionEvent.SameWithCurrentPokemon -> toast( - this.stringOf(R.string.pokemon_detail_evolution_same_with_current_pokemon_message, event.pokemonName), + this.stringOf( + R.string.pokemon_detail_evolution_same_with_current_pokemon_message, + event.pokemonName, + ), ) } } diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt index e92b31c92..27ff24677 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt @@ -23,7 +23,7 @@ class PokemonDetailViewModel( private val logger: AnalyticsLogger = analyticsLogger(), ) : ErrorHandleViewModel(logger), - PokemonDetailNavigateHandler { + PokemonDetailNavigateHandler { private val _uiState: MutableStateFlow = MutableStateFlow(PokemonDetailUiState.IsLoading) val uiState = _uiState.asStateFlow() @@ -32,15 +32,6 @@ class PokemonDetailViewModel( uiState.map { it is PokemonDetailUiState.IsLoading } .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000L), true) - private val _navigationToAbilityDetailEvent = MutableEventFlow() - val navigationToAbilityDetailEvent = _navigationToAbilityDetailEvent.asEventFlow() - - private val _navigationToBiomeDetailEvent = MutableEventFlow() - val navigationToBiomeDetailEvent = _navigationToBiomeDetailEvent.asEventFlow() - - private val _navigateToHomeEvent = MutableEventFlow() - val navigateToHomeEvent = _navigateToHomeEvent.asEventFlow() - private val _navigateToBattleEvent = MutableEventFlow() val navigateToBattleEvent = _navigateToBattleEvent.asEventFlow() @@ -59,24 +50,18 @@ class PokemonDetailViewModel( override fun navigateToAbilityDetail(abilityId: String) { viewModelScope.launch { - // TODO: REMOVE - _navigationToAbilityDetailEvent.emit(abilityId) _navigationEvent.emit(NavigationEvent.ToAbilityDetail(abilityId)) } } override fun navigateToBiomeDetail(biomeId: String) { viewModelScope.launch { - // TODO: REMOVE - _navigationToBiomeDetailEvent.emit(biomeId) _navigationEvent.emit(NavigationEvent.ToBiomeDetail(biomeId)) } } override fun navigateToHome() { viewModelScope.launch { - // TODO: REMOVE - _navigateToHomeEvent.emit(true) _navigationEvent.emit(NavigationEvent.ToHome) } } From 9d2e18c97dc9c8d1e183223331644cd8f2ebc522 Mon Sep 17 00:00:00 2001 From: sh1mj1 <7wlgns@gmail.com> Date: Fri, 6 Dec 2024 20:52:50 +0900 Subject: [PATCH 15/20] =?UTF-8?q?refactor(PokemonDetailViewModel,=20Activi?= =?UTF-8?q?ty):=20=EB=B0=B0=ED=8B=80=EB=A1=9C=20=EB=84=A4=EB=B9=84?= =?UTF-8?q?=EA=B2=8C=EC=9D=B4=EC=85=98=ED=95=98=EB=8A=94=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=EB=A5=BC=20=ED=95=9C=20=EA=B0=9D=EC=B2=B4?= =?UTF-8?q?=EB=A1=9C=20=ED=95=A9=EC=B9=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dex/detail/PokemonDetailActivity.kt | 30 +++++++------------ .../dex/detail/PokemonDetailViewModel.kt | 25 +++++++++------- 2 files changed, 25 insertions(+), 30 deletions(-) diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt index 41739e151..a83270e97 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt @@ -88,7 +88,6 @@ class PokemonDetailActivity : observePokemonDetailUi() observeNavigationEvent() observePokemonEvolutionEvent() - observeNavigateToBattleEvent() } private fun initFloatingButtonsHandler() { @@ -110,7 +109,6 @@ class PokemonDetailActivity : } } - private fun observeNavigationEvent() { repeatOnStarted { viewModel.navigationEvent.collect { event -> @@ -130,7 +128,14 @@ class PokemonDetailActivity : HomeActivity.intent(this), ) - PokemonDetailViewModel.NavigationEvent.NONE -> return@collect + is PokemonDetailViewModel.NavigationEvent.NONE -> return@collect + is PokemonDetailViewModel.NavigationEvent.ToBattle.WithMyPokemon -> startActivity( + battleIntent(event) + ) + + is PokemonDetailViewModel.NavigationEvent.ToBattle.WithOpponentPokemon -> startActivity( + battleIntent(event) + ) } } } @@ -160,34 +165,21 @@ class PokemonDetailActivity : } } - private fun observeNavigateToBattleEvent() { - repeatOnStarted { - viewModel.navigateToBattleEvent.collect { battleEvent -> - val intent = battleIntent(battleEvent) - startActivity { - putExtras(intent) - } - } - } - } - - private fun battleIntent(battleEvent: NavigateToBattleEvent): Intent = + private fun battleIntent(battleEvent: PokemonDetailViewModel.NavigationEvent.ToBattle): Intent = when (battleEvent) { - is NavigateToBattleEvent.WithMyPokemon -> { + is PokemonDetailViewModel.NavigationEvent.ToBattle.WithMyPokemon -> BattleActivity.intent( this@PokemonDetailActivity, pokemonId = battleEvent.pokemon.id, isMine = true, ) - } - is NavigateToBattleEvent.WithOpponentPokemon -> { + is PokemonDetailViewModel.NavigationEvent.ToBattle.WithOpponentPokemon -> BattleActivity.intent( this@PokemonDetailActivity, pokemonId = battleEvent.pokemon.id, isMine = false, ) - } } private fun bindPokemonDetail(pokemonDetail: PokemonDetailUiState.Success) { diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt index 27ff24677..2f64384c7 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt @@ -14,7 +14,7 @@ import poke.rogue.helper.analytics.AnalyticsLogger import poke.rogue.helper.analytics.analyticsLogger import poke.rogue.helper.data.repository.DexRepository import poke.rogue.helper.presentation.base.error.ErrorHandleViewModel -import poke.rogue.helper.presentation.dex.logPokemonDetailToBattle +import poke.rogue.helper.presentation.dex.model.PokemonUiModel import poke.rogue.helper.presentation.util.event.MutableEventFlow import poke.rogue.helper.presentation.util.event.asEventFlow @@ -23,7 +23,7 @@ class PokemonDetailViewModel( private val logger: AnalyticsLogger = analyticsLogger(), ) : ErrorHandleViewModel(logger), - PokemonDetailNavigateHandler { + PokemonDetailNavigateHandler { private val _uiState: MutableStateFlow = MutableStateFlow(PokemonDetailUiState.IsLoading) val uiState = _uiState.asStateFlow() @@ -32,9 +32,6 @@ class PokemonDetailViewModel( uiState.map { it is PokemonDetailUiState.IsLoading } .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000L), true) - private val _navigateToBattleEvent = MutableEventFlow() - val navigateToBattleEvent = _navigateToBattleEvent.asEventFlow() - private val _navigationEvent = MutableEventFlow() val navigationEvent = _navigationEvent.asEventFlow() @@ -80,17 +77,17 @@ class PokemonDetailViewModel( override fun navigateToBattleWithMine() { viewModelScope.launch { - val navigation = NavigateToBattleEvent.WithMyPokemon(pokemonUiModel()) - _navigateToBattleEvent.emit(navigation) - logger.logPokemonDetailToBattle(navigation) + val navigation2 = NavigationEvent.ToBattle.WithMyPokemon(pokemonUiModel()) + _navigationEvent.emit(navigation2) +// logger.logPokemonDetailToBattle(navigation) // TODO: change } } override fun navigateToBattleWithOpponent() { viewModelScope.launch { - val navigation = NavigateToBattleEvent.WithOpponentPokemon(pokemonUiModel()) - _navigateToBattleEvent.emit(navigation) - logger.logPokemonDetailToBattle(navigation) + val navigation2 = NavigationEvent.ToBattle.WithOpponentPokemon(pokemonUiModel()) + _navigationEvent.emit(navigation2) +// logger.logPokemonDetailToBattle(navigation) // TODO: change } } @@ -107,5 +104,11 @@ class PokemonDetailViewModel( data object ToHome : NavigationEvent data object NONE : NavigationEvent + + sealed class ToBattle : NavigationEvent { + data class WithMyPokemon(val pokemon: PokemonUiModel) : ToBattle() + + data class WithOpponentPokemon(val pokemon: PokemonUiModel) : ToBattle() + } } } From fe391943639fe00a308fe40e544a91b0936956a5 Mon Sep 17 00:00:00 2001 From: sh1mj1 <7wlgns@gmail.com> Date: Fri, 6 Dec 2024 21:09:25 +0900 Subject: [PATCH 16/20] =?UTF-8?q?refactor(PokemonDetailViewModel):=20?= =?UTF-8?q?=EB=B0=B0=ED=8B=80=EB=A1=9C=20=EB=84=A4=EB=B9=84=EA=B2=8C?= =?UTF-8?q?=EC=9D=B4=EC=85=98=20=EC=8B=9C=EC=97=90=20=ED=8C=8C=EC=9D=B4?= =?UTF-8?q?=EC=96=B4=EB=B2=A0=EC=9D=B4=EC=8A=A4=20=EB=A1=9C=EA=B9=85=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/dex/AnalyticsExtensions.kt | 10 +++++----- .../dex/detail/NavigateToBattleEvent.kt | 9 --------- .../dex/detail/PokemonDetailActivity.kt | 17 +++++++++-------- .../dex/detail/PokemonDetailViewModel.kt | 17 +++++++++++------ 4 files changed, 25 insertions(+), 28 deletions(-) delete mode 100644 android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/NavigateToBattleEvent.kt diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/AnalyticsExtensions.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/AnalyticsExtensions.kt index eb2a74ca7..ccf51ea31 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/AnalyticsExtensions.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/dex/AnalyticsExtensions.kt @@ -2,7 +2,7 @@ package poke.rogue.helper.presentation.dex import poke.rogue.helper.analytics.AnalyticsEvent import poke.rogue.helper.analytics.AnalyticsLogger -import poke.rogue.helper.presentation.dex.detail.NavigateToBattleEvent +import poke.rogue.helper.presentation.dex.detail.PokemonDetailViewModel.NavigationEvent import poke.rogue.helper.presentation.dex.filter.PokeFilterUiModel import poke.rogue.helper.presentation.dex.sort.PokemonSortUiModel @@ -38,7 +38,7 @@ private fun PokeFilterUiModel.toParams(): List { } + AnalyticsEvent.Param(key = "generation", value = selectedGeneration.name) } -fun AnalyticsLogger.logPokemonDetailToBattle(event: NavigateToBattleEvent) { +fun AnalyticsLogger.logPokemonDetailToBattle(event: NavigationEvent.ToBattle) { val eventType = "pokemon_detail_to_battle_directly" logEvent( AnalyticsEvent( @@ -48,11 +48,11 @@ fun AnalyticsLogger.logPokemonDetailToBattle(event: NavigateToBattleEvent) { ) } -private fun NavigateToBattleEvent.toParams(): List { +private fun NavigationEvent.ToBattle.toParams(): List { val (battleRoleValue, pokemon) = when (this) { - is NavigateToBattleEvent.WithMyPokemon -> Pair("MyPokemon", pokemon) - is NavigateToBattleEvent.WithOpponentPokemon -> Pair("EnemyPokemon", pokemon) + is NavigationEvent.ToBattle.WithMyPokemon -> Pair("MyPokemon", pokemon) + is NavigationEvent.ToBattle.WithOpponentPokemon -> Pair("EnemyPokemon", pokemon) } return listOf( diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/NavigateToBattleEvent.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/NavigateToBattleEvent.kt deleted file mode 100644 index f443223eb..000000000 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/NavigateToBattleEvent.kt +++ /dev/null @@ -1,9 +0,0 @@ -package poke.rogue.helper.presentation.dex.detail - -import poke.rogue.helper.presentation.dex.model.PokemonUiModel - -sealed class NavigateToBattleEvent { - data class WithMyPokemon(val pokemon: PokemonUiModel) : NavigateToBattleEvent() - - data class WithOpponentPokemon(val pokemon: PokemonUiModel) : NavigateToBattleEvent() -} diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt index a83270e97..5649267ad 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt @@ -19,7 +19,6 @@ import poke.rogue.helper.presentation.biome.detail.BiomeDetailActivity import poke.rogue.helper.presentation.dex.PokemonTypesAdapter import poke.rogue.helper.presentation.home.HomeActivity import poke.rogue.helper.presentation.type.view.TypeChip -import poke.rogue.helper.presentation.util.context.startActivity import poke.rogue.helper.presentation.util.context.stringArrayOf import poke.rogue.helper.presentation.util.context.stringOf import poke.rogue.helper.presentation.util.context.toast @@ -128,14 +127,16 @@ class PokemonDetailActivity : HomeActivity.intent(this), ) - is PokemonDetailViewModel.NavigationEvent.NONE -> return@collect - is PokemonDetailViewModel.NavigationEvent.ToBattle.WithMyPokemon -> startActivity( - battleIntent(event) - ) + is PokemonDetailViewModel.NavigationEvent.ToBattle.WithMyPokemon -> + startActivity( + battleIntent(event), + ) - is PokemonDetailViewModel.NavigationEvent.ToBattle.WithOpponentPokemon -> startActivity( - battleIntent(event) - ) + is PokemonDetailViewModel.NavigationEvent.ToBattle.WithOpponentPokemon -> + startActivity( + battleIntent(event), + ) + is PokemonDetailViewModel.NavigationEvent.NONE -> return@collect } } } diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt index 2f64384c7..859fc4f24 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt @@ -14,6 +14,7 @@ import poke.rogue.helper.analytics.AnalyticsLogger import poke.rogue.helper.analytics.analyticsLogger import poke.rogue.helper.data.repository.DexRepository import poke.rogue.helper.presentation.base.error.ErrorHandleViewModel +import poke.rogue.helper.presentation.dex.logPokemonDetailToBattle import poke.rogue.helper.presentation.dex.model.PokemonUiModel import poke.rogue.helper.presentation.util.event.MutableEventFlow import poke.rogue.helper.presentation.util.event.asEventFlow @@ -77,17 +78,21 @@ class PokemonDetailViewModel( override fun navigateToBattleWithMine() { viewModelScope.launch { - val navigation2 = NavigationEvent.ToBattle.WithMyPokemon(pokemonUiModel()) - _navigationEvent.emit(navigation2) -// logger.logPokemonDetailToBattle(navigation) // TODO: change + pokemonUiModel().let { pokemon -> + val event = NavigationEvent.ToBattle.WithMyPokemon(pokemon) + _navigationEvent.emit(event) + logger.logPokemonDetailToBattle(event) + } } } override fun navigateToBattleWithOpponent() { viewModelScope.launch { - val navigation2 = NavigationEvent.ToBattle.WithOpponentPokemon(pokemonUiModel()) - _navigationEvent.emit(navigation2) -// logger.logPokemonDetailToBattle(navigation) // TODO: change + pokemonUiModel().let { pokemon -> + val event = NavigationEvent.ToBattle.WithOpponentPokemon(pokemon) + _navigationEvent.emit(event) + logger.logPokemonDetailToBattle(event) + } } } From 1db5f42c26c8f5906fa00797bab49689921e8d3e Mon Sep 17 00:00:00 2001 From: sh1mj1 <7wlgns@gmail.com> Date: Fri, 6 Dec 2024 21:25:24 +0900 Subject: [PATCH 17/20] =?UTF-8?q?refactor(PokemonDetailViewModel,=20Activi?= =?UTF-8?q?ty):=20=ED=8F=AC=EC=BC=93=EB=AA=AC=20=EC=83=81=EC=84=B8?= =?UTF-8?q?=EB=A1=9C=20=EA=B0=80=EB=8A=94=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EB=B3=91=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dex/detail/PokemonDetailActivity.kt | 32 ++++++------------- .../dex/detail/PokemonDetailViewModel.kt | 13 +++++--- .../dex/detail/PokemonEvolutionEvent.kt | 7 ---- 3 files changed, 17 insertions(+), 35 deletions(-) delete mode 100644 android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonEvolutionEvent.kt diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt index 5649267ad..8384494a4 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt @@ -86,7 +86,6 @@ class PokemonDetailActivity : private fun initObservers() { observePokemonDetailUi() observeNavigationEvent() - observePokemonEvolutionEvent() } private fun initFloatingButtonsHandler() { @@ -127,40 +126,27 @@ class PokemonDetailActivity : HomeActivity.intent(this), ) - is PokemonDetailViewModel.NavigationEvent.ToBattle.WithMyPokemon -> + is PokemonDetailViewModel.NavigationEvent.ToBattle -> startActivity( - battleIntent(event), - ) - - is PokemonDetailViewModel.NavigationEvent.ToBattle.WithOpponentPokemon -> - startActivity( - battleIntent(event), + battleIntent( + event, + ), ) - is PokemonDetailViewModel.NavigationEvent.NONE -> return@collect - } - } - } - } - private fun observePokemonEvolutionEvent() { - repeatOnStarted { - viewModel.evolutionsEvent.collect { event -> - when (event) { - is PokemonEvolutionEvent.NavigateToPokemonDetail -> + is PokemonDetailViewModel.NavigationEvent.ToPokemonDetail.Success -> startActivity( - intent( - this, - event.pokemonId, - ), + intent(this, event.pokemonId), ) - is PokemonEvolutionEvent.SameWithCurrentPokemon -> + is PokemonDetailViewModel.NavigationEvent.ToPokemonDetail.Failure -> toast( this.stringOf( R.string.pokemon_detail_evolution_same_with_current_pokemon_message, event.pokemonName, ), ) + + is PokemonDetailViewModel.NavigationEvent.NONE -> return@collect } } } diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt index 859fc4f24..6370622c9 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailViewModel.kt @@ -36,9 +36,6 @@ class PokemonDetailViewModel( private val _navigationEvent = MutableEventFlow() val navigationEvent = _navigationEvent.asEventFlow() - private val _evolutionsEvent = MutableEventFlow() - val evolutionsEvent = _evolutionsEvent.asEventFlow() - fun updatePokemonDetail(pokemonId: String?) { requireNotNull(pokemonId) { "Pokemon ID must not be null" } viewModelScope.launch { @@ -68,10 +65,10 @@ class PokemonDetailViewModel( viewModelScope.launch { pokemonUiModel().let { pokemon -> if (pokemon.id == pokemonId) { - _evolutionsEvent.emit(PokemonEvolutionEvent.SameWithCurrentPokemon(pokemon.name)) + _navigationEvent.emit(NavigationEvent.ToPokemonDetail.Failure(pokemon.name)) return@launch } - _evolutionsEvent.emit(PokemonEvolutionEvent.NavigateToPokemonDetail(pokemonId)) + _navigationEvent.emit(NavigationEvent.ToPokemonDetail.Success(pokemonId)) } } } @@ -115,5 +112,11 @@ class PokemonDetailViewModel( data class WithOpponentPokemon(val pokemon: PokemonUiModel) : ToBattle() } + + sealed class ToPokemonDetail : NavigationEvent { + data class Success(val pokemonId: String) : ToPokemonDetail() + + data class Failure(val pokemonName: String) : ToPokemonDetail() + } } } diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonEvolutionEvent.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonEvolutionEvent.kt deleted file mode 100644 index cfe0f1f78..000000000 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonEvolutionEvent.kt +++ /dev/null @@ -1,7 +0,0 @@ -package poke.rogue.helper.presentation.dex.detail - -sealed class PokemonEvolutionEvent { - data class NavigateToPokemonDetail(val pokemonId: String) : PokemonEvolutionEvent() - - data class SameWithCurrentPokemon(val pokemonName: String) : PokemonEvolutionEvent() -} From f995cc363aa4e7c051186e59f30aacc1877c8b9c Mon Sep 17 00:00:00 2001 From: sh1mj1 <7wlgns@gmail.com> Date: Fri, 6 Dec 2024 21:30:14 +0900 Subject: [PATCH 18/20] =?UTF-8?q?refactor(PokemonDetailActivity):=20?= =?UTF-8?q?=ED=8F=AC=EC=BC=93=EB=AA=AC=20=EC=83=81=EC=84=B8=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=8F=99=20=EC=B2=98=EB=A6=AC=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dex/detail/PokemonDetailActivity.kt | 64 ++++++++++--------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt index 8384494a4..6bc139462 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/dex/detail/PokemonDetailActivity.kt @@ -133,18 +133,7 @@ class PokemonDetailActivity : ), ) - is PokemonDetailViewModel.NavigationEvent.ToPokemonDetail.Success -> - startActivity( - intent(this, event.pokemonId), - ) - - is PokemonDetailViewModel.NavigationEvent.ToPokemonDetail.Failure -> - toast( - this.stringOf( - R.string.pokemon_detail_evolution_same_with_current_pokemon_message, - event.pokemonName, - ), - ) + is PokemonDetailViewModel.NavigationEvent.ToPokemonDetail -> navigateToPokemonDetail(event) is PokemonDetailViewModel.NavigationEvent.NONE -> return@collect } @@ -152,23 +141,6 @@ class PokemonDetailActivity : } } - private fun battleIntent(battleEvent: PokemonDetailViewModel.NavigationEvent.ToBattle): Intent = - when (battleEvent) { - is PokemonDetailViewModel.NavigationEvent.ToBattle.WithMyPokemon -> - BattleActivity.intent( - this@PokemonDetailActivity, - pokemonId = battleEvent.pokemon.id, - isMine = true, - ) - - is PokemonDetailViewModel.NavigationEvent.ToBattle.WithOpponentPokemon -> - BattleActivity.intent( - this@PokemonDetailActivity, - pokemonId = battleEvent.pokemon.id, - isMine = false, - ) - } - private fun bindPokemonDetail(pokemonDetail: PokemonDetailUiState.Success) { with(binding) { ivPokemonDetailPokemon.loadImageWithProgress( @@ -206,6 +178,40 @@ class PokemonDetailActivity : ) } + private fun battleIntent(battleEvent: PokemonDetailViewModel.NavigationEvent.ToBattle): Intent = + when (battleEvent) { + is PokemonDetailViewModel.NavigationEvent.ToBattle.WithMyPokemon -> + BattleActivity.intent( + this@PokemonDetailActivity, + pokemonId = battleEvent.pokemon.id, + isMine = true, + ) + + is PokemonDetailViewModel.NavigationEvent.ToBattle.WithOpponentPokemon -> + BattleActivity.intent( + this@PokemonDetailActivity, + pokemonId = battleEvent.pokemon.id, + isMine = false, + ) + } + + private fun navigateToPokemonDetail(event: PokemonDetailViewModel.NavigationEvent.ToPokemonDetail) { + when (event) { + is PokemonDetailViewModel.NavigationEvent.ToPokemonDetail.Success -> + startActivity( + intent(this, event.pokemonId), + ) + + is PokemonDetailViewModel.NavigationEvent.ToPokemonDetail.Failure -> + toast( + this.stringOf( + R.string.pokemon_detail_evolution_same_with_current_pokemon_message, + event.pokemonName, + ), + ) + } + } + private fun toggleFloatingButtons() { val rotateOpen: Animation = AnimationUtils.loadAnimation(this, R.anim.rotate_open) val rotateClose: Animation = AnimationUtils.loadAnimation(this, R.anim.rotate_close) From 9ad269baebd349c9dcea92e34478115af64cd92e Mon Sep 17 00:00:00 2001 From: sh1mj1 <7wlgns@gmail.com> Date: Fri, 6 Dec 2024 21:36:31 +0900 Subject: [PATCH 19/20] =?UTF-8?q?fix(ko-rKR-strings):=20=ED=98=84=EC=9E=AC?= =?UTF-8?q?=20=ED=99=94=EB=A9=B4=EC=9D=98=20=ED=8F=AC=EC=BC=93=EB=AA=AC?= =?UTF-8?q?=EA=B3=BC=20=EA=B0=99=EC=9D=80=20=ED=8F=AC=EC=BC=93=EB=AA=AC?= =?UTF-8?q?=EC=9D=98=20=EC=83=81=EC=84=B8=20=ED=99=94=EB=A9=B4=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B4=EB=8F=99=ED=95=A0=20=EB=95=8C=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/app/src/main/res/values-ko-rKR/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/app/src/main/res/values-ko-rKR/strings.xml b/android/app/src/main/res/values-ko-rKR/strings.xml index fcb3008fa..f75fafa9e 100644 --- a/android/app/src/main/res/values-ko-rKR/strings.xml +++ b/android/app/src/main/res/values-ko-rKR/strings.xml @@ -118,7 +118,7 @@ 진화 체인이 없는 포켓몬입니다. 레벨 %d - 현재 화면의 포켓몬이 $s 입니다. + 현재 화면의 포켓몬이 %s 입니다. 특성 도감 From bbeac80286b4ba1be9680ddc8b9ea60a58bea86a Mon Sep 17 00:00:00 2001 From: sh1mj1 <7wlgns@gmail.com> Date: Fri, 13 Dec 2024 17:25:07 +0900 Subject: [PATCH 20/20] =?UTF-8?q?chore(ProgressBarAnimation):=20progressBa?= =?UTF-8?q?r=20=EC=97=90=20progress=20=EB=A5=BC=20=EC=A4=91=EB=B3=B5?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=84=A4=EC=A0=95=ED=95=B4=EC=A3=BC?= =?UTF-8?q?=EB=8A=94=20=EB=B6=80=EB=B6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../helper/presentation/util/view/ProgressBarAnimation.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/util/view/ProgressBarAnimation.kt b/android/app/src/main/java/poke/rogue/helper/presentation/util/view/ProgressBarAnimation.kt index 844a9f741..352f9264c 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/util/view/ProgressBarAnimation.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/util/view/ProgressBarAnimation.kt @@ -16,9 +16,6 @@ class ProgressBarAnimation( super.applyTransformation(interpolatedTime, t) val value = from + to * interpolatedTime progressBar.progress = value.toInt() - progressBar.apply { - progress = value.toInt() - } } }