Skip to content

Commit

Permalink
[AN-REFACTOR] 포켓몬 도감 데이터는 데이터 레이어에서 불러온다. (#36)
Browse files Browse the repository at this point in the history
* chore: pokemon2 패키지 이름을 dex 로 변경한다

* refactor: PokemonListFragment 에서 뷰모델을 BaseViewModelFactory 을 통해 생성한다

* refactor: PokemonListFragment 어댑터를 lazy 하게 생성한다

* refactor: PokemonDetailFragment 에서 뷰모델을 BaseViewModelFactory 을 통해 생성한다

* refactor: PokemonDetailFragment 의 어댑터를 lazy 하게 생성한다

* feat(data/model/Type): 포켓몬 타입 원시값 포장, 캐싱한다

- 캐싱을 통해 타입을 계속해서 생성하지 않아도 된다
- 추후에 타입이 추가되었을 때 서버 통신을 통해 TYPES 맵에 추가할 수 있도록 대응한다

* feat(data/model/Pokemon): 포켓몬 데이터

* feat: 포켓몬 목록을 in-memory 에서 불러온다

* feat(dex/model/PokemonUiModel): id, 이름, 이미지, 타입 목록을 가지는 ui model

* feat(TypeUiModel): 데이터 레이어의 타입으로부터 타입 ui 모델로 만든다

* refactor: pokemonUiModel 을 모델 패키지의 것으로 교체한다

* refactor: 포켓몬 목록 화면에서 데이터 레이어로부터 데이터를 가져온다

- Before: 뷰모델에서 ui model 의 더미 데이터를 가져온다
- After: 데이터 소스를 통해 더미 데이터를 가져온다

* feat(data/model/Stat): 스탯 이름과 수치를 프로퍼티로 가진다

* feat(presentation/.../StatUiModel): 스탯 이름, 수치, progress 를 프로퍼티로 가진다

* feat(presentation/.../PokemonUiModel): id, 도감번호, 이름, 이미지, 타입 목록을 가진다

* feat(data/.../PokemonDetail): 포켓몬, 스탯 목록, 특성 목록, 키, 무게를 가진다

* feat(presentation/.../PokemonDetailUiModel): 포켓몬 상세 정보 ui 모델을 가진다

* feat(PokemonDetailDataSource): 포켓몬 상세 정보를 가져온다

* refactor($PokemonDetail): 포켓몬 상세 페이지에서 ui 모델을 사용한다

- Before: 데이터 레이어에 있는 모델을 사용

- After: 프레젠테이션 레이어에 있는 모델을 사용

* refactor(PokemonDetailViewModel): 데이터 소스로부터 포켓몬 상세 정보를 불러온다

* refactor(StatUiModel): 능력치 값의 limit 를 설정

능력치 총합의 limit 와 단일 능력치의 limit 을 각각 설정한다

* refactor(item_stat.xml): 능력치 아이템의 텍스트 너비 조정

* chore: 사용하지 않는 ui,데이터 모델 삭제

* refactor(PokemonListFragment): 포켓몬 어댑터에 리스너 함수의 참조가 아닌 뷰모델을 넘긴다

* refactor: 타입 이름을 한글로 설정한다

* chore(PokemonDetailViewModel): 로그 제거

* refactor: data/model/Type 을 enum class 로 변경한다

* chore: 임시 포켓몬 리스트 데이터 소스 클래스 이름 변경

- InMemoryPokemonListDataSource -> FakePokemonListDataSource 로 이름 변경

* chore: 임시 포켓몬 리스트 데이터 소스 인터페이스 제거

* feat: PokemonListRepository 인터페이스와 Fake 구현체를 만든다

* refactor: 포켓몬 목록 뷰모델이 레포지토리로부터 포켓몬을 가져온다

- Before: 페이크 데이터 소스로부터 포켓몬를 가져온다
- After: 레포지토리 인터페이스로부터 포켓몬을 가져온다

* chore: 임시 포켓몬 디테일 데이터 소스 클래스 이름 변경

- DummyPokemonDetailDataSource -> FakePokemonDetailDataSource 로 이름 변경

* chore: 임시 포켓몬 상세 데이터 소스 인터페이스 제거

* feat: 포켓몬 상세 인터페이스와 Fake 구현체를 만든다

* refactor: 포켓몬 상세 데이터 클래스에 있던 더미 데이터를 fake 데이터 소스로 이동

- fake 포켓몬 상세 레포지토리가 fakepokemonDataSource 를 주 생성자로 가진다

* refactor: 포켓몬 상세 뷰모델이 레포지토리로부터 포켓몬을 가져온다

- Before: 페이크 데이터 소스로부터 포켓몬를 가져온다
- After: 레포지토리 인터페이스로부터 포켓몬을 가져온다
  • Loading branch information
sh1mj1 authored Jul 21, 2024
1 parent e4bdacd commit 797a78f
Show file tree
Hide file tree
Showing 40 changed files with 570 additions and 155 deletions.
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
android:theme="@style/Theme.PokeRogueHelper"
tools:targetApi="31">
<activity
android:name=".presentation.poketmon2.PokemonActivity"
android:name=".presentation.dex.PokemonActivity"
android:exported="true" />
<activity
android:name=".presentation.home.HomeActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package poke.rogue.helper.data.datasource

import poke.rogue.helper.data.model.Pokemon
import poke.rogue.helper.data.model.PokemonDetail
import poke.rogue.helper.data.model.Stat

class FakePokemonDetailDataSource {
fun pokemonDetail(id: Long): PokemonDetail = DUMMY_POKEMON_DETAIL

companion object {
val DUMMY_POKEMON_DETAIL =
PokemonDetail(
pokemon = Pokemon.DUMMY,
stats =
listOf(
Stat("HP", 45),
Stat("공격", 49),
Stat("방어", 49),
Stat("특수공격", 65),
Stat("특수방어", 65),
Stat("스피드", 45),
Stat("총합", 318),
),
abilities = listOf("그래스메이커", "심록", "엽록소"),
height = 0.7f,
weight = 6.9f,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
package poke.rogue.helper.data.datasource

import poke.rogue.helper.data.model.Pokemon
import poke.rogue.helper.data.model.Type

class FakePokemonListDataSource {
fun pokemons(): List<Pokemon> = POKEMONS

companion object {
private const val FORMAT_POKEMON_IMAGE_URL =
"https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other" +
"/official-artwork/"

private const val POSTFIX_PNG = ".png"

private fun pokemonImageUrl(pokemonId: Long) = FORMAT_POKEMON_IMAGE_URL + pokemonId + POSTFIX_PNG

private val POKEMONS: List<Pokemon> =
listOf(
Pokemon(
id = 1,
dexNumber = 1,
name = "이상해씨",
imageUrl = pokemonImageUrl(pokemonId = 1),
types = listOf(Type.GRASS, Type.POISON),
),
Pokemon(
id = 2,
dexNumber = 2,
name = "이상해풀",
imageUrl = pokemonImageUrl(pokemonId = 2),
types = listOf(Type.GRASS, Type.POISON),
),
Pokemon(
id = 3,
dexNumber = 3,
name = "이상해꽃",
imageUrl = pokemonImageUrl(pokemonId = 3),
types = listOf(Type.GRASS, Type.POISON),
),
Pokemon(
id = 4,
dexNumber = 4,
name = "파이리",
imageUrl = pokemonImageUrl(pokemonId = 4),
types = listOf(Type.FIRE),
),
Pokemon(
id = 5,
dexNumber = 5,
name = "리자드",
imageUrl = pokemonImageUrl(pokemonId = 5),
types = listOf(Type.FIRE),
),
Pokemon(
id = 6,
dexNumber = 6,
name = "리자몽",
imageUrl = pokemonImageUrl(pokemonId = 6),
types = listOf(Type.FIRE, Type.FLYING),
),
Pokemon(
id = 7,
dexNumber = 7,
name = "꼬부기",
imageUrl = pokemonImageUrl(pokemonId = 7),
types = listOf(Type.WATER),
),
Pokemon(
id = 8,
dexNumber = 8,
name = "어니부기",
imageUrl = pokemonImageUrl(pokemonId = 8),
types = listOf(Type.WATER),
),
Pokemon(
id = 9,
dexNumber = 9,
name = "거북왕",
imageUrl = pokemonImageUrl(pokemonId = 9),
types = listOf(Type.WATER),
),
Pokemon(
id = 10,
dexNumber = 10,
name = "캐터피",
imageUrl = pokemonImageUrl(pokemonId = 10),
types = listOf(Type.BUG),
),
Pokemon(
id = 11,
dexNumber = 11,
name = "단데기",
imageUrl = pokemonImageUrl(pokemonId = 11),
types = listOf(Type.BUG),
),
Pokemon(
id = 12,
dexNumber = 12,
name = "버터플",
imageUrl = pokemonImageUrl(pokemonId = 12),
types = listOf(Type.BUG, Type.FLYING),
),
Pokemon(
id = 13,
dexNumber = 13,
name = "뿔충이",
imageUrl = pokemonImageUrl(pokemonId = 13),
types = listOf(Type.BUG, Type.POISON),
),
Pokemon(
id = 14,
dexNumber = 14,
name = "딱충이",
imageUrl = pokemonImageUrl(pokemonId = 14),
types = listOf(Type.BUG, Type.POISON),
),
Pokemon(
id = 15,
dexNumber = 15,
name = "독침붕",
imageUrl = pokemonImageUrl(pokemonId = 15),
types = listOf(Type.BUG, Type.POISON),
),
Pokemon(
id = 16,
dexNumber = 16,
name = "구구",
imageUrl = pokemonImageUrl(pokemonId = 16),
types = listOf(Type.NORMAL, Type.FLYING),
),
Pokemon(
id = 17,
dexNumber = 17,
name = "피죤",
imageUrl = pokemonImageUrl(pokemonId = 17),
types = listOf(Type.NORMAL, Type.FLYING),
),
Pokemon(
id = 18,
dexNumber = 18,
name = "피죤투",
imageUrl = pokemonImageUrl(pokemonId = 18),
types = listOf(Type.NORMAL, Type.FLYING),
),
Pokemon(
id = 19,
dexNumber = 19,
name = "꼬렛",
imageUrl = pokemonImageUrl(pokemonId = 19),
types = listOf(Type.NORMAL),
),
Pokemon(
id = 20,
dexNumber = 20,
name = "레트라",
imageUrl = pokemonImageUrl(pokemonId = 20),
types = listOf(Type.NORMAL),
),
Pokemon(
id = 21,
dexNumber = 21,
name = "깨비참",
imageUrl = pokemonImageUrl(pokemonId = 21),
types = listOf(Type.NORMAL, Type.FLYING),
),
Pokemon(
id = 22,
dexNumber = 22,
name = "깨비드릴조",
imageUrl = pokemonImageUrl(pokemonId = 22),
types = listOf(Type.NORMAL, Type.FLYING),
),
Pokemon(
id = 23,
dexNumber = 23,
name = "아보",
imageUrl = pokemonImageUrl(pokemonId = 23),
types = listOf(Type.POISON),
),
Pokemon(
id = 24,
dexNumber = 24,
name = "아보크",
imageUrl = pokemonImageUrl(pokemonId = 24),
types = listOf(Type.POISON),
),
Pokemon(
id = 25,
dexNumber = 25,
name = "피카츄",
imageUrl = pokemonImageUrl(pokemonId = 25),
types = listOf(Type.ELECTRIC),
),
Pokemon(
id = 26,
dexNumber = 26,
name = "라이츄",
imageUrl = pokemonImageUrl(pokemonId = 26),
types = listOf(Type.ELECTRIC),
),
Pokemon(
id = 27,
dexNumber = 27,
name = "모래두지",
imageUrl = pokemonImageUrl(pokemonId = 27),
types = listOf(Type.GROUND),
),
Pokemon(
id = 28,
dexNumber = 28,
name = "고지",
imageUrl = pokemonImageUrl(pokemonId = 28),
types = listOf(Type.GROUND),
),
Pokemon(
id = 29,
dexNumber = 29,
name = "니드런",
imageUrl = pokemonImageUrl(pokemonId = 29),
types = listOf(Type.POISON),
),
Pokemon(
id = 30,
dexNumber = 30,
name = "니드리나",
imageUrl = pokemonImageUrl(pokemonId = 30),
types = listOf(Type.POISON),
),
)
}
}
25 changes: 25 additions & 0 deletions android/app/src/main/java/poke/rogue/helper/data/model/Pokemon.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package poke.rogue.helper.data.model

data class Pokemon(
val id: Long,
val dexNumber: Long,
val name: String,
val imageUrl: String,
val types: List<Type>,
) {
companion object {
private const val DUMMY_POKEMON_NAME = "이상해씨"
private const val DUMMY_IMAGE_URL =
"https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/1.png"
private val DUMMY_TYPES = listOf(Type.GRASS, Type.POISON)

val DUMMY =
Pokemon(
id = 1,
dexNumber = 1,
name = DUMMY_POKEMON_NAME,
imageUrl = DUMMY_IMAGE_URL,
types = DUMMY_TYPES,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package poke.rogue.helper.data.model

data class PokemonDetail(
val pokemon: Pokemon,
val stats: List<Stat>,
val abilities: List<String>,
val height: Float,
val weight: Float,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package poke.rogue.helper.data.model

data class Stat(
val name: String,
val amount: Int,
)
22 changes: 22 additions & 0 deletions android/app/src/main/java/poke/rogue/helper/data/model/Type.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package poke.rogue.helper.data.model

enum class Type {
NORMAL,
FIRE,
WATER,
ELECTRIC,
GRASS,
ICE,
FIGHTING,
POISON,
GROUND,
FLYING,
PSYCHIC,
BUG,
ROCK,
GHOST,
DRAGON,
DARK,
STEEL,
FAIRY,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package poke.rogue.helper.data.repository

import poke.rogue.helper.data.datasource.FakePokemonDetailDataSource
import poke.rogue.helper.data.model.PokemonDetail

class FakePokemonDetailRepository(
private val fakePokemonDetailDataSource: FakePokemonDetailDataSource,
) : PokemonDetailRepository {
override fun pokemonDetail(id: Long): PokemonDetail = fakePokemonDetailDataSource.pokemonDetail(id)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package poke.rogue.helper.data.repository

import poke.rogue.helper.data.datasource.FakePokemonListDataSource
import poke.rogue.helper.data.model.Pokemon

class FakePokemonListRepository(
private val pokemonListDataSource: FakePokemonListDataSource,
) : PokemonListRepository {
override fun pokemons(): List<Pokemon> = pokemonListDataSource.pokemons()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package poke.rogue.helper.data.repository

import poke.rogue.helper.data.model.PokemonDetail

interface PokemonDetailRepository {
fun pokemonDetail(id: Long): PokemonDetail
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package poke.rogue.helper.data.repository

import poke.rogue.helper.data.model.Pokemon

interface PokemonListRepository {
fun pokemons(): List<Pokemon>
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import poke.rogue.helper.R
import poke.rogue.helper.databinding.ActivityAbilityDetailBinding
import poke.rogue.helper.presentation.ability.AbilityUiModel
import poke.rogue.helper.presentation.base.BindingActivity
import poke.rogue.helper.presentation.poketmon2.PokemonUiModel
import poke.rogue.helper.presentation.dex.PokemonUiModel
import poke.rogue.helper.presentation.util.context.drawableOf
import poke.rogue.helper.presentation.util.context.stringOf
import poke.rogue.helper.presentation.util.context.toast
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.ListAdapter
import poke.rogue.helper.databinding.ItemAbilityDetailPokemonBinding
import poke.rogue.helper.presentation.poketmon2.PokemonUiModel
import poke.rogue.helper.presentation.dex.PokemonUiModel
import poke.rogue.helper.presentation.util.view.ItemDiffCallback

class AbilityDetailAdapter :
Expand Down
Loading

0 comments on commit 797a78f

Please sign in to comment.