Skip to content

Commit 65d1dfb

Browse files
committed
Feat: 오늘의 감정 구슬 기능 구현
- 조회한 나의 감정에 따른 감정 구슬을 홈 화면에서 표시하는 기능 구현
1 parent b9c7ef9 commit 65d1dfb

File tree

6 files changed

+39
-1
lines changed

6 files changed

+39
-1
lines changed

presentation/src/main/java/com/threegap/bitnagil/presentation/home/HomeScreen.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ private fun HomeScreen(
241241

242242
CollapsibleHomeHeader(
243243
userName = uiState.userNickname,
244+
emotionBallType = uiState.myEmotion,
244245
collapsibleHeaderState = collapsibleHeaderState,
245246
onEmotionRecordClick = onRegisterEmotionClick,
246247
)

presentation/src/main/java/com/threegap/bitnagil/presentation/home/HomeViewModel.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.threegap.bitnagil.presentation.home
33
import android.util.Log
44
import androidx.lifecycle.SavedStateHandle
55
import androidx.lifecycle.viewModelScope
6+
import com.threegap.bitnagil.domain.emotion.usecase.GetMyEmotionUseCase
67
import com.threegap.bitnagil.domain.routine.model.RoutineCompletion
78
import com.threegap.bitnagil.domain.routine.model.RoutineCompletionInfo
89
import com.threegap.bitnagil.domain.routine.usecase.DeleteRoutineByDayUseCase
@@ -11,6 +12,7 @@ import com.threegap.bitnagil.domain.routine.usecase.FetchWeeklyRoutinesUseCase
1112
import com.threegap.bitnagil.domain.routine.usecase.RoutineCompletionUseCase
1213
import com.threegap.bitnagil.domain.user.usecase.FetchUserProfileUseCase
1314
import com.threegap.bitnagil.presentation.common.mviviewmodel.MviViewModel
15+
import com.threegap.bitnagil.presentation.home.model.EmotionBallType
1416
import com.threegap.bitnagil.presentation.home.model.HomeIntent
1517
import com.threegap.bitnagil.presentation.home.model.HomeSideEffect
1618
import com.threegap.bitnagil.presentation.home.model.HomeState
@@ -37,6 +39,7 @@ class HomeViewModel @Inject constructor(
3739
savedStateHandle: SavedStateHandle,
3840
private val fetchWeeklyRoutinesUseCase: FetchWeeklyRoutinesUseCase,
3941
private val fetchUserProfileUseCase: FetchUserProfileUseCase,
42+
private val getMyEmotionUseCase: GetMyEmotionUseCase,
4043
private val routineCompletionUseCase: RoutineCompletionUseCase,
4144
private val deleteRoutineUseCase: DeleteRoutineUseCase,
4245
private val deleteRoutineByDayUseCase: DeleteRoutineByDayUseCase,
@@ -53,6 +56,7 @@ class HomeViewModel @Inject constructor(
5356
observeRoutineUpdates()
5457
fetchWeeklyRoutines(container.stateFlow.value.currentWeeks)
5558
fetchUserProfile()
59+
getMyEmotion(container.stateFlow.value.selectedDate)
5660
}
5761

5862
override suspend fun SimpleSyntax<HomeState, HomeSideEffect>.reduceState(
@@ -188,6 +192,10 @@ class HomeViewModel @Inject constructor(
188192
}
189193

190194
is HomeIntent.ConfirmRoutineByDayDeletion -> null
195+
196+
is HomeIntent.LoadMyEmotion -> {
197+
state.copy(myEmotion = intent.emotion)
198+
}
191199
}
192200
return newState
193201
}
@@ -252,6 +260,23 @@ class HomeViewModel @Inject constructor(
252260
}
253261
}
254262

263+
private fun getMyEmotion(currentDate: LocalDate) {
264+
sendIntent(HomeIntent.UpdateLoading(true))
265+
viewModelScope.launch {
266+
getMyEmotionUseCase(currentDate.toString()).fold(
267+
onSuccess = { emotion ->
268+
val ballType = EmotionBallType.fromDomainEmotion(emotion.emotionMarbleType)
269+
sendIntent(HomeIntent.LoadMyEmotion(ballType))
270+
sendIntent(HomeIntent.UpdateLoading(false))
271+
},
272+
onFailure = { error ->
273+
Log.e("HomeViewModel", "나의 감정 실패: ${error.message}")
274+
sendIntent(HomeIntent.UpdateLoading(false))
275+
},
276+
)
277+
}
278+
}
279+
255280
fun toggleRoutineCompletion(routineId: String, isCompleted: Boolean) {
256281
val originalState = container.stateFlow.value
257282
sendIntent(HomeIntent.OnRoutineCompletionToggle(routineId, isCompleted))

presentation/src/main/java/com/threegap/bitnagil/presentation/home/component/template/CollapsibleHomeHeader.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ import com.threegap.bitnagil.designsystem.component.atom.BitnagilIcon
2626
import com.threegap.bitnagil.designsystem.modifier.clickableWithoutRipple
2727
import com.threegap.bitnagil.presentation.home.component.atom.EmotionBall
2828
import com.threegap.bitnagil.presentation.home.component.block.SpeechBubbleTooltip
29+
import com.threegap.bitnagil.presentation.home.model.EmotionBallType
2930
import com.threegap.bitnagil.presentation.home.util.CollapsibleHeaderState
3031
import com.threegap.bitnagil.presentation.home.util.rememberCollapsibleHeaderState
3132

3233
@Composable
3334
fun CollapsibleHomeHeader(
3435
userName: String,
36+
emotionBallType: EmotionBallType?,
3537
collapsibleHeaderState: CollapsibleHeaderState,
3638
onEmotionRecordClick: () -> Unit,
3739
modifier: Modifier = Modifier,
@@ -96,7 +98,7 @@ fun CollapsibleHomeHeader(
9698
.align(Alignment.BottomEnd),
9799
) {
98100
EmotionBall(
99-
emotionType = null,
101+
emotionType = emotionBallType,
100102
onClick = {},
101103
)
102104
}
@@ -149,6 +151,7 @@ private fun GreetingMessage(
149151
private fun HomeTopBarPreview() {
150152
CollapsibleHomeHeader(
151153
userName = "대현",
154+
emotionBallType = null,
152155
collapsibleHeaderState = rememberCollapsibleHeaderState(),
153156
onEmotionRecordClick = {},
154157
)

presentation/src/main/java/com/threegap/bitnagil/presentation/home/model/EmotionBallType.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.threegap.bitnagil.presentation.home.model
33
import androidx.annotation.DrawableRes
44
import androidx.compose.ui.graphics.Color
55
import com.threegap.bitnagil.designsystem.R
6+
import com.threegap.bitnagil.domain.emotion.model.Emotion
67

78
enum class EmotionBallType(
89
@DrawableRes val drawableId: Int,
@@ -39,4 +40,10 @@ enum class EmotionBallType(
3940
ambientColor = Color(0xFFC71A1A).copy(alpha = 0.28f),
4041
spotColor = Color(0xFFC71A1A),
4142
),
43+
;
44+
45+
companion object {
46+
fun fromDomainEmotion(emotion: Emotion?): EmotionBallType? =
47+
emotion?.let { valueOf(it.name) }
48+
}
4249
}

presentation/src/main/java/com/threegap/bitnagil/presentation/home/model/HomeIntent.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import java.time.LocalDate
66
sealed class HomeIntent : MviIntent {
77
data class UpdateLoading(val isLoading: Boolean) : HomeIntent()
88
data class LoadUserProfile(val nickname: String) : HomeIntent()
9+
data class LoadMyEmotion(val emotion: EmotionBallType?) : HomeIntent()
910
data class LoadWeeklyRoutines(val routines: RoutinesUiModel) : HomeIntent()
1011
data class OnDateSelect(val date: LocalDate) : HomeIntent()
1112
data class OnRoutineCompletionToggle(val routineId: String, val isCompleted: Boolean) : HomeIntent()

presentation/src/main/java/com/threegap/bitnagil/presentation/home/model/HomeState.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import java.time.LocalDate
99
data class HomeState(
1010
val isLoading: Boolean = false,
1111
val userNickname: String = "",
12+
val myEmotion: EmotionBallType? = null,
1213
val selectedDate: LocalDate = LocalDate.now(),
1314
val currentWeeks: List<LocalDate> = LocalDate.now().getCurrentWeekDays(),
1415
val routines: RoutinesUiModel = RoutinesUiModel(),

0 commit comments

Comments
 (0)