Skip to content

Commit f6df1df

Browse files
committed
Refactor: RecommendCategory enum 직렬화 및 관련 로직 변경
1 parent fc35108 commit f6df1df

8 files changed

Lines changed: 78 additions & 63 deletions

File tree

data/src/main/java/com/threegap/bitnagil/data/recommendroutine/model/response/RecommendRoutinesDto.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import kotlinx.serialization.Serializable
99
@Serializable
1010
data class RecommendRoutinesDto(
1111
@SerialName("recommendedRoutines")
12-
val recommendedRoutinesByCategory: Map<String, List<RecommendedRoutineDto>>,
12+
val recommendedRoutinesByCategory: Map<RecommendCategory, List<RecommendedRoutineDto>>,
1313
@SerialName("emotionMarbleType")
1414
val emotionMarbleType: EmotionMarbleType?,
1515
)
1616

1717
fun RecommendRoutinesDto.toDomain(): RecommendRoutines =
1818
RecommendRoutines(
19-
recommendRoutinesByCategory = this.recommendedRoutinesByCategory.map { (categoryString, routines) ->
20-
RecommendCategory.fromString(categoryString) to routines.map { it.toDomain() }
19+
recommendRoutinesByCategory = this.recommendedRoutinesByCategory.map { (category, routines) ->
20+
category to routines.map { it.toDomain() }
2121
}.toMap(),
2222
emotionMarbleType = this.emotionMarbleType,
2323
)

data/src/main/java/com/threegap/bitnagil/data/recommendroutine/model/response/RecommendedRoutineDto.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ data class RecommendedRoutineDto(
1919
@SerialName("executionTime")
2020
val executionTime: String,
2121
@SerialName("recommendedRoutineType")
22-
val recommendedRoutineType: String,
22+
val recommendedRoutineType: RecommendCategory,
2323
@SerialName("recommendedSubRoutineSearchResult")
2424
val recommendedSubRoutineSearchResult: List<RecommendedSubRoutineDto>,
2525
)
@@ -31,6 +31,6 @@ fun RecommendedRoutineDto.toDomain(): RecommendRoutine =
3131
description = this.recommendedRoutineDescription,
3232
level = this.recommendedRoutineLevel,
3333
executionTime = this.executionTime,
34-
recommendedRoutineType = RecommendCategory.fromString(recommendedRoutineType),
34+
recommendedRoutineType = this.recommendedRoutineType,
3535
recommendSubRoutines = this.recommendedSubRoutineSearchResult.map { it.toDomain() },
3636
)
Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
package com.threegap.bitnagil.domain.recommendroutine.model
22

3-
enum class RecommendCategory(
4-
val categoryName: String,
5-
val displayName: String,
6-
val isVisible: Boolean = true,
7-
) {
8-
PERSONALIZED("PERSONALIZED", "맞춤 추천"),
9-
OUTING("OUTING", "나가봐요"),
10-
WAKE_UP("WAKE_UP", "일어나요"),
11-
CONNECT("CONNECT", "연결해요"),
12-
REST("REST", "쉬어가요"),
13-
GROW("GROW", "성장해요"),
14-
OUTING_REPORT("OUTING_REPORT", "신고", isVisible = false),
15-
UNKNOWN("UNKNOWN", "알 수 없음", isVisible = false),
16-
;
3+
import kotlinx.serialization.Serializable
174

18-
companion object {
19-
fun fromString(categoryName: String): RecommendCategory =
20-
entries.find { it.categoryName == categoryName } ?: UNKNOWN
21-
}
5+
@Serializable
6+
enum class RecommendCategory {
7+
PERSONALIZED,
8+
OUTING,
9+
WAKE_UP,
10+
CONNECT,
11+
REST,
12+
GROW,
13+
OUTING_REPORT,
14+
UNKNOWN,
15+
;
2216
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.threegap.bitnagil.presentation.common.extension
2+
3+
import androidx.annotation.DrawableRes
4+
import androidx.compose.runtime.Composable
5+
import androidx.compose.ui.graphics.Color
6+
import com.threegap.bitnagil.designsystem.BitnagilTheme
7+
import com.threegap.bitnagil.designsystem.R
8+
import com.threegap.bitnagil.domain.recommendroutine.model.RecommendCategory
9+
10+
val RecommendCategory.displayColor: Color
11+
@Composable get() = when (this) {
12+
RecommendCategory.OUTING -> BitnagilTheme.colors.skyBlue10
13+
RecommendCategory.WAKE_UP -> BitnagilTheme.colors.orange25
14+
RecommendCategory.CONNECT -> BitnagilTheme.colors.purple10
15+
RecommendCategory.REST -> BitnagilTheme.colors.green10
16+
RecommendCategory.GROW -> BitnagilTheme.colors.pink10
17+
RecommendCategory.PERSONALIZED -> BitnagilTheme.colors.yellow10
18+
RecommendCategory.OUTING_REPORT -> BitnagilTheme.colors.yellow10
19+
RecommendCategory.UNKNOWN -> BitnagilTheme.colors.yellow10
20+
}
21+
22+
val RecommendCategory.displayIcon: Int
23+
@DrawableRes get() = when (this) {
24+
RecommendCategory.OUTING -> R.drawable.ic_outside
25+
RecommendCategory.WAKE_UP -> R.drawable.ic_wakeup
26+
RecommendCategory.CONNECT -> R.drawable.ic_connect
27+
RecommendCategory.REST -> R.drawable.ic_rest
28+
RecommendCategory.GROW -> R.drawable.ic_grow
29+
RecommendCategory.PERSONALIZED -> R.drawable.ic_shine
30+
RecommendCategory.OUTING_REPORT -> R.drawable.ic_shine
31+
RecommendCategory.UNKNOWN -> R.drawable.ic_shine
32+
}
33+
34+
val RecommendCategory.displayTitle: String
35+
get() = when (this) {
36+
RecommendCategory.PERSONALIZED -> "맞춤 추천"
37+
RecommendCategory.OUTING -> "나가봐요"
38+
RecommendCategory.WAKE_UP -> "일어나요"
39+
RecommendCategory.CONNECT -> "연결해요"
40+
RecommendCategory.REST -> "쉬어가요"
41+
RecommendCategory.GROW -> "성장해요"
42+
RecommendCategory.OUTING_REPORT -> "신고"
43+
RecommendCategory.UNKNOWN -> "알 수 없음"
44+
}
45+
46+
val RecommendCategory.isVisible: Boolean
47+
get() = when (this) {
48+
RecommendCategory.OUTING_REPORT -> false
49+
RecommendCategory.UNKNOWN -> false
50+
else -> true
51+
}

presentation/src/main/java/com/threegap/bitnagil/presentation/recommendroutine/RecommendRoutineScreen.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import com.threegap.bitnagil.designsystem.component.block.BitnagilTopBar
3333
import com.threegap.bitnagil.designsystem.modifier.clickableWithoutRipple
3434
import com.threegap.bitnagil.domain.recommendroutine.model.RecommendCategory
3535
import com.threegap.bitnagil.presentation.common.extension.displayLevel
36+
import com.threegap.bitnagil.presentation.common.extension.displayTitle
37+
import com.threegap.bitnagil.presentation.common.extension.isVisible
3638
import com.threegap.bitnagil.presentation.recommendroutine.component.atom.RecommendCategoryChip
3739
import com.threegap.bitnagil.presentation.recommendroutine.component.block.EmotionRecommendRoutineButton
3840
import com.threegap.bitnagil.presentation.recommendroutine.component.block.RecommendRoutineItem
@@ -110,7 +112,7 @@ private fun RecommendRoutineScreen(
110112
key = { it.name },
111113
) { category ->
112114
RecommendCategoryChip(
113-
categoryName = category.displayName,
115+
categoryName = category.displayTitle,
114116
isSelected = uiState.selectedCategory == category,
115117
onCategorySelected = {
116118
onCategorySelected(category)

presentation/src/main/java/com/threegap/bitnagil/presentation/recommendroutine/component/block/RecommendRoutineItem.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import com.threegap.bitnagil.designsystem.component.atom.BitnagilIcon
2222
import com.threegap.bitnagil.designsystem.modifier.clickableWithoutRipple
2323
import com.threegap.bitnagil.domain.recommendroutine.model.RecommendCategory
2424
import com.threegap.bitnagil.domain.recommendroutine.model.RecommendLevel
25+
import com.threegap.bitnagil.presentation.common.extension.displayColor
26+
import com.threegap.bitnagil.presentation.common.extension.displayIcon
2527
import com.threegap.bitnagil.presentation.recommendroutine.model.RecommendRoutineUiModel
2628
import com.threegap.bitnagil.presentation.recommendroutine.model.RecommendSubRoutineUiModel
2729

@@ -47,11 +49,11 @@ fun RecommendRoutineItem(
4749
verticalAlignment = Alignment.CenterVertically,
4850
) {
4951
BitnagilIcon(
50-
id = routine.icon,
52+
id = routine.recommendedRoutineType?.displayIcon ?: R.drawable.ic_shine,
5153
tint = null,
5254
modifier = Modifier
5355
.background(
54-
color = routine.color,
56+
color = routine.recommendedRoutineType?.displayColor ?: BitnagilTheme.colors.yellow10,
5557
shape = RoundedCornerShape(4.dp),
5658
)
5759
.padding(4.dp),
Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package com.threegap.bitnagil.presentation.recommendroutine.model
22

33
import android.os.Parcelable
4-
import androidx.compose.runtime.Composable
5-
import androidx.compose.ui.graphics.Color
6-
import com.threegap.bitnagil.designsystem.BitnagilTheme
7-
import com.threegap.bitnagil.designsystem.R
84
import com.threegap.bitnagil.domain.recommendroutine.model.RecommendCategory
95
import com.threegap.bitnagil.domain.recommendroutine.model.RecommendLevel
106
import com.threegap.bitnagil.domain.recommendroutine.model.RecommendRoutine
@@ -17,13 +13,7 @@ data class RecommendRoutineUiModel(
1713
val level: RecommendLevel? = null,
1814
val recommendedRoutineType: RecommendCategory? = null,
1915
val recommendSubRoutines: List<RecommendSubRoutineUiModel> = emptyList(),
20-
) : Parcelable {
21-
val icon: Int
22-
get() = recommendedRoutineType?.getIcon() ?: R.drawable.ic_shine
23-
24-
val color: Color
25-
@Composable get() = recommendedRoutineType?.getColor() ?: BitnagilTheme.colors.yellow10
26-
}
16+
) : Parcelable
2717

2818
fun RecommendRoutine.toUiModel() =
2919
RecommendRoutineUiModel(
@@ -33,28 +23,3 @@ fun RecommendRoutine.toUiModel() =
3323
recommendedRoutineType = this.recommendedRoutineType,
3424
recommendSubRoutines = this.recommendSubRoutines.map { it.toUiModel() },
3525
)
36-
37-
private fun RecommendCategory.getIcon(): Int =
38-
when (this) {
39-
RecommendCategory.OUTING -> R.drawable.ic_outside
40-
RecommendCategory.WAKE_UP -> R.drawable.ic_wakeup
41-
RecommendCategory.CONNECT -> R.drawable.ic_connect
42-
RecommendCategory.REST -> R.drawable.ic_rest
43-
RecommendCategory.GROW -> R.drawable.ic_grow
44-
RecommendCategory.PERSONALIZED -> R.drawable.ic_shine
45-
RecommendCategory.OUTING_REPORT -> R.drawable.ic_shine
46-
RecommendCategory.UNKNOWN -> R.drawable.ic_shine
47-
}
48-
49-
@Composable
50-
private fun RecommendCategory.getColor(): Color =
51-
when (this) {
52-
RecommendCategory.OUTING -> BitnagilTheme.colors.skyBlue10
53-
RecommendCategory.WAKE_UP -> BitnagilTheme.colors.orange25
54-
RecommendCategory.CONNECT -> BitnagilTheme.colors.purple10
55-
RecommendCategory.REST -> BitnagilTheme.colors.green10
56-
RecommendCategory.GROW -> BitnagilTheme.colors.pink10
57-
RecommendCategory.PERSONALIZED -> BitnagilTheme.colors.yellow10
58-
RecommendCategory.OUTING_REPORT -> BitnagilTheme.colors.yellow10
59-
RecommendCategory.UNKNOWN -> BitnagilTheme.colors.yellow10
60-
}

presentation/src/main/java/com/threegap/bitnagil/presentation/writeroutine/WriteRoutineViewModel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.threegap.bitnagil.domain.writeroutine.model.RepeatDay
88
import com.threegap.bitnagil.domain.writeroutine.model.RoutineUpdateType
99
import com.threegap.bitnagil.domain.writeroutine.usecase.EditRoutineUseCase
1010
import com.threegap.bitnagil.domain.writeroutine.usecase.RegisterRoutineUseCase
11+
import com.threegap.bitnagil.presentation.common.extension.displayTitle
1112
import com.threegap.bitnagil.presentation.writeroutine.model.Date
1213
import com.threegap.bitnagil.presentation.writeroutine.model.Day
1314
import com.threegap.bitnagil.presentation.writeroutine.model.RepeatType
@@ -146,7 +147,7 @@ class WriteRoutineViewModel @AssistedInject constructor(
146147
oldSubRoutines.getOrNull(2)?.name ?: "",
147148
),
148149
loading = false,
149-
recommendedRoutineType = routine.recommendedRoutineType.categoryName,
150+
recommendedRoutineType = routine.recommendedRoutineType.displayTitle,
150151
)
151152
}
152153
},

0 commit comments

Comments
 (0)