@@ -22,35 +22,33 @@ import androidx.compose.material3.HorizontalDivider
2222import androidx.compose.material3.Icon
2323import androidx.compose.material3.Text
2424import androidx.compose.runtime.Composable
25- import androidx.compose.runtime.remember
2625import androidx.compose.ui.Alignment
2726import androidx.compose.ui.Modifier
2827import androidx.compose.ui.draw.clip
2928import androidx.compose.ui.graphics.vector.ImageVector
3029import androidx.compose.ui.res.painterResource
3130import androidx.compose.ui.res.vectorResource
3231import androidx.compose.ui.unit.dp
33- import com.ninecraft.booket.core.common.utils.analyzeEmotions
3432import com.ninecraft.booket.core.designsystem.ComponentPreview
33+ import com.ninecraft.booket.core.designsystem.graphicRes
3534import com.ninecraft.booket.core.designsystem.ratioBarColor
3635import com.ninecraft.booket.core.designsystem.theme.ReedTheme
3736import com.ninecraft.booket.core.designsystem.theme.Yellow700
38- import com.ninecraft.booket.core.model.Emotion
37+ import com.ninecraft.booket.core.model.EmotionCode
3938import com.ninecraft.booket.core.model.EmotionModel
39+ import com.ninecraft.booket.core.model.PrimaryEmotionModel
4040import kotlinx.collections.immutable.ImmutableList
4141import kotlinx.collections.immutable.persistentListOf
4242import com.ninecraft.booket.core.designsystem.R as designR
4343
4444@Composable
4545internal fun CollectedSeeds (
4646 seedsStats : ImmutableList <EmotionModel >,
47+ representativeEmotion : PrimaryEmotionModel ,
4748 isStatsExpanded : Boolean ,
4849 onToggleClick : () -> Unit ,
4950 modifier : Modifier = Modifier ,
5051) {
51- val analysisResult = remember(seedsStats) { analyzeEmotions(seedsStats) }
52- val topEmotion = analysisResult.topEmotions.firstOrNull()
53-
5452 Column (
5553 modifier = modifier
5654 .fillMaxWidth()
@@ -65,7 +63,7 @@ internal fun CollectedSeeds(
6563 .padding(ReedTheme .spacing.spacing4),
6664 ) {
6765 CollectedSeedsHeader (
68- topEmotion = topEmotion ,
66+ primaryEmotion = representativeEmotion ,
6967 isStatsExpanded = isStatsExpanded,
7068 onToggleClick = onToggleClick,
7169 )
@@ -91,9 +89,9 @@ internal fun CollectedSeeds(
9189 modifier = Modifier .fillMaxWidth(),
9290 horizontalArrangement = Arrangement .spacedBy(ReedTheme .spacing.spacing1),
9391 ) {
94- Emotion .entries.forEach { emotion ->
95- val emotionModel = seedsStats.find { it.name == emotion }
96- ? : EmotionModel (emotion , 0 )
92+ EmotionCode .entries.forEach { emotionCode ->
93+ val emotionModel = seedsStats.find { it.code == emotionCode }
94+ ? : EmotionModel (emotionCode , 0 )
9795 EmotionStatCard (
9896 emotion = emotionModel,
9997 modifier = Modifier .weight(1f ),
@@ -107,7 +105,7 @@ internal fun CollectedSeeds(
107105
108106@Composable
109107private fun CollectedSeedsHeader (
110- topEmotion : EmotionModel ? ,
108+ primaryEmotion : PrimaryEmotionModel ,
111109 isStatsExpanded : Boolean ,
112110 onToggleClick : () -> Unit ,
113111 modifier : Modifier = Modifier ,
@@ -122,9 +120,9 @@ private fun CollectedSeedsHeader(
122120 Row (
123121 verticalAlignment = Alignment .CenterVertically ,
124122 ) {
125- topEmotion ?.let { emotion ->
123+ primaryEmotion ?.let { emotion ->
126124 Image (
127- painter = painterResource(id = getEmotionImageResourceByDisplayName( emotion.name.displayName) ),
125+ painter = painterResource(id = emotion.code.graphicRes ),
128126 contentDescription = " Seed Image" ,
129127 modifier = Modifier
130128 .size(36 .dp)
@@ -136,7 +134,7 @@ private fun CollectedSeedsHeader(
136134
137135 Row {
138136 Text (
139- text = " '${topEmotion?.name ?.displayName ? : " " } '" ,
137+ text = " '${primaryEmotion?.code ?.displayName ? : " " } '" ,
140138 color = Yellow700 ,
141139 style = ReedTheme .typography.label1SemiBold,
142140 )
@@ -173,16 +171,16 @@ private fun EmotionRatioBar(
173171 .height(12 .dp)
174172 .clip(RoundedCornerShape (ReedTheme .radius.full)),
175173 ) {
176- Emotion .entries.forEach { emotion ->
177- val emotionModel = seedsStats.find { it.name == emotion }
174+ EmotionCode .entries.forEach { emotionCode ->
175+ val emotionModel = seedsStats.find { it.code == emotionCode }
178176 val count = emotionModel?.count ? : 0
179177 if (count > 0 ) {
180178 val weight = count.toFloat() / totalCount
181179 Box (
182180 modifier = Modifier
183181 .weight(weight)
184182 .height(12 .dp)
185- .background(emotion .ratioBarColor),
183+ .background(emotionCode .ratioBarColor),
186184 )
187185 }
188186 }
@@ -208,13 +206,13 @@ private fun EmotionStatCard(
208206 modifier = Modifier
209207 .size(10 .dp)
210208 .clip(RoundedCornerShape (ReedTheme .radius.xs))
211- .background(emotion.name .ratioBarColor),
209+ .background(emotion.code .ratioBarColor),
212210 )
213211
214212 Spacer (modifier = Modifier .height(ReedTheme .spacing.spacing2))
215213
216214 Text (
217- text = emotion.name .displayName,
215+ text = emotion.code .displayName,
218216 color = ReedTheme .colors.contentSecondary,
219217 style = ReedTheme .typography.label2Regular,
220218 )
@@ -233,12 +231,13 @@ private fun CollectedSeedsCollapsedPreview() {
233231 ReedTheme {
234232 CollectedSeeds (
235233 seedsStats = persistentListOf(
236- EmotionModel (Emotion . WARM , 4 ),
237- EmotionModel (Emotion .JOY , 2 ),
238- EmotionModel (Emotion . SAD , 2 ),
239- EmotionModel (Emotion .INSIGHT , 2 ),
240- EmotionModel (Emotion . ETC , 2 ),
234+ EmotionModel (EmotionCode . WARMTH , 4 ),
235+ EmotionModel (EmotionCode .JOY , 2 ),
236+ EmotionModel (EmotionCode . SADNESS , 2 ),
237+ EmotionModel (EmotionCode .INSIGHT , 2 ),
238+ EmotionModel (EmotionCode . OTHER , 2 ),
241239 ),
240+ representativeEmotion = PrimaryEmotionModel (EmotionCode .WARMTH , " 기쁨" ),
242241 isStatsExpanded = false ,
243242 onToggleClick = {},
244243 )
@@ -251,12 +250,13 @@ private fun CollectedSeedsExpandedPreview() {
251250 ReedTheme {
252251 CollectedSeeds (
253252 seedsStats = persistentListOf(
254- EmotionModel (Emotion . WARM , 4 ),
255- EmotionModel (Emotion .JOY , 2 ),
256- EmotionModel (Emotion . SAD , 2 ),
257- EmotionModel (Emotion .INSIGHT , 2 ),
258- EmotionModel (Emotion . ETC , 2 ),
253+ EmotionModel (EmotionCode . WARMTH , 4 ),
254+ EmotionModel (EmotionCode .JOY , 2 ),
255+ EmotionModel (EmotionCode . SADNESS , 2 ),
256+ EmotionModel (EmotionCode .INSIGHT , 2 ),
257+ EmotionModel (EmotionCode . OTHER , 2 ),
259258 ),
259+ representativeEmotion = PrimaryEmotionModel (EmotionCode .WARMTH , " 기쁨" ),
260260 isStatsExpanded = true ,
261261 onToggleClick = {},
262262 )
@@ -269,12 +269,13 @@ private fun CollectedSeedsExpandedDuplicatedPreview() {
269269 ReedTheme {
270270 CollectedSeeds (
271271 seedsStats = persistentListOf(
272- EmotionModel (Emotion . WARM , 4 ),
273- EmotionModel (Emotion .JOY , 4 ),
274- EmotionModel (Emotion . SAD , 2 ),
275- EmotionModel (Emotion .INSIGHT , 2 ),
276- EmotionModel (Emotion . ETC , 2 ),
272+ EmotionModel (EmotionCode . WARMTH , 4 ),
273+ EmotionModel (EmotionCode .JOY , 4 ),
274+ EmotionModel (EmotionCode . SADNESS , 2 ),
275+ EmotionModel (EmotionCode .INSIGHT , 2 ),
276+ EmotionModel (EmotionCode . OTHER , 2 ),
277277 ),
278+ representativeEmotion = PrimaryEmotionModel (EmotionCode .WARMTH , " 기쁨" ),
278279 isStatsExpanded = true ,
279280 onToggleClick = {},
280281 )
0 commit comments