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.1/AN-REFACTOR] 타입, 배틀 화면 Koin 적용 #415

Merged
merged 33 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ff06fe0
feat: 포켓몬 아이디를 통해 새로운 포켓몬 선택 기능
JoYehyun99 Oct 18, 2024
bd55756
feat: intent를 통해 선택 타입 및 포켓몬 아이디 받기
JoYehyun99 Oct 18, 2024
6f542d9
ui: 바이옴 디테일 페이지에 배틀 페이지 이동 모드 토글 버튼 설정
JoYehyun99 Oct 20, 2024
ca6d4fc
feat: 이동 모드에 따라 다르게 페이지 이동
JoYehyun99 Oct 20, 2024
dd61ee1
feat: 이동 모드 설정값 datastore에 저장
JoYehyun99 Oct 20, 2024
09d4095
chore: balloon gradle 설정
JoYehyun99 Oct 20, 2024
fb1eaa1
feat: tooltip 안내 메세지 제공
JoYehyun99 Oct 20, 2024
63b137a
fix: 포켓몬 선택 저장 기능 반영
JoYehyun99 Oct 20, 2024
a46170a
feat: 새로운 datastore 파일 Koin 적용
JoYehyun99 Oct 20, 2024
e7d1910
ui: 작은 화면 대응
JoYehyun99 Oct 20, 2024
66068c8
chore: 린트 설정 완화
JoYehyun99 Oct 20, 2024
baa0b16
refactor: 네이밍 수정
JoYehyun99 Oct 21, 2024
6f9d8a6
refactor: 리뷰 반영
JoYehyun99 Oct 21, 2024
62bc9ab
fix: 초기 데이터 배틀 선택시 결과값 출력 안되는 문제 해결
JoYehyun99 Oct 21, 2024
2be01a2
chore: 린트 체크
JoYehyun99 Oct 21, 2024
637152b
chore: 린트 체크
JoYehyun99 Oct 21, 2024
c130755
chore: 바이옴 페이지 이동 로그 달기
JoYehyun99 Oct 23, 2024
2a92956
conflict 해결
JoYehyun99 Oct 23, 2024
a15742b
feat: 포켓몬 상세에서 배틀 페이지 이동
JoYehyun99 Oct 23, 2024
9418dcd
test: FakeBattleRepository 구현
JoYehyun99 Oct 23, 2024
6d89b66
feat: BattleViewModel 수동 주입 -> koin 변경
JoYehyun99 Oct 23, 2024
7f4da24
test: BattleViewModel 주입 테스트
JoYehyun99 Oct 23, 2024
a143d66
refactor: 배틀 선택 화면 koin 적용
JoYehyun99 Oct 23, 2024
d0df36b
test: BattleSelectionActivity 주입 테스트
JoYehyun99 Oct 23, 2024
976e6b8
refactor: TypeActivity koin 적용
JoYehyun99 Oct 23, 2024
934cd5f
test: TypeActivity 주입 테스트
JoYehyun99 Oct 23, 2024
c28808d
chore: 코드 정리
JoYehyun99 Oct 23, 2024
2003667
refactor: 구체적인 변수명들 대신 Params 사용
JoYehyun99 Oct 23, 2024
6dfc1d8
conflict 해결
JoYehyun99 Oct 24, 2024
3c892b6
refactor: 린트 체크
JoYehyun99 Oct 24, 2024
c7e129d
refactor: 린트 체크
JoYehyun99 Oct 24, 2024
4c937a9
test: 선택 Fragment 테스트 추가
JoYehyun99 Oct 24, 2024
0475bba
chore: 린트 체크
JoYehyun99 Oct 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions android/app/src/main/java/poke/rogue/helper/di/ViewModelModule.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
package poke.rogue.helper.di

import org.koin.core.module.dsl.viewModel
import org.koin.core.module.dsl.viewModelOf
import org.koin.dsl.module
import poke.rogue.helper.presentation.battle.BattleViewModel
import poke.rogue.helper.presentation.battle.selection.BattleSelectionViewModel
import poke.rogue.helper.presentation.battle.selection.pokemon.PokemonSelectionViewModel
import poke.rogue.helper.presentation.battle.selection.skill.SkillSelectionViewModel
import poke.rogue.helper.presentation.dex.PokemonListViewModel
import poke.rogue.helper.presentation.type.TypeViewModel

val viewModelModule
get() =
module {
viewModelOf(::PokemonListViewModel)
viewModel<BattleViewModel> { params ->
BattleViewModel(get(), get(), get(), params.getOrNull(), params.getOrNull())
}
viewModel<BattleSelectionViewModel> { params ->
BattleSelectionViewModel(params.get(), params.get(), get())
}
viewModel { params ->
PokemonSelectionViewModel(get(), params.getOrNull(), get())
}
viewModel { params ->
SkillSelectionViewModel(get(), params.getOrNull(), get())
}
viewModelOf(::TypeViewModel)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.appcompat.widget.Toolbar
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.koin.core.parameter.parametersOf
import poke.rogue.helper.R
import poke.rogue.helper.data.repository.DefaultBattleRepository
import poke.rogue.helper.data.repository.DefaultDexRepository
import poke.rogue.helper.databinding.ActivityBattleBinding
import poke.rogue.helper.presentation.base.toolbar.ToolbarActivity
import poke.rogue.helper.presentation.battle.model.SelectionData
Expand All @@ -25,15 +24,12 @@ import poke.rogue.helper.presentation.util.view.setImage
import timber.log.Timber

class BattleActivity : ToolbarActivity<ActivityBattleBinding>(R.layout.activity_battle) {
private val viewModel by viewModels<BattleViewModel> {
BattleViewModel.factory(
private val viewModel by viewModel<BattleViewModel> {
parametersOf(
intent.getStringExtra(POKEMON_ID),
intent.serializable(SELECTION_TYPE),
DefaultBattleRepository.instance(applicationContext),
DefaultDexRepository.instance(),
)
}

private val weatherAdapter by lazy {
WeatherSpinnerAdapter(this)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package poke.rogue.helper.presentation.battle

import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -19,7 +18,6 @@ import poke.rogue.helper.analytics.AnalyticsLogger
import poke.rogue.helper.analytics.analyticsLogger
import poke.rogue.helper.data.repository.BattleRepository
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.battle.model.BattlePredictionUiModel
import poke.rogue.helper.presentation.battle.model.PokemonSelectionUiModel
Expand Down Expand Up @@ -246,23 +244,6 @@ class BattleViewModel(
} else {
SelectionData.WithoutSkill(previousPokemonSelection)
}

companion object {
fun factory(
pokemonId: String?,
selectionType: SelectionType?,
battleRepository: BattleRepository,
pokemonRepository: DexRepository,
): ViewModelProvider.Factory =
BaseViewModelFactory {
BattleViewModel(
battleRepository = battleRepository,
pokemonId = pokemonId,
selectionType = selectionType,
pokemonRepository = pokemonRepository,
)
}
}
}

data class SelectionNavigationData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package poke.rogue.helper.presentation.battle.selection
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.widget.Toolbar
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.koin.core.parameter.parametersOf
import poke.rogue.helper.R
import poke.rogue.helper.databinding.ActivityBattleSelectionBinding
import poke.rogue.helper.presentation.base.error.ErrorHandleActivity
Expand All @@ -20,8 +21,8 @@ import poke.rogue.helper.presentation.util.view.setImage

class BattleSelectionActivity :
ErrorHandleActivity<ActivityBattleSelectionBinding>(R.layout.activity_battle_selection) {
private val viewModel by viewModels<BattleSelectionViewModel> {
BattleSelectionViewModel.factory(selectionMode, previousSelection)
private val viewModel by viewModel<BattleSelectionViewModel> {
parametersOf(selectionMode, previousSelection)
}
private val previousSelection by lazy {
intent.parcelable<SelectionData>(KEY_PREVIOUS_SELECTION) ?: error("잘못된 선택 데이터")
Expand Down Expand Up @@ -93,8 +94,8 @@ class BattleSelectionActivity :
}

companion object {
private const val KEY_SELECTION_MODE = "selectionMode"
private const val KEY_PREVIOUS_SELECTION = "previousSelection"
const val KEY_SELECTION_MODE = "selectionMode"
const val KEY_PREVIOUS_SELECTION = "previousSelection"
const val KEY_SELECTION_RESULT = "selectionResult"

fun intent(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package poke.rogue.helper.presentation.battle.selection

import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -14,7 +13,6 @@ import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import poke.rogue.helper.analytics.AnalyticsLogger
import poke.rogue.helper.analytics.analyticsLogger
import poke.rogue.helper.presentation.base.BaseViewModelFactory
import poke.rogue.helper.presentation.base.error.ErrorHandleViewModel
import poke.rogue.helper.presentation.battle.BattleSelectionUiState
import poke.rogue.helper.presentation.battle.isSelected
Expand Down Expand Up @@ -84,17 +82,17 @@ class BattleSelectionViewModel(
}
}

private fun initialStep(selectionMode: SelectionMode): SelectionStep {
return when {
private fun initialStep(selectionMode: SelectionMode): SelectionStep =
when {
selectionMode == SelectionMode.SKILL_FIRST && previousSelection != SelectionData.NoSelection -> {
val selected = requireNotNull(previousSelection.selectedPokemon()) { "포켓몬이 선택되지 않았습니다." }
val selected =
requireNotNull(previousSelection.selectedPokemon()) { "포켓몬이 선택되지 않았습니다." }
updateDexNumberForSkills(selected.dexNumber)
SelectionStep.SKILL_SELECTION
}

else -> SelectionStep.POKEMON_SELECTION
}
}

fun selectPokemon(pokemon: PokemonSelectionUiModel) {
_selectedPokemon.value = BattleSelectionUiState.Selected(pokemon)
Expand Down Expand Up @@ -149,11 +147,4 @@ class BattleSelectionViewModel(
_currentStep.value = prevPage
}
}

companion object {
fun factory(
selectionMode: SelectionMode,
previousSelection: SelectionData,
): ViewModelProvider.Factory = BaseViewModelFactory { BattleSelectionViewModel(selectionMode, previousSelection) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import org.koin.androidx.viewmodel.ext.android.activityViewModel
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.koin.core.parameter.parametersOf
import poke.rogue.helper.R
import poke.rogue.helper.data.repository.DefaultDexRepository
import poke.rogue.helper.databinding.FragmentPokemonSelectionBinding
import poke.rogue.helper.presentation.base.error.ErrorHandleFragment
import poke.rogue.helper.presentation.base.error.ErrorHandleViewModel
Expand All @@ -19,13 +19,11 @@ 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) {
private val sharedViewModel: BattleSelectionViewModel by activityViewModels()
private val viewModel: PokemonSelectionViewModel by viewModels<PokemonSelectionViewModel> {
PokemonSelectionViewModel.factory(
DefaultDexRepository.instance(),
sharedViewModel.previousSelection.selectedPokemon(),
)
class PokemonSelectionFragment :
ErrorHandleFragment<FragmentPokemonSelectionBinding>(R.layout.fragment_pokemon_selection) {
private val sharedViewModel: BattleSelectionViewModel by activityViewModel()
private val viewModel: PokemonSelectionViewModel by viewModel<PokemonSelectionViewModel> {
parametersOf(sharedViewModel.previousSelection.selectedPokemon())
}
private val pokemonAdapter: PokemonSelectionAdapter by lazy {
PokemonSelectionAdapter(viewModel)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package poke.rogue.helper.presentation.battle.selection.pokemon

import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
Expand All @@ -18,7 +17,6 @@ import kotlinx.coroutines.launch
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.BaseViewModelFactory
import poke.rogue.helper.presentation.base.error.ErrorHandleViewModel
import poke.rogue.helper.presentation.battle.model.PokemonSelectionUiModel
import poke.rogue.helper.presentation.battle.model.toSelectionUi
Expand Down Expand Up @@ -82,11 +80,4 @@ class PokemonSelectionViewModel(
searchQuery.emit(name)
}
}

companion object {
fun factory(
dexRepository: DexRepository,
previousSelection: PokemonSelectionUiModel?,
): ViewModelProvider.Factory = BaseViewModelFactory { PokemonSelectionViewModel(dexRepository, previousSelection) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import org.koin.androidx.viewmodel.ext.android.activityViewModel
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.koin.core.parameter.parametersOf
import poke.rogue.helper.R
import poke.rogue.helper.data.repository.DefaultBattleRepository
import poke.rogue.helper.databinding.FragmentSkillSelectionBinding
import poke.rogue.helper.presentation.base.error.ErrorHandleFragment
import poke.rogue.helper.presentation.base.error.ErrorHandleViewModel
Expand All @@ -21,12 +21,9 @@ import poke.rogue.helper.presentation.util.view.setOnSearchAction

class SkillSelectionFragment :
ErrorHandleFragment<FragmentSkillSelectionBinding>(R.layout.fragment_skill_selection) {
private val sharedViewModel: BattleSelectionViewModel by activityViewModels()
private val viewModel: SkillSelectionViewModel by viewModels<SkillSelectionViewModel> {
SkillSelectionViewModel.factory(
DefaultBattleRepository.instance(requireContext().applicationContext),
sharedViewModel.previousSelection as? SelectionData.WithSkill,
)
private val sharedViewModel: BattleSelectionViewModel by activityViewModel()
private val viewModel: SkillSelectionViewModel by viewModel<SkillSelectionViewModel> {
parametersOf(sharedViewModel.previousSelection as? SelectionData.WithSkill)
}
private val skillAdapter: SkillSelectionAdapter by lazy {
SkillSelectionAdapter(viewModel)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package poke.rogue.helper.presentation.battle.selection.skill

import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
Expand All @@ -18,7 +17,6 @@ import kotlinx.coroutines.launch
import poke.rogue.helper.analytics.AnalyticsLogger
import poke.rogue.helper.analytics.analyticsLogger
import poke.rogue.helper.data.repository.BattleRepository
import poke.rogue.helper.presentation.base.BaseViewModelFactory
import poke.rogue.helper.presentation.base.error.ErrorHandleViewModel
import poke.rogue.helper.presentation.battle.model.SelectionData
import poke.rogue.helper.presentation.battle.model.SkillSelectionUiModel
Expand Down Expand Up @@ -79,7 +77,8 @@ class SkillSelectionViewModel(
previousPokemonDexNumber = pokemonDexNumber
viewModelScope.launch(errorHandler) {
_skills.value = emptyList()
val availableSkills = battleRepository.availableSkills(pokemonDexNumber).map { it.toUi() }
val availableSkills =
battleRepository.availableSkills(pokemonDexNumber).map { it.toUi() }
_skills.value = availableSkills.initialized()
}
}
Expand All @@ -99,11 +98,4 @@ class SkillSelectionViewModel(
searchQuery.emit(name)
}
}

companion object {
fun factory(
battleRepository: BattleRepository,
previousSelection: SelectionData.WithSkill?,
): ViewModelProvider.Factory = BaseViewModelFactory { SkillSelectionViewModel(battleRepository, previousSelection) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package poke.rogue.helper.presentation.type
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.widget.Toolbar
import org.koin.androidx.viewmodel.ext.android.viewModel
import poke.rogue.helper.R
import poke.rogue.helper.databinding.ActivityTypeBinding
import poke.rogue.helper.presentation.base.toolbar.ToolbarActivity
Expand All @@ -15,9 +15,7 @@ import poke.rogue.helper.presentation.type.selection.TypeSelectionBottomSheetFra
import poke.rogue.helper.presentation.util.repeatOnStarted

class TypeActivity : ToolbarActivity<ActivityTypeBinding>(R.layout.activity_type) {
private val viewModel: TypeViewModel by viewModels {
TypeViewModel.factory()
}
private val viewModel by viewModel<TypeViewModel>()
private val typeResultAdapter by lazy { TypeResultAdapter() }

override val toolbar: Toolbar
Expand Down Expand Up @@ -94,8 +92,6 @@ class TypeActivity : ToolbarActivity<ActivityTypeBinding>(R.layout.activity_type
}

companion object {
fun intent(context: Context): Intent {
return Intent(context, TypeActivity::class.java)
}
fun intent(context: Context): Intent = Intent(context, TypeActivity::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import poke.rogue.helper.data.datasource.LocalTypeDataSource
import poke.rogue.helper.data.repository.DefaultTypeRepository
import poke.rogue.helper.data.repository.TypeRepository
import poke.rogue.helper.presentation.base.BaseViewModelFactory
import poke.rogue.helper.presentation.type.model.MatchedTypesUiModel
import poke.rogue.helper.presentation.type.model.MatchedTypesUiModelComparator
import poke.rogue.helper.presentation.type.model.SelectorType
Expand Down Expand Up @@ -53,9 +50,10 @@ class TypeViewModel(
}.sortedWith(MatchedTypesUiModelComparator)
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000L), emptyList())

private fun matchedTypesAgainstOpponents(opponents: List<TypeSelectionUiState.Selected>): List<MatchedTypesUiModel> {
return opponents.flatMap { matchedTypesAgainstOpponent(it) }
}
private fun matchedTypesAgainstOpponents(opponents: List<TypeSelectionUiState.Selected>): List<MatchedTypesUiModel> =
opponents.flatMap {
matchedTypesAgainstOpponent(it)
}

private fun matchedTypesAgainstOpponent(opponent: TypeSelectionUiState.Selected): List<MatchedTypesUiModel> {
val selectedTypeId = opponent.selectedType.id
Expand Down Expand Up @@ -127,8 +125,4 @@ class TypeViewModel(
opponentType2 = TypeSelectionUiState.Empty,
)
}

companion object {
fun factory() = BaseViewModelFactory { TypeViewModel(DefaultTypeRepository(LocalTypeDataSource())) }
}
}
Loading
Loading