diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/battle/BattleActivity.kt b/android/app/src/main/java/poke/rogue/helper/presentation/battle/BattleActivity.kt index 821e5d04..60657ca4 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/battle/BattleActivity.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/battle/BattleActivity.kt @@ -57,9 +57,10 @@ class BattleActivity : ToolbarActivity(R.layout.activity_ private fun initSpinner() { binding.spinnerWeather.adapter = weatherAdapter - binding.spinnerWeather.onItemSelectedListener = itemSelectListener { - viewModel.updateWeather(it) - } + binding.spinnerWeather.onItemSelectedListener = + itemSelectListener { + viewModel.updateWeather(it) + } } private fun initObserver() { diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/battle/BattleViewModel.kt b/android/app/src/main/java/poke/rogue/helper/presentation/battle/BattleViewModel.kt index 9bbc86ec..89fd9ee6 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/battle/BattleViewModel.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/battle/BattleViewModel.kt @@ -39,15 +39,16 @@ class BattleViewModel( private val _selectedState = MutableStateFlow(BattleSelectionsState.DEFAULT) val selectedState = _selectedState.asStateFlow() - val weatherPos: StateFlow = combine( - battleRepository.savedWeatherStream(), - weathers, - ) { weather, weathers -> - if (weather == null || weathers.isEmpty()) return@combine null - if (weathers.any { it.id == weather.id }.not()) return@combine null - weathers.indexOfFirst { it.id == weather.id } - }.filterNotNull() - .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), 0) + val weatherPos: StateFlow = + combine( + battleRepository.savedWeatherStream(), + weathers, + ) { weather, weathers -> + if (weather == null || weathers.isEmpty()) return@combine null + if (weathers.any { it.id == weather.id }.not()) return@combine null + weathers.indexOfFirst { it.id == weather.id } + }.filterNotNull() + .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), 0) private val _navigateToSelection = MutableSharedFlow() val navigateToSelection = _navigateToSelection.asSharedFlow() diff --git a/android/app/src/main/java/poke/rogue/helper/presentation/battle/view/WeatherItemSelectedListener.kt b/android/app/src/main/java/poke/rogue/helper/presentation/battle/view/WeatherItemSelectedListener.kt index fb125198..84aad3d6 100644 --- a/android/app/src/main/java/poke/rogue/helper/presentation/battle/view/WeatherItemSelectedListener.kt +++ b/android/app/src/main/java/poke/rogue/helper/presentation/battle/view/WeatherItemSelectedListener.kt @@ -24,4 +24,4 @@ inline fun itemSelectListener(crossinline onSelected: (T) -> Unit): override fun onNothingSelected(parent: AdapterView<*>?) {} } -} \ No newline at end of file +} diff --git a/android/data/src/main/java/poke/rogue/helper/data/repository/DefaultBattleRepository.kt b/android/data/src/main/java/poke/rogue/helper/data/repository/DefaultBattleRepository.kt index 8de60d43..8845783a 100644 --- a/android/data/src/main/java/poke/rogue/helper/data/repository/DefaultBattleRepository.kt +++ b/android/data/src/main/java/poke/rogue/helper/data/repository/DefaultBattleRepository.kt @@ -40,16 +40,14 @@ class DefaultBattleRepository( opponentPokemonId = opponentPokemonId, ) - override suspend fun savePokemon(pokemonId: String) = - localBattleDataSource.savePokemon(pokemonId) + override suspend fun savePokemon(pokemonId: String) = localBattleDataSource.savePokemon(pokemonId) override suspend fun savePokemonWithSkill( pokemonId: String, skillId: String, ) = localBattleDataSource.savePokemonWithSkill(pokemonId, skillId) - override fun savedPokemonStream(): Flow = - localBattleDataSource.pokemonId().map { it?.let { pokemonRepository.pokemon(it) } } + override fun savedPokemonStream(): Flow = localBattleDataSource.pokemonId().map { it?.let { pokemonRepository.pokemon(it) } } override fun savedPokemonWithSkillStream(): Flow = localBattleDataSource.pokemonWithSkill().map { @@ -60,8 +58,7 @@ class DefaultBattleRepository( } } - override suspend fun saveWeather(weatherId: String) = - localBattleDataSource.saveWeather(weatherId) + override suspend fun saveWeather(weatherId: String) = localBattleDataSource.saveWeather(weatherId) override fun savedWeatherStream(): Flow = localBattleDataSource.weatherId().map {