@@ -22,25 +22,36 @@ 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
2526import androidx.compose.ui.Alignment
2627import androidx.compose.ui.Modifier
2728import androidx.compose.ui.draw.clip
2829import androidx.compose.ui.graphics.vector.ImageVector
2930import androidx.compose.ui.res.painterResource
31+ import androidx.compose.ui.res.stringResource
3032import androidx.compose.ui.res.vectorResource
3133import androidx.compose.ui.unit.dp
3234import com.ninecraft.booket.core.designsystem.ComponentPreview
3335import com.ninecraft.booket.core.designsystem.graphicRes
36+ import com.ninecraft.booket.core.designsystem.primaryEmotionColor
3437import com.ninecraft.booket.core.designsystem.ratioBarColor
3538import com.ninecraft.booket.core.designsystem.theme.ReedTheme
36- import com.ninecraft.booket.core.designsystem.theme.Yellow700
3739import com.ninecraft.booket.core.model.EmotionCode
3840import com.ninecraft.booket.core.model.EmotionModel
3941import com.ninecraft.booket.core.model.PrimaryEmotionModel
42+ import com.ninecraft.booket.feature.detail.R
4043import kotlinx.collections.immutable.ImmutableList
4144import kotlinx.collections.immutable.persistentListOf
4245import com.ninecraft.booket.core.designsystem.R as designR
4346
47+ private val EMOTION_DISPLAY_ORDER = listOf (
48+ EmotionCode .WARMTH ,
49+ EmotionCode .JOY ,
50+ EmotionCode .SADNESS ,
51+ EmotionCode .INSIGHT ,
52+ EmotionCode .OTHER ,
53+ )
54+
4455@Composable
4556internal fun CollectedSeeds (
4657 seedsStats : ImmutableList <EmotionModel >,
@@ -85,17 +96,23 @@ internal fun CollectedSeeds(
8596
8697 Spacer (modifier = Modifier .height(ReedTheme .spacing.spacing4))
8798
88- Row (
89- modifier = Modifier .fillMaxWidth(),
90- horizontalArrangement = Arrangement .spacedBy(ReedTheme .spacing.spacing1),
91- ) {
92- EmotionCode .entries.forEach { emotionCode ->
93- val emotionModel = seedsStats.find { it.code == emotionCode }
94- ? : EmotionModel (emotionCode, 0 )
95- EmotionStatCard (
96- emotion = emotionModel,
97- modifier = Modifier .weight(1f ),
98- )
99+ val displayEmotions = remember(seedsStats) {
100+ EMOTION_DISPLAY_ORDER .mapNotNull { emotionCode ->
101+ seedsStats.find { it.code == emotionCode && it.count > 0 }
102+ }
103+ }
104+
105+ if (displayEmotions.isNotEmpty()) {
106+ Row (
107+ modifier = Modifier .fillMaxWidth(),
108+ horizontalArrangement = Arrangement .spacedBy(ReedTheme .spacing.spacing1),
109+ ) {
110+ displayEmotions.forEach { emotionModel ->
111+ EmotionStatCard (
112+ emotion = emotionModel,
113+ modifier = Modifier .weight(1f ),
114+ )
115+ }
99116 }
100117 }
101118 }
@@ -132,15 +149,28 @@ private fun CollectedSeedsHeader(
132149 Spacer (modifier = Modifier .width(ReedTheme .spacing.spacing2))
133150 }
134151
135- Row {
152+ Row (
153+ verticalAlignment = Alignment .CenterVertically ,
154+ ) {
155+ val emotionDisplayName = if (primaryEmotion.code == EmotionCode .OTHER ) {
156+ stringResource(R .string.collected_seed_other_emotion_name)
157+ } else {
158+ primaryEmotion.code.displayName
159+ }
136160 Text (
137- text = " '${primaryEmotion.code.displayName} '" ,
138- color = Yellow700 ,
161+ text = " '$emotionDisplayName '" ,
162+ color = primaryEmotion.code.primaryEmotionColor ,
139163 style = ReedTheme .typography.label1SemiBold,
140164 )
141165 Spacer (modifier = Modifier .width(ReedTheme .spacing.spacing1))
142166 Text (
143- text = " 감정을 많이 느꼈어요" ,
167+ text = stringResource(
168+ if (primaryEmotion.code == EmotionCode .OTHER ) {
169+ R .string.collected_seed_other_emotion_description
170+ } else {
171+ R .string.collected_seed_emotion_description
172+ },
173+ ),
144174 color = ReedTheme .colors.contentSecondary,
145175 style = ReedTheme .typography.label1Medium,
146176 )
@@ -163,7 +193,9 @@ private fun EmotionRatioBar(
163193 seedsStats : ImmutableList <EmotionModel >,
164194 modifier : Modifier = Modifier ,
165195) {
166- val totalCount = seedsStats.sumOf { it.count }.coerceAtLeast(1 )
196+ val totalCount = remember(seedsStats) {
197+ seedsStats.sumOf { it.count }.coerceAtLeast(1 )
198+ }
167199
168200 Row (
169201 modifier = modifier
@@ -231,13 +263,13 @@ private fun CollectedSeedsCollapsedPreview() {
231263 ReedTheme {
232264 CollectedSeeds (
233265 seedsStats = persistentListOf(
234- EmotionModel (EmotionCode .WARMTH , 4 ),
266+ EmotionModel (EmotionCode .WARMTH , 2 ),
235267 EmotionModel (EmotionCode .JOY , 2 ),
236- EmotionModel (EmotionCode .SADNESS , 2 ),
268+ EmotionModel (EmotionCode .SADNESS , 4 ),
237269 EmotionModel (EmotionCode .INSIGHT , 2 ),
238270 EmotionModel (EmotionCode .OTHER , 2 ),
239271 ),
240- representativeEmotion = PrimaryEmotionModel (EmotionCode .WARMTH , " 기쁨 " ),
272+ representativeEmotion = PrimaryEmotionModel (EmotionCode .SADNESS , " 슬픔 " ),
241273 isStatsExpanded = false ,
242274 onToggleClick = {},
243275 )
@@ -250,13 +282,13 @@ private fun CollectedSeedsExpandedPreview() {
250282 ReedTheme {
251283 CollectedSeeds (
252284 seedsStats = persistentListOf(
253- EmotionModel (EmotionCode .WARMTH , 4 ),
285+ EmotionModel (EmotionCode .WARMTH , 2 ),
254286 EmotionModel (EmotionCode .JOY , 2 ),
255287 EmotionModel (EmotionCode .SADNESS , 2 ),
256288 EmotionModel (EmotionCode .INSIGHT , 2 ),
257- EmotionModel (EmotionCode .OTHER , 2 ),
289+ EmotionModel (EmotionCode .OTHER , 4 ),
258290 ),
259- representativeEmotion = PrimaryEmotionModel (EmotionCode .WARMTH , " 기쁨 " ),
291+ representativeEmotion = PrimaryEmotionModel (EmotionCode .OTHER , " 기타 " ),
260292 isStatsExpanded = true ,
261293 onToggleClick = {},
262294 )
@@ -275,7 +307,7 @@ private fun CollectedSeedsExpandedDuplicatedPreview() {
275307 EmotionModel (EmotionCode .INSIGHT , 2 ),
276308 EmotionModel (EmotionCode .OTHER , 2 ),
277309 ),
278- representativeEmotion = PrimaryEmotionModel (EmotionCode .WARMTH , " 기쁨 " ),
310+ representativeEmotion = PrimaryEmotionModel (EmotionCode .WARMTH , " 따뜻함 " ),
279311 isStatsExpanded = true ,
280312 onToggleClick = {},
281313 )
0 commit comments