-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AN-REFACTOR] 포켓몬 도감 데이터는 데이터 레이어에서 불러온다. (#36)
* 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
Showing
40 changed files
with
570 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
android/app/src/main/java/poke/rogue/helper/data/datasource/FakePokemonDetailDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} | ||
} |
232 changes: 232 additions & 0 deletions
232
android/app/src/main/java/poke/rogue/helper/data/datasource/FakePokemonListDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
25
android/app/src/main/java/poke/rogue/helper/data/model/Pokemon.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
android/app/src/main/java/poke/rogue/helper/data/model/PokemonDetail.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
6 changes: 6 additions & 0 deletions
6
android/app/src/main/java/poke/rogue/helper/data/model/Stat.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
22
android/app/src/main/java/poke/rogue/helper/data/model/Type.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
10 changes: 10 additions & 0 deletions
10
android/app/src/main/java/poke/rogue/helper/data/repository/FakePokemonDetailRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
10 changes: 10 additions & 0 deletions
10
android/app/src/main/java/poke/rogue/helper/data/repository/FakePokemonListRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
7 changes: 7 additions & 0 deletions
7
android/app/src/main/java/poke/rogue/helper/data/repository/PokemonDetailRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
7 changes: 7 additions & 0 deletions
7
android/app/src/main/java/poke/rogue/helper/data/repository/PokemonListRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.