Skip to content

Commit a278f6a

Browse files
committed
[BOOK-490] refactor: EmotionModel, EmotionCode -> EmotionCode로 통일
각 Emotion 네이밍 warmth, joy, sadness, insight, other로 통일(리소스 네이밍 수정)
1 parent d89ed4b commit a278f6a

16 files changed

Lines changed: 57 additions & 84 deletions

File tree

core/designsystem/src/main/kotlin/com/ninecraft/booket/core/designsystem/Emotion.kt renamed to core/designsystem/src/main/kotlin/com/ninecraft/booket/core/designsystem/EmotionCode.kt

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package com.ninecraft.booket.core.designsystem
22

33
import androidx.compose.ui.graphics.Color
44
import com.ninecraft.booket.core.designsystem.theme.Blue300
5-
import com.ninecraft.booket.core.designsystem.theme.EtcBgColor
6-
import com.ninecraft.booket.core.designsystem.theme.EtcTextColor
5+
import com.ninecraft.booket.core.designsystem.theme.OtherBgColor
6+
import com.ninecraft.booket.core.designsystem.theme.OtherTextColor
77
import com.ninecraft.booket.core.designsystem.theme.InsightBgColor
88
import com.ninecraft.booket.core.designsystem.theme.InsightTextColor
99
import com.ninecraft.booket.core.designsystem.theme.JoyBgColor
@@ -16,34 +16,33 @@ import com.ninecraft.booket.core.designsystem.theme.Violet300
1616
import com.ninecraft.booket.core.designsystem.theme.WarmthBgColor
1717
import com.ninecraft.booket.core.designsystem.theme.WarmthTextColor
1818
import com.ninecraft.booket.core.designsystem.theme.Yellow300
19-
import com.ninecraft.booket.core.model.Emotion
2019
import com.ninecraft.booket.core.model.EmotionCode
2120

22-
val Emotion.bgColor: Color
21+
val EmotionCode.bgColor: Color
2322
get() = when (this) {
24-
Emotion.WARM -> WarmthBgColor
25-
Emotion.JOY -> JoyBgColor
26-
Emotion.SAD -> SadnessBgColor
27-
Emotion.INSIGHT -> InsightBgColor
28-
Emotion.ETC -> EtcBgColor
23+
EmotionCode.WARMTH -> WarmthBgColor
24+
EmotionCode.JOY -> JoyBgColor
25+
EmotionCode.SADNESS -> SadnessBgColor
26+
EmotionCode.INSIGHT -> InsightBgColor
27+
EmotionCode.OTHER -> OtherBgColor
2928
}
3029

31-
val Emotion.textColor: Color
30+
val EmotionCode.textColor: Color
3231
get() = when (this) {
33-
Emotion.WARM -> WarmthTextColor
34-
Emotion.JOY -> JoyTextColor
35-
Emotion.SAD -> SadnessTextColor
36-
Emotion.INSIGHT -> InsightTextColor
37-
Emotion.ETC -> EtcTextColor
32+
EmotionCode.WARMTH -> WarmthTextColor
33+
EmotionCode.JOY -> JoyTextColor
34+
EmotionCode.SADNESS -> SadnessTextColor
35+
EmotionCode.INSIGHT -> InsightTextColor
36+
EmotionCode.OTHER -> OtherTextColor
3837
}
3938

40-
val Emotion.ratioBarColor: Color
39+
val EmotionCode.ratioBarColor: Color
4140
get() = when (this) {
42-
Emotion.WARM -> Yellow300
43-
Emotion.JOY -> Orange300
44-
Emotion.SAD -> Blue300
45-
Emotion.INSIGHT -> Violet300
46-
Emotion.ETC -> Neutral300
41+
EmotionCode.WARMTH -> Yellow300
42+
EmotionCode.JOY -> Orange300
43+
EmotionCode.SADNESS -> Blue300
44+
EmotionCode.INSIGHT -> Violet300
45+
EmotionCode.OTHER -> Neutral300
4746
}
4847

4948
val EmotionCode.graphicRes: Int

core/designsystem/src/main/kotlin/com/ninecraft/booket/core/designsystem/theme/Color.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ val InsightTextColor = Color(0xFF9A55E4)
9898
val InsightBgColor = Color(0xFFF3E8FF)
9999
val SadnessTextColor = Color(0xFF2872E9)
100100
val SadnessBgColor = Color(0xFFE1ECFF)
101-
val EtcTextColor = Color(0xFF737373)
102-
val EtcBgColor = Color(0xFFF5F5F5)
101+
val OtherTextColor = Color(0xFF737373)
102+
val OtherBgColor = Color(0xFFF5F5F5)
103103

104104
@Immutable
105105
data class ReedColorScheme(

core/model/src/main/kotlin/com/ninecraft/booket/core/model/EmotionModel.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,23 @@ data class DetailEmotionModel(
2020
val name: String,
2121
)
2222

23-
enum class EmotionCode {
24-
WARMTH, JOY, SADNESS, INSIGHT, OTHER;
23+
enum class EmotionCode(
24+
val displayName: String,
25+
) {
26+
WARMTH("따뜻함"),
27+
JOY("즐거움"),
28+
SADNESS("슬픔"),
29+
INSIGHT("깨달음"),
30+
OTHER("기타"),
31+
;
2532

2633
companion object {
2734
fun fromCode(code: String): EmotionCode? {
2835
return EmotionCode.entries.find { it.name == code }
2936
}
37+
38+
fun fromDisplayName(displayName: String): EmotionCode? {
39+
return entries.find { it.displayName == displayName }
40+
}
3041
}
3142
}

core/model/src/main/kotlin/com/ninecraft/booket/core/model/SeedModel.kt

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,6 @@ data class SeedModel(
99

1010
@Stable
1111
data class EmotionModel(
12-
val name: Emotion,
12+
val code: EmotionCode,
1313
val count: Int,
1414
)
15-
16-
enum class Emotion(
17-
val displayName: String,
18-
) {
19-
WARM("따뜻함"),
20-
JOY("즐거움"),
21-
SAD("슬픔"),
22-
INSIGHT("깨달음"),
23-
ETC("기타"),
24-
;
25-
26-
companion object {
27-
fun fromDisplayName(displayName: String): Emotion? {
28-
return entries.find { it.displayName == displayName }
29-
}
30-
}
31-
}

feature/detail/src/main/kotlin/com/ninecraft/booket/feature/detail/book/BookDetailUi.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import com.ninecraft.booket.core.designsystem.component.button.ReedButtonColorSt
3636
import com.ninecraft.booket.core.designsystem.component.button.mediumButtonStyle
3737
import com.ninecraft.booket.core.designsystem.theme.ReedTheme
3838
import com.ninecraft.booket.core.model.BookDetailModel
39-
import com.ninecraft.booket.core.model.Emotion
39+
import com.ninecraft.booket.core.model.EmotionCode
4040
import com.ninecraft.booket.core.model.EmotionModel
4141
import com.ninecraft.booket.core.model.PrimaryEmotionModel
4242
import com.ninecraft.booket.core.model.ReadingRecordModel
@@ -286,6 +286,7 @@ internal fun BookDetailContent(
286286
if (state.hasEmotionData()) {
287287
CollectedSeeds(
288288
seedsStats = state.seedsStats,
289+
representativeEmotion = state.representativeEmotion,
289290
isStatsExpanded = state.isStatsExpanded,
290291
onToggleClick = {
291292
state.eventSink(BookDetailUiEvent.OnStatsToggleClick(!state.isStatsExpanded))
@@ -408,10 +409,10 @@ private fun BookDetailSeedStatsPreview() {
408409
coverImageUrl = "",
409410
),
410411
seedsStats = persistentListOf(
411-
EmotionModel(name = Emotion.WARM, count = 5),
412-
EmotionModel(name = Emotion.JOY, count = 3),
413-
EmotionModel(name = Emotion.SAD, count = 2),
414-
EmotionModel(name = Emotion.INSIGHT, count = 7),
412+
EmotionModel(code = EmotionCode.WARMTH, count = 5),
413+
EmotionModel(code = EmotionCode.JOY, count = 3),
414+
EmotionModel(code = EmotionCode.SADNESS, count = 2),
415+
EmotionModel(code = EmotionCode.INSIGHT, count = 7),
415416
),
416417
readingRecords = persistentListOf(
417418
ReadingRecordModel(
@@ -461,10 +462,10 @@ private fun BookDetailSeedsStatsExpandedPreview() {
461462
coverImageUrl = "",
462463
),
463464
seedsStats = persistentListOf(
464-
EmotionModel(name = Emotion.WARM, count = 5),
465-
EmotionModel(name = Emotion.JOY, count = 3),
466-
EmotionModel(name = Emotion.SAD, count = 2),
467-
EmotionModel(name = Emotion.INSIGHT, count = 7),
465+
EmotionModel(code = EmotionCode.WARMTH, count = 5),
466+
EmotionModel(code = EmotionCode.JOY, count = 3),
467+
EmotionModel(code = EmotionCode.SADNESS, count = 2),
468+
EmotionModel(code = EmotionCode.INSIGHT, count = 7),
468469
),
469470
isStatsExpanded = true,
470471
readingRecords = persistentListOf(

feature/detail/src/main/kotlin/com/ninecraft/booket/feature/detail/book/component/CollectedSeeds.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private fun CollectedSeedsHeader(
120120
Row(
121121
verticalAlignment = Alignment.CenterVertically,
122122
) {
123-
primaryEmotion?.let { emotion ->
123+
primaryEmotion.let { emotion ->
124124
Image(
125125
painter = painterResource(id = emotion.code.graphicRes),
126126
contentDescription = "Seed Image",
@@ -134,7 +134,7 @@ private fun CollectedSeedsHeader(
134134

135135
Row {
136136
Text(
137-
text = "'${primaryEmotion?.code?.displayName ?: ""}'",
137+
text = "'${primaryEmotion.code.displayName}'",
138138
color = Yellow700,
139139
style = ReedTheme.typography.label1SemiBold,
140140
)

feature/detail/src/main/kotlin/com/ninecraft/booket/feature/detail/book/component/RecordItem.kt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,6 @@ internal fun RecordItem(
100100
}
101101
}
102102

103-
fun getEmotionImageResourceByDisplayName(displayName: String): Int {
104-
return when (displayName) {
105-
"따뜻함" -> R.drawable.img_warm
106-
"즐거움" -> R.drawable.img_joy
107-
"슬픔" -> R.drawable.img_sad
108-
"깨달음" -> R.drawable.img_insight
109-
"기타" -> R.drawable.img_etc
110-
else -> R.drawable.img_warm
111-
}
112-
}
113-
114103
@ComponentPreview
115104
@Composable
116105
private fun RecordItemPreview() {

feature/detail/src/main/kotlin/com/ninecraft/booket/feature/detail/book/component/SeedItem.kt

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import androidx.compose.ui.res.painterResource
1818
import androidx.compose.ui.unit.dp
1919
import com.ninecraft.booket.core.designsystem.ComponentPreview
2020
import com.ninecraft.booket.core.designsystem.bgColor
21+
import com.ninecraft.booket.core.designsystem.graphicRes
2122
import com.ninecraft.booket.core.designsystem.textColor
2223
import com.ninecraft.booket.core.designsystem.theme.ReedTheme
23-
import com.ninecraft.booket.core.model.Emotion
24+
import com.ninecraft.booket.core.model.EmotionCode
2425
import com.ninecraft.booket.core.model.EmotionModel
25-
import com.ninecraft.booket.feature.detail.R
2626

2727
@Composable
2828
internal fun SeedItem(
@@ -34,24 +34,24 @@ internal fun SeedItem(
3434
horizontalAlignment = Alignment.CenterHorizontally,
3535
) {
3636
Image(
37-
painter = painterResource(id = getEmotionImageResource(emotion.name)),
37+
painter = painterResource(id = emotion.code.graphicRes),
3838
contentDescription = "Seed Graphic Image",
3939
modifier = Modifier.size(50.dp),
4040
)
4141
Spacer(modifier = Modifier.height(ReedTheme.spacing.spacing2))
4242
Box(
4343
modifier = Modifier
4444
.clip(RoundedCornerShape(ReedTheme.radius.full))
45-
.background(emotion.name.bgColor)
45+
.background(emotion.code.bgColor)
4646
.padding(
4747
horizontal = ReedTheme.spacing.spacing2,
4848
vertical = ReedTheme.spacing.spacing1,
4949
),
5050
contentAlignment = Alignment.Center,
5151
) {
5252
Text(
53-
text = emotion.name.displayName,
54-
color = emotion.name.textColor,
53+
text = emotion.code.displayName,
54+
color = emotion.code.textColor,
5555
style = ReedTheme.typography.label2SemiBold,
5656
)
5757
}
@@ -64,23 +64,13 @@ internal fun SeedItem(
6464
}
6565
}
6666

67-
private fun getEmotionImageResource(emotion: Emotion): Int {
68-
return when (emotion) {
69-
Emotion.WARM -> R.drawable.img_warm
70-
Emotion.JOY -> R.drawable.img_joy
71-
Emotion.SAD -> R.drawable.img_sad
72-
Emotion.INSIGHT -> R.drawable.img_insight
73-
Emotion.ETC -> R.drawable.img_etc
74-
}
75-
}
76-
7767
@ComponentPreview
7868
@Composable
7969
private fun SeedItemPreview() {
8070
ReedTheme {
8171
SeedItem(
8272
emotion = EmotionModel(
83-
name = Emotion.WARM,
73+
code = EmotionCode.WARMTH,
8474
count = 3,
8575
),
8676
)

feature/detail/src/main/kotlin/com/ninecraft/booket/feature/detail/card/component/RecordCard.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ internal fun RecordCard(
7676

7777
private fun getEmotionCardImage(emotionCode: EmotionCode): Int {
7878
return when (emotionCode) {
79-
EmotionCode.WARMTH -> R.drawable.img_record_card_warm
79+
EmotionCode.WARMTH -> R.drawable.img_record_card_warmth
8080
EmotionCode.JOY -> R.drawable.img_record_card_joy
81-
EmotionCode.SADNESS -> R.drawable.img_record_card_sad
81+
EmotionCode.SADNESS -> R.drawable.img_record_card_sadness
8282
EmotionCode.INSIGHT -> R.drawable.img_record_card_insight
8383
EmotionCode.OTHER -> R.drawable.img_record_card_other
8484
}
-7.03 KB
Binary file not shown.

0 commit comments

Comments
 (0)