Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.1.0/AN-FEAT] 배틀 선택 / 결과 UI 개선 #316

Merged
merged 7 commits into from
Sep 14, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import poke.rogue.helper.presentation.base.toolbar.ToolbarActivity
import poke.rogue.helper.presentation.battle.model.SelectionData
import poke.rogue.helper.presentation.battle.model.WeatherUiModel
import poke.rogue.helper.presentation.battle.selection.BattleSelectionActivity
import poke.rogue.helper.presentation.util.context.colorOf
import poke.rogue.helper.presentation.util.parcelable
import poke.rogue.helper.presentation.util.repeatOnStarted
import poke.rogue.helper.presentation.util.view.setImage
Expand Down Expand Up @@ -123,6 +124,7 @@ class BattleActivity : ToolbarActivity<ActivityBattleBinding>(R.layout.activity_
val result = it.result
binding.tvPowerContent.text = result.power
binding.tvMultiplierContent.text = result.multiplier
binding.tvMultiplierContent.setTextColor(colorOf(result.colorRes))
binding.tvCalculatedPowerContent.text = result.calculatedResult
binding.tvAccuracyContent.text =
getString(R.string.battle_accuracy_title, result.accuracy)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
package poke.rogue.helper.presentation.battle.model

import androidx.annotation.ColorRes
import poke.rogue.helper.R
import poke.rogue.helper.data.model.BattlePrediction
import poke.rogue.helper.presentation.battle.model.BattlePredictionUiModel.Companion.DEFAULT_NUMBER_FORMAT
import poke.rogue.helper.presentation.battle.model.BattlePredictionUiModel.Companion.NO_EFFECT_VALUE

data class BattlePredictionUiModel(val power: String, val accuracy: String, val multiplier: String, val calculatedResult: String)
data class BattlePredictionUiModel(
val power: String,
val accuracy: String,
val multiplier: String,
val calculatedResult: String,
@ColorRes val colorRes: Int,
) {
companion object {
const val NO_EFFECT_VALUE = "-"
const val DEFAULT_NUMBER_FORMAT = "%.1f"
}
}

fun BattlePrediction.toUi(format: String = "%.1f"): BattlePredictionUiModel =
BattlePredictionUiModel(
power = power.toString(),
fun BattlePrediction.toUi(format: String = DEFAULT_NUMBER_FORMAT): BattlePredictionUiModel {
val formattedPower = if (power < 0) NO_EFFECT_VALUE else power.toString()
val formattedResult = if (calculatedResult < 0) NO_EFFECT_VALUE else String.format(format, calculatedResult)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기술 위력과 계산된 위력이 - 로 표시되는 군요.
image
이러한 상황일 때 추가로 배수도 - 로 표시하는 게 더 자연스러워 보입니다.
그리고 오른쪽 하단에 명중 확률도 조정을 해야 할 듯..

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이러한 상황일 때 추가로 배수도 - 로 표시하는 게 더 자연스러워 보입니다.

저는 배수는 1.0으로 보여주는 것도 좋아요 !
3개 다 - - - 로 보여주면 뭔가 어색할 것 같기도 해요

명중 확률

이 부분은 동의합니다 !

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저두요

val color =
when {
multiplier < 1.0 -> R.color.poke_grey_60
multiplier in 1.0..2.9 -> R.color.poke_red_20
multiplier >= 3 -> R.color.poke_green_20
else -> R.color.poke_white
}

return BattlePredictionUiModel(
power = formattedPower,
accuracy = String.format(format, accuracy),
multiplier = String.format(format, multiplier),
calculatedResult = String.format(format, calculatedResult),
calculatedResult = formattedResult,
colorRes = color,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import poke.rogue.helper.presentation.util.view.LinearSpacingItemDecoration
import poke.rogue.helper.presentation.util.view.dp
import poke.rogue.helper.presentation.util.view.setOnSearchAction

class PokemonSelectionFragment :
ErrorHandleFragment<FragmentPokemonSelectionBinding>(R.layout.fragment_pokemon_selection) {
class PokemonSelectionFragment : ErrorHandleFragment<FragmentPokemonSelectionBinding>(R.layout.fragment_pokemon_selection) {
private val sharedViewModel: BattleSelectionViewModel by activityViewModels()
private val viewModel: PokemonSelectionViewModel by viewModels<PokemonSelectionViewModel> {
PokemonSelectionViewModel.factory(
Expand Down Expand Up @@ -72,7 +71,12 @@ class PokemonSelectionFragment :
private fun initObserver() {
repeatOnStarted {
viewModel.filteredPokemon.collect {
pokemonAdapter.submitList(it)
pokemonAdapter.submitList(it) {
if (sharedViewModel.previousSelection.selectedPokemon() != null) {
val position = it.indexOfFirst { it.isSelected }
binding.rvPokemons.scrollToPosition(position)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 섬세한데요~
submitList 에 람다로 바로 콜백을 지정할 수 있군요~

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

헐 대박.. 제 코드 수정하러 갑니다 ㅋㅋ

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 이게 되네 ㅋㅋㅋ

}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ class SkillSelectionFragment :

repeatOnStarted {
viewModel.filteredSkills.collect {
skillAdapter.submitList(it)
skillAdapter.submitList(it) {
if (viewModel.previousSkillsId != null) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

viewModel.previousSkillsId
이제 봤는데 이전 스킬 id 가 이전 스킬 id 로 되어 있네요 ㅋㅋ

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그러게 ㅋㅋㅋㅋ

val position = it.indexOfFirst { it.isSelected }
binding.rvSkills.scrollToPosition(position)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class RemoteBattleDataSource(
}
.getOrThrow()
.map { it.toData() }
.filter { it.power > 0 }

suspend fun calculatedBattlePrediction(
weatherId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import poke.rogue.helper.data.model.Weather
class DefaultBattleRepository(private val remoteBattleDataSource: RemoteBattleDataSource) : BattleRepository {
override suspend fun weathers(): List<Weather> = remoteBattleDataSource.weathers()

override suspend fun availableSkills(dexNumber: Long): List<BattleSkill> = remoteBattleDataSource.availableSkills(dexNumber)
override suspend fun availableSkills(dexNumber: Long): List<BattleSkill> = remoteBattleDataSource.availableSkills(dexNumber).distinct()

override suspend fun calculatedBattlePrediction(
weatherId: String,
Expand Down
Loading