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

[AN-REFACTOR] 포켓몬 도감 데이터는 데이터 레이어에서 불러온다. #36

Merged
merged 37 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
563f163
chore: pokemon2 패키지 이름을 dex 로 변경한다
sh1mj1 Jul 17, 2024
a844f29
refactor: PokemonListFragment 에서 뷰모델을 BaseViewModelFactory 을 통해 생성한다
sh1mj1 Jul 17, 2024
82bd1a7
refactor: PokemonListFragment 어댑터를 lazy 하게 생성한다
sh1mj1 Jul 17, 2024
f459f0a
refactor: PokemonDetailFragment 에서 뷰모델을 BaseViewModelFactory 을 통해 생성한다
sh1mj1 Jul 17, 2024
48aac06
refactor: PokemonDetailFragment 의 어댑터를 lazy 하게 생성한다
sh1mj1 Jul 17, 2024
ae48877
feat(data/model/Type): 포켓몬 타입 원시값 포장, 캐싱한다
sh1mj1 Jul 17, 2024
9f2d5de
feat(data/model/Pokemon): 포켓몬 데이터
sh1mj1 Jul 17, 2024
0357661
feat: 포켓몬 목록을 in-memory 에서 불러온다
sh1mj1 Jul 17, 2024
3f1d6a3
feat(dex/model/PokemonUiModel): id, 이름, 이미지, 타입 목록을 가지는 ui model
sh1mj1 Jul 17, 2024
df11966
feat(TypeUiModel): 데이터 레이어의 타입으로부터 타입 ui 모델로 만든다
sh1mj1 Jul 17, 2024
d89bdfa
refactor: pokemonUiModel 을 모델 패키지의 것으로 교체한다
sh1mj1 Jul 17, 2024
d8f8f02
refactor: 포켓몬 목록 화면에서 데이터 레이어로부터 데이터를 가져온다
sh1mj1 Jul 17, 2024
dd9bc42
feat(data/model/Stat): 스탯 이름과 수치를 프로퍼티로 가진다
sh1mj1 Jul 18, 2024
be20db2
feat(presentation/.../StatUiModel): 스탯 이름, 수치, progress 를 프로퍼티로 가진다
sh1mj1 Jul 18, 2024
dd7820e
feat(presentation/.../PokemonUiModel): id, 도감번호, 이름, 이미지, 타입 목록을 가진다
sh1mj1 Jul 18, 2024
c96577a
feat(data/.../PokemonDetail): 포켓몬, 스탯 목록, 특성 목록, 키, 무게를 가진다
sh1mj1 Jul 18, 2024
69e8046
feat(presentation/.../PokemonDetailUiModel): 포켓몬 상세 정보 ui 모델을 가진다
sh1mj1 Jul 18, 2024
3a34b40
feat(PokemonDetailDataSource): 포켓몬 상세 정보를 가져온다
sh1mj1 Jul 18, 2024
265d4a8
refactor($PokemonDetail): 포켓몬 상세 페이지에서 ui 모델을 사용한다
sh1mj1 Jul 18, 2024
8f3c37d
refactor(PokemonDetailViewModel): 데이터 소스로부터 포켓몬 상세 정보를 불러온다
sh1mj1 Jul 18, 2024
77ebe4b
refactor(StatUiModel): 능력치 값의 limit 를 설정
sh1mj1 Jul 18, 2024
74b1248
refactor(item_stat.xml): 능력치 아이템의 텍스트 너비 조정
sh1mj1 Jul 18, 2024
72aa5fd
chore: 사용하지 않는 ui,데이터 모델 삭제
sh1mj1 Jul 18, 2024
38fa2a9
refactor(PokemonListFragment): 포켓몬 어댑터에 리스너 함수의 참조가 아닌 뷰모델을 넘긴다
sh1mj1 Jul 18, 2024
ab9777b
Merge branch 'an/develop' into an/refactor/dex_load_data_from_data_layer
sh1mj1 Jul 18, 2024
79cecea
refactor: 타입 이름을 한글로 설정한다
sh1mj1 Jul 18, 2024
4d87be4
chore(PokemonDetailViewModel): 로그 제거
sh1mj1 Jul 18, 2024
42ce099
refactor: data/model/Type 을 enum class 로 변경한다
sh1mj1 Jul 19, 2024
bf666c5
chore: 임시 포켓몬 리스트 데이터 소스 클래스 이름 변경
sh1mj1 Jul 19, 2024
5758312
chore: 임시 포켓몬 리스트 데이터 소스 인터페이스 제거
sh1mj1 Jul 19, 2024
0ee5fdc
feat: PokemonListRepository 인터페이스와 Fake 구현체를 만든다
sh1mj1 Jul 19, 2024
efa2011
refactor: 포켓몬 목록 뷰모델이 레포지토리로부터 포켓몬을 가져온다
sh1mj1 Jul 19, 2024
95f7d7a
chore: 임시 포켓몬 디테일 데이터 소스 클래스 이름 변경
sh1mj1 Jul 19, 2024
01f16b4
chore: 임시 포켓몬 상세 데이터 소스 인터페이스 제거
sh1mj1 Jul 19, 2024
b832591
feat: 포켓몬 상세 인터페이스와 Fake 구현체를 만든다
sh1mj1 Jul 19, 2024
c1ef63c
refactor: 포켓몬 상세 데이터 클래스에 있던 더미 데이터를 fake 데이터 소스로 이동
sh1mj1 Jul 19, 2024
9ac6345
refactor: 포켓몬 상세 뷰모델이 레포지토리로부터 포켓몬을 가져온다
sh1mj1 Jul 19, 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
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