Skip to content

Commit

Permalink
Revert "[1.1.1/AN-FEAT] 포켓몬 상세에서 배틀 도우미로 가는 floating 버튼 추가 (#378)"
Browse files Browse the repository at this point in the history
This reverts commit 7174c8d.
  • Loading branch information
murjune authored Oct 23, 2024
1 parent 5c91a83 commit e95393f
Show file tree
Hide file tree
Showing 16 changed files with 15 additions and 310 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ 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.filter.PokeFilterUiModel
import poke.rogue.helper.presentation.dex.sort.PokemonSortUiModel

Expand Down Expand Up @@ -37,27 +36,3 @@ private fun PokeFilterUiModel.toParams(): List<AnalyticsEvent.Param> {
AnalyticsEvent.Param(key = "type", value = it.name)
} + AnalyticsEvent.Param(key = "generation", value = selectedGeneration.name)
}

fun AnalyticsLogger.logPokemonDetailToBattle(event: NavigateToBattleEvent) {
val eventType = "pokemon_detail_to_battle_directly"
logEvent(
AnalyticsEvent(
type = eventType,
extras = event.toParams(),
),
)
}

private fun NavigateToBattleEvent.toParams(): List<AnalyticsEvent.Param> {
val (battleRoleValue, pokemon) =
when (this) {
is NavigateToBattleEvent.WithMyPokemon -> Pair("MyPokemon", pokemon)
is NavigateToBattleEvent.WithOpponentPokemon -> Pair("EnemyPokemon", pokemon)
}

return listOf(
AnalyticsEvent.Param(key = "battle_role", value = battleRoleValue),
AnalyticsEvent.Param(key = "pokemon_id", value = pokemon.id),
AnalyticsEvent.Param(key = "pokemon_name", value = pokemon.name),
)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package poke.rogue.helper.presentation.dex.detail
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import android.widget.LinearLayout.LayoutParams
import androidx.activity.viewModels
import androidx.appcompat.widget.Toolbar
Expand All @@ -24,7 +21,6 @@ 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 All @@ -35,8 +31,6 @@ class PokemonDetailActivity :
private lateinit var pokemonTypesAdapter: PokemonTypesAdapter
private lateinit var pokemonDetailPagerAdapter: PokemonDetailPagerAdapter

private var isExpanded = false

override val toolbar: Toolbar
get() = binding.toolbarPokemonDetail

Expand All @@ -46,22 +40,9 @@ class PokemonDetailActivity :

binding.eventHandler = viewModel
binding.lifecycleOwner = this
binding.vm = viewModel

initAdapter()
initObservers()
initFloatingButtonsHandler()
}

override fun onSaveInstanceState(outState: Bundle) {
outState.putBoolean(IS_EXPANDED, isExpanded)
super.onSaveInstanceState(outState)
}

override fun onRestoreInstanceState(savedInstanceState: Bundle) {
isExpanded = savedInstanceState.getBoolean(IS_EXPANDED)
super.onRestoreInstanceState(savedInstanceState)
updateFloatingButtonsState()
}

private fun initAdapter() {
Expand All @@ -88,13 +69,6 @@ class PokemonDetailActivity :
observeNavigateToAbilityDetailEvent()
observeNavigateToBiomeDetailEvent()
observeNavigateToPokemonDetailEvent()
observeNavigateToBattleEvent()
}

private fun initFloatingButtonsHandler() {
binding.fabPokemonDetailBattle.setOnClickListener {
toggleFloatingButtons()
}
}

private fun observePokemonDetailUi() {
Expand Down Expand Up @@ -144,24 +118,6 @@ 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()
}
}
}
}
}

private fun bindPokemonDetail(pokemonDetail: PokemonDetailUiState.Success) {
with(binding) {
ivPokemonDetailPokemon.loadImageWithProgress(
Expand All @@ -184,44 +140,8 @@ class PokemonDetailActivity :
)
}

private fun toggleFloatingButtons() {
val rotateOpen: Animation = AnimationUtils.loadAnimation(this, R.anim.rotate_open)
val rotateClose: Animation = AnimationUtils.loadAnimation(this, R.anim.rotate_close)
val fromBottom: Animation = AnimationUtils.loadAnimation(this, R.anim.from_bottom)
val toBottom: Animation = AnimationUtils.loadAnimation(this, R.anim.to_bottom)

updateFloatingButtonsState()
with(binding) {
if (!isExpanded) {
fabPokemonDetailBattle.startAnimation(rotateOpen)
efabPokemonDetailBattleWithMine.startAnimation(fromBottom)
efabPokemonDetailBattleWithOpponent.startAnimation(fromBottom)
} else {
fabPokemonDetailBattle.startAnimation(rotateClose)
efabPokemonDetailBattleWithMine.startAnimation(toBottom)
efabPokemonDetailBattleWithOpponent.startAnimation(toBottom)
}
}

isExpanded = !isExpanded
}

private fun updateFloatingButtonsState() {
with(binding) {
if (isExpanded) {
efabPokemonDetailBattleWithMine.visibility = View.VISIBLE
efabPokemonDetailBattleWithOpponent.visibility = View.VISIBLE
} else {
efabPokemonDetailBattleWithMine.visibility = View.INVISIBLE
efabPokemonDetailBattleWithOpponent.visibility = View.INVISIBLE
}
}
}

companion object {
private const val POKEMON_ID = "pokemonId"
private const val IS_EXPANDED = "isExpanded"

val TAG: String = PokemonDetailActivity::class.java.simpleName

private val typesUiConfig =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,4 @@ interface PokemonDetailNavigateHandler {
fun navigateToHome()

fun navigateToPokemonDetail(pokemonId: String)

fun navigateToBattleWithMine()

fun navigateToBattleWithOpponent()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package poke.rogue.helper.presentation.dex.detail

import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
Expand All @@ -16,37 +17,31 @@ import poke.rogue.helper.analytics.analyticsLogger
import poke.rogue.helper.data.repository.DexRepository
import poke.rogue.helper.presentation.base.BaseViewModelFactory
import poke.rogue.helper.presentation.base.error.ErrorHandleViewModel
import poke.rogue.helper.presentation.dex.logPokemonDetailToBattle
import poke.rogue.helper.presentation.util.event.MutableEventFlow
import poke.rogue.helper.presentation.util.event.asEventFlow

class PokemonDetailViewModel(
private val dexRepository: DexRepository,
private val logger: AnalyticsLogger = analyticsLogger(),
logger: AnalyticsLogger = analyticsLogger(),
) :
ErrorHandleViewModel(logger),
PokemonDetailNavigateHandler {
private val _uiState: MutableStateFlow<PokemonDetailUiState> = MutableStateFlow(PokemonDetailUiState.IsLoading)
val uiState = _uiState.asStateFlow()

val isLoading: StateFlow<Boolean> =
val isEmpty: StateFlow<Boolean> =
uiState.map { it is PokemonDetailUiState.IsLoading }
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000L), true)

private val _navigationToAbilityDetailEvent = MutableEventFlow<String>()
val navigationToAbilityDetailEvent = _navigationToAbilityDetailEvent.asEventFlow()
private val _navigationToAbilityDetailEvent = MutableSharedFlow<String>()
val navigationToAbilityDetailEvent: SharedFlow<String> = _navigationToAbilityDetailEvent.asSharedFlow()

private val _navigationToBiomeDetailEvent = MutableEventFlow<String>()
val navigationToBiomeDetailEvent = _navigationToBiomeDetailEvent.asEventFlow()
private val _navigationToBiomeDetailEvent = MutableSharedFlow<String>()
val navigationToBiomeDetailEvent: SharedFlow<String> = _navigationToBiomeDetailEvent.asSharedFlow()

private val _navigateToHomeEvent = MutableEventFlow<Boolean>()
val navigateToHomeEvent = _navigateToHomeEvent.asEventFlow()
private val _navigateToHomeEvent = MutableSharedFlow<Boolean>()
val navigateToHomeEvent = _navigateToHomeEvent.asSharedFlow()

private val _navigateToPokemonDetailEvent = MutableEventFlow<String>()
val navigateToPokemonDetailEvent = _navigateToPokemonDetailEvent.asEventFlow()

private val _navigateToBattleEvent = MutableEventFlow<NavigateToBattleEvent>()
val navigateToBattleEvent = _navigateToBattleEvent.asEventFlow()
private val _navigateToPokemonDetailEvent = MutableSharedFlow<String>()
val navigateToPokemonDetailEvent = _navigateToPokemonDetailEvent.asSharedFlow()

fun updatePokemonDetail(pokemonId: String?) {
requireNotNull(pokemonId) { "Pokemon ID must not be null" }
Expand Down Expand Up @@ -79,27 +74,6 @@ class PokemonDetailViewModel(
}
}

override fun navigateToBattleWithMine() {
viewModelScope.launch {
val navigation = NavigateToBattleEvent.WithMyPokemon(pokemonUiModel())
_navigateToBattleEvent.emit(navigation)
logger.logPokemonDetailToBattle(navigation)
}
}

override fun navigateToBattleWithOpponent() {
viewModelScope.launch {
val navigation = NavigateToBattleEvent.WithOpponentPokemon(pokemonUiModel())
_navigateToBattleEvent.emit(navigation)
logger.logPokemonDetailToBattle(navigation)
}
}

private suspend fun pokemonUiModel() =
uiState
.filterIsInstance<PokemonDetailUiState.Success>()
.first().pokemon

companion object {
fun factory(dexRepository: DexRepository): ViewModelProvider.Factory =
BaseViewModelFactory { PokemonDetailViewModel(dexRepository) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fun Context.stringOf(

fun Context.stringArrayOf(
@ArrayRes resId: Int,
): Array<String> = resources.getStringArray(resId)
) = resources.getStringArray(resId)

fun Context.colorOf(
@ColorRes resId: Int,
Expand Down
20 changes: 0 additions & 20 deletions android/app/src/main/res/anim/from_bottom.xml

This file was deleted.

11 changes: 0 additions & 11 deletions android/app/src/main/res/anim/rotate_close.xml

This file was deleted.

10 changes: 0 additions & 10 deletions android/app/src/main/res/anim/rotate_open.xml

This file was deleted.

23 changes: 0 additions & 23 deletions android/app/src/main/res/anim/to_bottom.xml

This file was deleted.

Binary file not shown.
Binary file not shown.
14 changes: 0 additions & 14 deletions android/app/src/main/res/drawable/shape_red_20_fill_20_rect.xml

This file was deleted.

Loading

0 comments on commit e95393f

Please sign in to comment.