-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
해당 PR 내용은 아니지만 CategoryUiModel를 sealed interface로 만들고 Expense와 Income에 대해 Enum 상수로 선언 한다면 조금 더 깔끔해지지 않을까 생각이 들었습니다.
entries로 접근할 수도 있고, 지출이냐 수입이냐에 따라 구분해 처리하기도 쉬워질 것 같습니다!
생각보다 여러 곳에서 사용해서 고려 정도만 해보셔도 좋을 것 같습니다~
sealed interface CategoryUiModel {
val stringResId: Int
val iconResId: Int
enum class Expense(
@StringRes override val stringResId: Int,
@DrawableRes override val iconResId: Int
) : CategoryUiModel {
Food(R.string.ledger_category_food, R.drawable.ic_ledger_category_food),
Transport(R.string.ledger_category_transport, R.drawable.ic_ledger_category_transport),
...
}
enum class Income(
@StringRes override val stringResId: Int,
@DrawableRes override val iconResId: Int
) : CategoryUiModel {
Salary(R.string.ledger_category_salary, R.drawable.ic_ledger_category_salary),
Bonus(R.string.ledger_category_bonus, R.drawable.ic_ledger_category_bonus),
...
}
// 필요하면 편의 함수
companion object {
fun entriesFor(type: LedgerTypeUiModel): List<CategoryUiModel> = when (type) {
LedgerTypeUiModel.Income -> Income.entries
LedgerTypeUiModel.Expense -> Expense.entries
}
val allEntries: List<CategoryUiModel> get() = Expense.entries + Income.entries
}
}Originally posted by @UiHyeon-Kim in #34 (comment)
Reactions are currently unavailable