Skip to content

Commit 9d639de

Browse files
committed
[BOOK-212] feat: 감정이 존재하지 않을 경우에 대한 분기 처리 추가
1 parent abd709a commit 9d639de

File tree

5 files changed

+101
-61
lines changed

5 files changed

+101
-61
lines changed

core/common/src/main/kotlin/com/ninecraft/booket/core/common/util/EmotionAnalyzer.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@ data class EmotionAnalysisResult(
88
)
99

1010
enum class EmotionDisplayType {
11+
NONE, // 모든 감정의 count가 0
1112
SINGLE, // 1개 감정이 1위
1213
DUAL, // 2개 감정이 공동 1위
1314
BALANCED, // 3개 이상 감정이 공동 1위
1415
}
1516

1617
fun analyzeEmotions(emotions: List<EmotionModel>): EmotionAnalysisResult {
17-
if (emotions.isEmpty()) {
18-
return EmotionAnalysisResult(emptyList(), EmotionDisplayType.BALANCED)
18+
val maxCount = emotions.maxOf { it.count }
19+
20+
// 모든 감정의 count가 0인 경우
21+
if (maxCount == 0) {
22+
return EmotionAnalysisResult(emptyList(), EmotionDisplayType.NONE)
1923
}
2024

21-
val maxCount = emotions.maxOf { it.count }
2225
val topEmotions = emotions.filter { it.count == maxCount }
2326

2427
val displayType = when (topEmotions.size) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ internal fun BookDetailContent(
148148
state.eventSink(BookDetailUiEvent.OnBookStatusButtonClick)
149149
},
150150
text = stringResource(
151-
BookStatus.fromValue(state.bookDetail.userBookStatus)?.getDisplayNameRes()
151+
BookStatus.fromValue(state.bookDetail.userBookStatus)?.getDisplayNameRes()
152152
?: BookStatus.BEFORE_READING.getDisplayNameRes()
153153
),
154154
sizeStyle = largeButtonStyle,
@@ -178,10 +178,10 @@ internal fun BookDetailContent(
178178
}
179179

180180
item {
181-
if (state.recordCollections.isEmpty()) {
182-
Spacer(modifier = Modifier.height(ReedTheme.spacing.spacing10))
183-
} else {
181+
if (state.hasEmotionData()) {
184182
CollectedSeeds(seedsStats = state.seedsStats)
183+
} else {
184+
Spacer(modifier = Modifier.height(ReedTheme.spacing.spacing10))
185185
}
186186

187187
ReedDivider()

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,36 @@ data class BookDetailUiState(
2424
RecordRegisterModel(
2525
id = "0",
2626
pageNumber = 12,
27-
quote = "책을 읽으면 차분해지며 숲으로 둘러싸인 여름 별장 속으로 간 것 같은 기분이 든다. 그 곳에서 그들이 품은 건축에 대한 이상과 삶을 구경하는 것만으로도 충분했다.책을 읽으면 차분해지며 숲으로 둘러싸인 여름 별장 속으로 간 것 같은 기분이 든다. 그 곳에서 그들이 품은 건축에 대한 이상과 삶을 구경하는 것만으로도 충분했다.",
27+
quote = "책을 읽으면 차분해지며 숲으로 둘러싸인 여름 별장 속으로 간 것 같은 기분이 든다. 그 곳에서 그들이 품은 건축에 대한 이상과 삶을 구경하는 것만으로도 충분했다.책을 읽으면 차분해지며 숲으로 둘러싸인 여름 별장 속으로 간 것 같은 기분이 든다. 그 곳에서 그들이 품은 건축에 대한 이상과 삶을 구경하는 것만으로도 충분했다.",
2828
createdAt = "2025.06.25",
2929
),
3030
RecordRegisterModel(
3131
id = "1",
3232
pageNumber = 13,
33-
quote = "책을 읽으면 차분해지며 숲으로 둘러싸인 여름 별장 속으로 간 것 같은 기분이 든다. 그 곳에서 그들이 품은 건축에 대한 이상과 삶을 구경하는 것만으로도 충분했다.책을 읽으면 차분해지며 숲으로 둘러싸인 여름 별장 속으로 간 것 같은 기분이 든다. 그 곳에서 그들이 품은 건축에 대한 이상과 삶을 구경하는 것만으로도 충분했다.",
33+
quote = "책을 읽으면 차분해지며 숲으로 둘러싸인 여름 별장 속으로 간 것 같은 기분이 든다. 그 곳에서 그들이 품은 건축에 대한 이상과 삶을 구경하는 것만으로도 충분했다.책을 읽으면 차분해지며 숲으로 둘러싸인 여름 별장 속으로 간 것 같은 기분이 든다. 그 곳에서 그들이 품은 건축에 대한 이상과 삶을 구경하는 것만으로도 충분했다.",
3434
createdAt = "2025.06.25",
3535
),
3636
RecordRegisterModel(
3737
id = "2",
3838
pageNumber = 14,
39-
quote = "책을 읽으면 차분해지며 숲으로 둘러싸인 여름 별장 속으로 간 것 같은 기분이 든다. 그 곳에서 그들이 품은 건축에 대한 이상과 삶을 구경하는 것만으로도 충분했다.책을 읽으면 차분해지며 숲으로 둘러싸인 여름 별장 속으로 간 것 같은 기분이 든다. 그 곳에서 그들이 품은 건축에 대한 이상과 삶을 구경하는 것만으로도 충분했다.",
39+
quote = "책을 읽으면 차분해지며 숲으로 둘러싸인 여름 별장 속으로 간 것 같은 기분이 든다. 그 곳에서 그들이 품은 건축에 대한 이상과 삶을 구경하는 것만으로도 충분했다.책을 읽으면 차분해지며 숲으로 둘러싸인 여름 별장 속으로 간 것 같은 기분이 든다. 그 곳에서 그들이 품은 건축에 대한 이상과 삶을 구경하는 것만으로도 충분했다.",
4040
createdAt = "2025.06.25",
4141
),
4242
RecordRegisterModel(
4343
id = "3",
4444
pageNumber = 15,
45-
quote = "책을 읽으면 차분해지며 숲으로 둘러싸인 여름 별장 속으로 간 것 같은 기분이 든다. 그 곳에서 그들이 품은 건축에 대한 이상과 삶을 구경하는 것만으로도 충분했다.책을 읽으면 차분해지며 숲으로 둘러싸인 여름 별장 속으로 간 것 같은 기분이 든다. 그 곳에서 그들이 품은 건축에 대한 이상과 삶을 구경하는 것만으로도 충분했다.",
45+
quote = "책을 읽으면 차분해지며 숲으로 둘러싸인 여름 별장 속으로 간 것 같은 기분이 든다. 그 곳에서 그들이 품은 건축에 대한 이상과 삶을 구경하는 것만으로도 충분했다.책을 읽으면 차분해지며 숲으로 둘러싸인 여름 별장 속으로 간 것 같은 기분이 든다. 그 곳에서 그들이 품은 건축에 대한 이상과 삶을 구경하는 것만으로도 충분했다.",
4646
createdAt = "2025.06.25",
4747
),
4848
),
4949
val sideEffect: BookDetailSideEffect? = null,
5050
val eventSink: (BookDetailUiEvent) -> Unit,
51-
) : CircuitUiState
51+
) : CircuitUiState {
52+
53+
fun hasEmotionData(): Boolean {
54+
return seedsStats.any { it.count > 0 }
55+
}
56+
}
5257

5358
@Immutable
5459
sealed interface BookDetailSideEffect {

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,19 @@ internal fun CollectedSeeds(
7575
shape = RoundedCornerShape(ReedTheme.radius.sm),
7676
),
7777
) {
78-
Text(
79-
text = EmotionAnalysisResultText(
80-
emotions = seedsStats,
81-
brandColor = ReedTheme.colors.contentBrand,
82-
secondaryColor = ReedTheme.colors.contentSecondary,
83-
emotionTextStyle = ReedTheme.typography.label2SemiBold,
84-
regularTextStyle = ReedTheme.typography.label2Regular,
85-
),
86-
modifier = Modifier.fillMaxWidth(),
87-
textAlign = TextAlign.Center,
88-
)
78+
EmotionAnalysisResultText(
79+
emotions = seedsStats,
80+
brandColor = ReedTheme.colors.contentBrand,
81+
secondaryColor = ReedTheme.colors.contentSecondary,
82+
emotionTextStyle = ReedTheme.typography.label2SemiBold,
83+
regularTextStyle = ReedTheme.typography.label2Regular,
84+
)?.let { annotatedString ->
85+
Text(
86+
text = annotatedString,
87+
modifier = Modifier.fillMaxWidth(),
88+
textAlign = TextAlign.Center,
89+
)
90+
}
8991
}
9092
Spacer(modifier = Modifier.height(ReedTheme.spacing.spacing4))
9193
}

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

Lines changed: 68 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ internal fun EmotionAnalysisResultText(
3131
secondaryColor: Color,
3232
emotionTextStyle: TextStyle,
3333
regularTextStyle: TextStyle,
34-
): AnnotatedString {
34+
): AnnotatedString? {
3535
val analysisResult = remember(emotions) { analyzeEmotions(emotions) }
3636

3737
return when (analysisResult.displayType) {
38+
EmotionDisplayType.NONE -> null
39+
3840
EmotionDisplayType.SINGLE -> {
3941
val emotion = analysisResult.topEmotions.first()
4042
buildAnnotatedString {
@@ -91,51 +93,79 @@ private fun EmotionTextAllCasesPreview() {
9193
ReedTheme {
9294
Column(modifier = Modifier.padding(16.dp)) {
9395
Text(text = "1개의 감정이 1위인 경우:")
94-
Text(
95-
text = EmotionAnalysisResultText(
96-
emotions = persistentListOf(
97-
EmotionModel(name = Emotion.WARM, count = 5),
98-
EmotionModel(name = Emotion.JOY, count = 2),
99-
),
100-
brandColor = ReedTheme.colors.contentBrand,
101-
secondaryColor = ReedTheme.colors.contentSecondary,
102-
emotionTextStyle = ReedTheme.typography.label2SemiBold,
103-
regularTextStyle = ReedTheme.typography.label2Regular,
96+
EmotionAnalysisResultText(
97+
emotions = persistentListOf(
98+
EmotionModel(name = Emotion.WARM, count = 5),
99+
EmotionModel(name = Emotion.JOY, count = 2),
104100
),
105-
modifier = Modifier.padding(vertical = 8.dp),
106-
)
101+
brandColor = ReedTheme.colors.contentBrand,
102+
secondaryColor = ReedTheme.colors.contentSecondary,
103+
emotionTextStyle = ReedTheme.typography.label2SemiBold,
104+
regularTextStyle = ReedTheme.typography.label2Regular,
105+
)?.let { annotatedString ->
106+
Text(
107+
text = annotatedString,
108+
modifier = Modifier.padding(vertical = 8.dp),
109+
)
110+
}
107111
Spacer(modifier = Modifier.height(16.dp))
108112
Text(text = "2개의 감정이 공동 1위인 경우:")
109-
Text(
110-
text = EmotionAnalysisResultText(
111-
emotions = persistentListOf(
112-
EmotionModel(name = Emotion.WARM, count = 5),
113-
EmotionModel(name = Emotion.JOY, count = 5),
114-
EmotionModel(name = Emotion.SADNESS, count = 2),
115-
),
116-
brandColor = ReedTheme.colors.contentBrand,
117-
secondaryColor = ReedTheme.colors.contentSecondary,
118-
emotionTextStyle = ReedTheme.typography.label2SemiBold,
119-
regularTextStyle = ReedTheme.typography.label2Regular,
113+
EmotionAnalysisResultText(
114+
emotions = persistentListOf(
115+
EmotionModel(name = Emotion.WARM, count = 5),
116+
EmotionModel(name = Emotion.JOY, count = 5),
117+
EmotionModel(name = Emotion.SADNESS, count = 2),
120118
),
121-
modifier = Modifier.padding(vertical = 8.dp),
122-
)
119+
brandColor = ReedTheme.colors.contentBrand,
120+
secondaryColor = ReedTheme.colors.contentSecondary,
121+
emotionTextStyle = ReedTheme.typography.label2SemiBold,
122+
regularTextStyle = ReedTheme.typography.label2Regular,
123+
)?.let { annotatedString ->
124+
Text(
125+
text = annotatedString,
126+
modifier = Modifier.padding(vertical = 8.dp),
127+
)
128+
}
123129
Spacer(modifier = Modifier.height(16.dp))
124130
Text(text = "3~4개의 감정이 공동 1위인 경우:")
125-
Text(
126-
text = EmotionAnalysisResultText(
127-
emotions = persistentListOf(
128-
EmotionModel(name = Emotion.WARM, count = 3),
129-
EmotionModel(name = Emotion.JOY, count = 3),
130-
EmotionModel(name = Emotion.SADNESS, count = 3),
131-
EmotionModel(name = Emotion.TENSION, count = 3),
132-
),
133-
brandColor = ReedTheme.colors.contentBrand,
134-
secondaryColor = ReedTheme.colors.contentSecondary,
135-
emotionTextStyle = ReedTheme.typography.label2SemiBold,
136-
regularTextStyle = ReedTheme.typography.label2Regular,
131+
EmotionAnalysisResultText(
132+
emotions = persistentListOf(
133+
EmotionModel(name = Emotion.WARM, count = 3),
134+
EmotionModel(name = Emotion.JOY, count = 3),
135+
EmotionModel(name = Emotion.SADNESS, count = 3),
136+
EmotionModel(name = Emotion.TENSION, count = 3),
137+
),
138+
brandColor = ReedTheme.colors.contentBrand,
139+
secondaryColor = ReedTheme.colors.contentSecondary,
140+
emotionTextStyle = ReedTheme.typography.label2SemiBold,
141+
regularTextStyle = ReedTheme.typography.label2Regular,
142+
)?.let { annotatedString ->
143+
Text(
144+
text = annotatedString,
145+
modifier = Modifier.padding(vertical = 8.dp),
146+
)
147+
}
148+
Spacer(modifier = Modifier.height(16.dp))
149+
Text(text = "모든 감정의 count가 0인 경우:")
150+
EmotionAnalysisResultText(
151+
emotions = persistentListOf(
152+
EmotionModel(name = Emotion.WARM, count = 0),
153+
EmotionModel(name = Emotion.JOY, count = 0),
154+
EmotionModel(name = Emotion.SADNESS, count = 0),
137155
),
156+
brandColor = ReedTheme.colors.contentBrand,
157+
secondaryColor = ReedTheme.colors.contentSecondary,
158+
emotionTextStyle = ReedTheme.typography.label2SemiBold,
159+
regularTextStyle = ReedTheme.typography.label2Regular,
160+
)?.let { annotatedString ->
161+
Text(
162+
text = annotatedString,
163+
modifier = Modifier.padding(vertical = 8.dp),
164+
)
165+
} ?: Text(
166+
text = "null 반환 - 표시되지 않음",
138167
modifier = Modifier.padding(vertical = 8.dp),
168+
color = ReedTheme.colors.contentSecondary,
139169
)
140170
}
141171
}

0 commit comments

Comments
 (0)