Skip to content

Commit

Permalink
feat: 포켓몬 상세에서 배틀 페이지 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
JoYehyun99 committed Oct 23, 2024
1 parent 2a92956 commit a15742b
Showing 1 changed file with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ import poke.rogue.helper.data.repository.DefaultDexRepository
import poke.rogue.helper.databinding.ActivityPokemonDetailBinding
import poke.rogue.helper.presentation.ability.AbilityActivity
import poke.rogue.helper.presentation.base.toolbar.ToolbarActivity
import poke.rogue.helper.presentation.battle.BattleActivity
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.repeatOnStarted
import poke.rogue.helper.presentation.util.view.dp
import poke.rogue.helper.presentation.util.view.loadImageWithProgress
import timber.log.Timber

class PokemonDetailActivity :
ToolbarActivity<ActivityPokemonDetailBinding>(R.layout.activity_pokemon_detail) {
Expand Down Expand Up @@ -77,7 +78,10 @@ class PokemonDetailActivity :
}

val tabTitles = stringArrayOf(R.array.pokemon_detail_tab_titles)
TabLayoutMediator(binding.tabLayoutPokemonDetail, binding.pagerPokemonDetail) { tab, position ->
TabLayoutMediator(
binding.tabLayoutPokemonDetail,
binding.pagerPokemonDetail,
) { tab, position ->
tab.text = tabTitles[position]
}.attach()
}
Expand Down Expand Up @@ -144,24 +148,36 @@ class PokemonDetailActivity :
}
}

// TODO: 예니 여기서 하면 될 Battle Activity 로 이동하면 될 것 같아요
private fun observeNavigateToBattleEvent() {
repeatOnStarted {
viewModel.navigateToBattleEvent.collect { battleEvent ->
when (battleEvent) {
is NavigateToBattleEvent.WithMyPokemon -> {
Timber.d("내 포켓몬으로 배틀 액티비티로 이동 pokemon: ${battleEvent.pokemon}")
}

is NavigateToBattleEvent.WithOpponentPokemon -> {
Timber.d("상대 포켓몬으로 배틀 액티비티로 이동 pokemon: ${battleEvent.pokemon}")
// TODO()
}
val intent = battleIntent(battleEvent)
startActivity<BattleActivity> {
putExtras(intent)
}
}
}
}

private fun battleIntent(battleEvent: NavigateToBattleEvent): Intent =
when (battleEvent) {
is NavigateToBattleEvent.WithMyPokemon -> {
BattleActivity.intent(
this@PokemonDetailActivity,
pokemonId = battleEvent.pokemon.id,
isMine = true,
)
}

is NavigateToBattleEvent.WithOpponentPokemon -> {
BattleActivity.intent(
this@PokemonDetailActivity,
pokemonId = battleEvent.pokemon.id,
isMine = false,
)
}
}

private fun bindPokemonDetail(pokemonDetail: PokemonDetailUiState.Success) {
with(binding) {
ivPokemonDetailPokemon.loadImageWithProgress(
Expand Down

0 comments on commit a15742b

Please sign in to comment.