Skip to content

Commit 595254e

Browse files
committed
Refactor: Emotion 관련 UiModel 매핑 로직 변경
- Domain Model을 UiModel로 변환하는 로직을 각 UiModel의 companion object에서 확장 함수(toUiModel)로 변경합니다.
1 parent df2095d commit 595254e

3 files changed

Lines changed: 33 additions & 32 deletions

File tree

presentation/src/main/java/com/threegap/bitnagil/presentation/emotion/EmotionViewModel.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.threegap.bitnagil.presentation.emotion.contract.EmotionState
1111
import com.threegap.bitnagil.presentation.emotion.model.EmotionRecommendRoutineUiModel
1212
import com.threegap.bitnagil.presentation.emotion.model.EmotionScreenStep
1313
import com.threegap.bitnagil.presentation.emotion.model.EmotionUiModel
14+
import com.threegap.bitnagil.presentation.emotion.model.toUiModel
1415
import dagger.hilt.android.lifecycle.HiltViewModel
1516
import kotlinx.coroutines.delay
1617
import kotlinx.coroutines.launch
@@ -39,7 +40,7 @@ class EmotionViewModel @Inject constructor(
3940
onSuccess = { emotions ->
4041
reduce {
4142
state.copy(
42-
emotionTypeUiModels = emotions.map { EmotionUiModel.fromDomain(it) },
43+
emotionTypeUiModels = emotions.map { it.toUiModel() },
4344
isLoading = false,
4445
)
4546
}
@@ -69,7 +70,7 @@ class EmotionViewModel @Inject constructor(
6970

7071
registerEmotionUseCase(emotionType = emotionType).fold(
7172
onSuccess = { emotionRecommendRoutines ->
72-
val recommendRoutines = emotionRecommendRoutines.map { EmotionRecommendRoutineUiModel.fromEmotionRecommendRoutine(it) }
73+
val recommendRoutines = emotionRecommendRoutines.map { it.toUiModel() }
7374
reduce {
7475
state.copy(
7576
recommendRoutines = recommendRoutines,

presentation/src/main/java/com/threegap/bitnagil/presentation/emotion/model/EmotionRecommendRoutineUiModel.kt

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,12 @@ data class EmotionRecommendRoutineUiModel(
1010
val name: String,
1111
val description: String,
1212
val selected: Boolean,
13-
) : Parcelable {
14-
companion object {
15-
fun fromEmotionRecommendRoutine(
16-
emotionRecommendRoutine: EmotionRecommendRoutine,
17-
): EmotionRecommendRoutineUiModel {
18-
return EmotionRecommendRoutineUiModel(
19-
id = emotionRecommendRoutine.routineId,
20-
name = emotionRecommendRoutine.routineName,
21-
description = emotionRecommendRoutine.routineDescription,
22-
selected = false,
23-
)
24-
}
25-
}
26-
}
13+
) : Parcelable
14+
15+
internal fun EmotionRecommendRoutine.toUiModel(): EmotionRecommendRoutineUiModel =
16+
EmotionRecommendRoutineUiModel(
17+
id = this.routineId,
18+
name = this.routineName,
19+
description = this.routineDescription,
20+
selected = false,
21+
)

presentation/src/main/java/com/threegap/bitnagil/presentation/emotion/model/EmotionUiModel.kt

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ package com.threegap.bitnagil.presentation.emotion.model
33
import android.os.Parcelable
44
import com.threegap.bitnagil.designsystem.R
55
import com.threegap.bitnagil.domain.emotion.model.Emotion
6+
import com.threegap.bitnagil.presentation.emotion.model.EmotionUiModel.Companion.getMessage
7+
import com.threegap.bitnagil.presentation.emotion.model.EmotionUiModel.Companion.getOfflineBackupImageResourceId
8+
import com.threegap.bitnagil.presentation.emotion.model.EmotionUiModel.Companion.getSymbolBackgroundColor
9+
import com.threegap.bitnagil.presentation.emotion.model.EmotionUiModel.Companion.getSymbolColor
610
import kotlinx.parcelize.Parcelize
711

812
@Parcelize
@@ -16,19 +20,7 @@ data class EmotionUiModel(
1620
val symbolColor: Long = 0xFF878A93,
1721
) : Parcelable {
1822
companion object {
19-
fun fromDomain(emotion: Emotion) = EmotionUiModel(
20-
emotionType = emotion.emotionType,
21-
emotionMarbleName = emotion.emotionMarbleName,
22-
image = EmotionImageUiModel.Url(
23-
url = emotion.imageUrl,
24-
offlineBackupImageResourceId = getOfflineBackupImageResourceId(emotion.emotionType),
25-
),
26-
message = getMessage(emotion.emotionType),
27-
symbolBackgroundColor = getSymbolBackgroundColor(emotion.emotionType),
28-
symbolColor = getSymbolColor(emotion.emotionType),
29-
)
30-
31-
private fun getOfflineBackupImageResourceId(emotionType: String): Int? {
23+
fun getOfflineBackupImageResourceId(emotionType: String): Int? {
3224
return when (emotionType) {
3325
"CALM" -> R.drawable.calm
3426
"VITALITY" -> R.drawable.vitality
@@ -40,7 +32,7 @@ data class EmotionUiModel(
4032
}
4133
}
4234

43-
private fun getMessage(emotionType: String): String? {
35+
fun getMessage(emotionType: String): String? {
4436
return when (emotionType) {
4537
"CALM" -> "평온함은 마음이 고요하고 편안해\n균형을 이루는 상태에요."
4638
"VITALITY" -> "활기참은 생기가 가득 차\n활발하고 적극적인 상태예요."
@@ -52,7 +44,7 @@ data class EmotionUiModel(
5244
}
5345
}
5446

55-
private fun getSymbolBackgroundColor(emotionType: String): Long {
47+
fun getSymbolBackgroundColor(emotionType: String): Long {
5648
return when (emotionType) {
5749
"CALM" -> 0xFFEFECFF
5850
"VITALITY" -> 0xFFE9FAD0
@@ -64,7 +56,7 @@ data class EmotionUiModel(
6456
}
6557
}
6658

67-
private fun getSymbolColor(emotionType: String): Long {
59+
fun getSymbolColor(emotionType: String): Long {
6860
return when (emotionType) {
6961
"CALM" -> 0xFF692BD0
7062
"VITALITY" -> 0xFF609F00
@@ -87,3 +79,16 @@ data class EmotionUiModel(
8779
)
8880
}
8981
}
82+
83+
internal fun Emotion.toUiModel(): EmotionUiModel =
84+
EmotionUiModel(
85+
emotionType = this.emotionType,
86+
emotionMarbleName = this.emotionMarbleName,
87+
image = EmotionImageUiModel.Url(
88+
url = this.imageUrl,
89+
offlineBackupImageResourceId = getOfflineBackupImageResourceId(this.emotionType),
90+
),
91+
message = getMessage(this.emotionType),
92+
symbolBackgroundColor = getSymbolBackgroundColor(this.emotionType),
93+
symbolColor = getSymbolColor(this.emotionType),
94+
)

0 commit comments

Comments
 (0)