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 26 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,7 @@
package poke.rogue.helper.data.datasource

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

class DummyPokemonDetailDataSource : PokemonDetailDataSource {
override fun pokemonDetail(id: Long): PokemonDetail = PokemonDetail.DUMMY
}
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 InMemoryPokemonListDataSource : PokemonListDataSource {
override 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.of("풀"), Type.of("독")),
),
Pokemon(
id = 2,
dexNumber = 2,
name = "이상해풀",
imageUrl = pokemonImageUrl(pokemonId = 2),
types = listOf(Type.of("풀"), Type.of("독")),
),
Pokemon(
id = 3,
dexNumber = 3,
name = "이상해꽃",
imageUrl = pokemonImageUrl(pokemonId = 3),
types = listOf(Type.of("풀"), Type.of("독")),
),
Pokemon(
id = 4,
dexNumber = 4,
name = "파이리",
imageUrl = pokemonImageUrl(pokemonId = 4),
types = listOf(Type.of("불꽃")),
),
Pokemon(
id = 5,
dexNumber = 5,
name = "리자드",
imageUrl = pokemonImageUrl(pokemonId = 5),
types = listOf(Type.of("불꽃")),
),
Pokemon(
id = 6,
dexNumber = 6,
name = "리자몽",
imageUrl = pokemonImageUrl(pokemonId = 6),
types = listOf(Type.of("불꽃"), Type.of("비행")),
),
Pokemon(
id = 7,
dexNumber = 7,
name = "꼬부기",
imageUrl = pokemonImageUrl(pokemonId = 7),
types = listOf(Type.of("물")),
),
Pokemon(
id = 8,
dexNumber = 8,
name = "어니부기",
imageUrl = pokemonImageUrl(pokemonId = 8),
types = listOf(Type.of("물")),
),
Pokemon(
id = 9,
dexNumber = 9,
name = "거북왕",
imageUrl = pokemonImageUrl(pokemonId = 9),
types = listOf(Type.of("물")),
),
Pokemon(
id = 10,
dexNumber = 10,
name = "캐터피",
imageUrl = pokemonImageUrl(pokemonId = 10),
types = listOf(Type.of("벌레")),
),
Pokemon(
id = 11,
dexNumber = 11,
name = "단데기",
imageUrl = pokemonImageUrl(pokemonId = 11),
types = listOf(Type.of("벌레")),
),
Pokemon(
id = 12,
dexNumber = 12,
name = "버터플",
imageUrl = pokemonImageUrl(pokemonId = 12),
types = listOf(Type.of("벌레"), Type.of("비행")),
),
Pokemon(
id = 13,
dexNumber = 13,
name = "뿔충이",
imageUrl = pokemonImageUrl(pokemonId = 13),
types = listOf(Type.of("벌레"), Type.of("독")),
),
Pokemon(
id = 14,
dexNumber = 14,
name = "딱충이",
imageUrl = pokemonImageUrl(pokemonId = 14),
types = listOf(Type.of("벌레"), Type.of("독")),
),
Pokemon(
id = 15,
dexNumber = 15,
name = "독침붕",
imageUrl = pokemonImageUrl(pokemonId = 15),
types = listOf(Type.of("벌레"), Type.of("독")),
),
Pokemon(
id = 16,
dexNumber = 16,
name = "구구",
imageUrl = pokemonImageUrl(pokemonId = 16),
types = listOf(Type.of("노말"), Type.of("비행")),
),
Pokemon(
id = 17,
dexNumber = 17,
name = "피죤",
imageUrl = pokemonImageUrl(pokemonId = 17),
types = listOf(Type.of("노말"), Type.of("비행")),
),
Pokemon(
id = 18,
dexNumber = 18,
name = "피죤투",
imageUrl = pokemonImageUrl(pokemonId = 18),
types = listOf(Type.of("노말"), Type.of("비행")),
),
Pokemon(
id = 19,
dexNumber = 19,
name = "꼬렛",
imageUrl = pokemonImageUrl(pokemonId = 19),
types = listOf(Type.of("노말")),
),
Pokemon(
id = 20,
dexNumber = 20,
name = "레트라",
imageUrl = pokemonImageUrl(pokemonId = 20),
types = listOf(Type.of("노말")),
),
Pokemon(
id = 21,
dexNumber = 21,
name = "깨비참",
imageUrl = pokemonImageUrl(pokemonId = 21),
types = listOf(Type.of("노말"), Type.of("비행")),
),
Pokemon(
id = 22,
dexNumber = 22,
name = "깨비드릴조",
imageUrl = pokemonImageUrl(pokemonId = 22),
types = listOf(Type.of("노말"), Type.of("비행")),
),
Pokemon(
id = 23,
dexNumber = 23,
name = "아보",
imageUrl = pokemonImageUrl(pokemonId = 23),
types = listOf(Type.of("독")),
),
Pokemon(
id = 24,
dexNumber = 24,
name = "아보크",
imageUrl = pokemonImageUrl(pokemonId = 24),
types = listOf(Type.of("독")),
),
Pokemon(
id = 25,
dexNumber = 25,
name = "피카츄",
imageUrl = pokemonImageUrl(pokemonId = 25),
types = listOf(Type.of("전기")),
),
Pokemon(
id = 26,
dexNumber = 26,
name = "라이츄",
imageUrl = pokemonImageUrl(pokemonId = 26),
types = listOf(Type.of("전기")),
),
Pokemon(
id = 27,
dexNumber = 27,
name = "모래두지",
imageUrl = pokemonImageUrl(pokemonId = 27),
types = listOf(Type.of("땅")),
),
Pokemon(
id = 28,
dexNumber = 28,
name = "고지",
imageUrl = pokemonImageUrl(pokemonId = 28),
types = listOf(Type.of("땅")),
),
Pokemon(
id = 29,
dexNumber = 29,
name = "니드런",
imageUrl = pokemonImageUrl(pokemonId = 29),
types = listOf(Type.of("독")),
),
Pokemon(
id = 30,
dexNumber = 30,
name = "니드리나",
imageUrl = pokemonImageUrl(pokemonId = 30),
types = listOf(Type.of("독")),
),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package poke.rogue.helper.data.datasource

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

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

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

interface PokemonListDataSource {
fun pokemons(): List<Pokemon>
}
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.of("풀"), Type.of("독"))

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,29 @@
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,
) {
companion object {
val DUMMY =
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,6 @@
package poke.rogue.helper.data.model

data class Stat(
val name: String,
val amount: Int,
)
30 changes: 30 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,30 @@
package poke.rogue.helper.data.model

@JvmInline
value class Type private constructor(val name: String) {
companion object {
private val TYPES: MutableMap<String, Type> =
mutableMapOf(
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Type 을 value class 로 wrapping 하신 것은 타입이 추가될 경우를 고려한 것인가요??
  2. TypeUiModel 처럼 Enum class 로 구현할 수 있을 것 같습니다. value class를 사용할 경우 name 에 잘못된 값이 들어가서 논리 오류가 발생 할지라도 Compile 시점에 검사할 방법이 없게됩니다 🥲

심지는 확장성을 더 중요하게 생각하는 걸까요?

Copy link
Contributor Author

@sh1mj1 sh1mj1 Jul 18, 2024

Choose a reason for hiding this comment

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

  1. 맞습니다.
    그리고 lv1 의 로또 미션 때처럼, 18 개의 객체만 미리 만들어두도록 캐싱하면 좋을 거라 생각했습니다.

  2. 이 부분은 생각하지 못한 부분이네요.
    enum class 로 구현하는 게 좋을 것 같네요.
    새 타입이 추가되는 시점은 새 세대의 닌텐도 게임이 추가되는 시점입니다.
    그래서 확장성보다 컴파일 시점에 검사할 수 있도록 하는 게 좋아보이네요.

예니 생각을 들어보고, 결론 내어서 수정하면 될 것 같아요

Copy link
Contributor

Choose a reason for hiding this comment

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

저도 enum class로 구현 좋은 것 같다는 생각입니다 🙃

"노말" to Type("노말"),
"불" to Type("불"),
"물" to Type("물"),
"전기" to Type("전기"),
"풀" to Type("풀"),
"얼음" to Type("얼음"),
"격투" to Type("격투"),
"독" to Type("독"),
"땅" to Type("땅"),
"비행" to Type("비행"),
"에스퍼" to Type("에스퍼"),
"벌레" to Type("벌레"),
"돌" to Type("돌"),
"고스트" to Type("고스트"),
"드래곤" to Type("드래곤"),
"악" to Type("악"),
"강철" to Type("강철"),
"페어리" to Type("페어리"),
)

fun of(name: String): Type = TYPES.getOrPut(name) { Type(name) }
}
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package poke.rogue.helper.presentation.ability.detail

import androidx.recyclerview.widget.RecyclerView
import poke.rogue.helper.databinding.ItemAbilityDetailPokemonBinding
import poke.rogue.helper.presentation.poketmon2.PokemonUiModel
import poke.rogue.helper.presentation.dex.PokemonUiModel

class AbilityDetailViewHolder(private val binding: ItemAbilityDetailPokemonBinding) :
RecyclerView.ViewHolder(binding.root) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package poke.rogue.helper.presentation.poketmon2
package poke.rogue.helper.presentation.dex

fun interface PokeMonItemClickListener {
fun onClickPokemon(pokemonId: Long)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package poke.rogue.helper.presentation.poketmon2
package poke.rogue.helper.presentation.dex

import android.content.Context
import android.content.Intent
Expand Down
Loading
Loading