Skip to content

Commit 6b12a55

Browse files
committed
FEAT: 감정 구슬 변화여부를 홈 화면에서 감지하여 감정 구슬을 갱신할 수 있도록 구현
1 parent 90494f7 commit 6b12a55

5 files changed

Lines changed: 43 additions & 1 deletion

File tree

data/src/main/java/com/threegap/bitnagil/data/emotion/repositoryImpl/EmotionRepositoryImpl.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import com.threegap.bitnagil.data.emotion.datasource.EmotionDataSource
44
import com.threegap.bitnagil.data.emotion.model.response.toDomain
55
import com.threegap.bitnagil.domain.emotion.model.EmotionRecommendRoutine
66
import com.threegap.bitnagil.domain.emotion.model.Emotion
7+
import com.threegap.bitnagil.domain.emotion.model.EmotionChangeEvent
78
import com.threegap.bitnagil.domain.emotion.repository.EmotionRepository
9+
import kotlinx.coroutines.flow.Flow
10+
import kotlinx.coroutines.flow.MutableSharedFlow
11+
import kotlinx.coroutines.flow.asSharedFlow
812
import javax.inject.Inject
913

1014
class EmotionRepositoryImpl @Inject constructor(
@@ -22,9 +26,16 @@ class EmotionRepositoryImpl @Inject constructor(
2226
emotionRecommendedRoutineDto ->
2327
emotionRecommendedRoutineDto.toEmotionRecommendRoutine()
2428
}
29+
}.also {
30+
if (it.isSuccess) {
31+
_emotionChangeEventFlow.emit(EmotionChangeEvent.ChangeEmotion(emotionMarbleType))
32+
}
2533
}
2634
}
2735

2836
override suspend fun getEmotionMarble(currentDate: String): Result<Emotion?> =
2937
emotionDataSource.getEmotionMarble(currentDate).map { it.toDomain() }
38+
39+
private val _emotionChangeEventFlow = MutableSharedFlow<EmotionChangeEvent>()
40+
override suspend fun getEmotionChangeEventFlow(): Flow<EmotionChangeEvent> = _emotionChangeEventFlow.asSharedFlow()
3041
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.threegap.bitnagil.domain.emotion.model
2+
3+
sealed interface EmotionChangeEvent {
4+
data class ChangeEmotion(val emotionType: String) : EmotionChangeEvent
5+
}

domain/src/main/java/com/threegap/bitnagil/domain/emotion/repository/EmotionRepository.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ package com.threegap.bitnagil.domain.emotion.repository
22

33
import com.threegap.bitnagil.domain.emotion.model.EmotionRecommendRoutine
44
import com.threegap.bitnagil.domain.emotion.model.Emotion
5+
import com.threegap.bitnagil.domain.emotion.model.EmotionChangeEvent
6+
import kotlinx.coroutines.flow.Flow
57

68
interface EmotionRepository {
79
suspend fun getEmotions(): Result<List<Emotion>>
810
suspend fun registerEmotion(emotionMarbleType: String): Result<List<EmotionRecommendRoutine>>
911
suspend fun getEmotionMarble(currentDate: String): Result<Emotion?>
12+
suspend fun getEmotionChangeEventFlow(): Flow<EmotionChangeEvent>
1013
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.threegap.bitnagil.domain.emotion.usecase
2+
3+
import com.threegap.bitnagil.domain.emotion.model.EmotionChangeEvent
4+
import com.threegap.bitnagil.domain.emotion.repository.EmotionRepository
5+
import kotlinx.coroutines.flow.Flow
6+
import javax.inject.Inject
7+
8+
class GetEmotionChangeEventFlowUseCase @Inject constructor(
9+
private val repository: EmotionRepository,
10+
) {
11+
suspend operator fun invoke(): Flow<EmotionChangeEvent> = repository.getEmotionChangeEventFlow()
12+
}

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

Lines changed: 12 additions & 1 deletion
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.GetEmotionChangeEventFlowUseCase
67
import com.threegap.bitnagil.domain.emotion.usecase.GetEmotionUseCase
78
import com.threegap.bitnagil.domain.routine.model.RoutineCompletion
89
import com.threegap.bitnagil.domain.routine.model.RoutineCompletionInfo
@@ -45,6 +46,7 @@ class HomeViewModel @Inject constructor(
4546
private val deleteRoutineUseCase: DeleteRoutineUseCase,
4647
private val deleteRoutineByDayUseCase: DeleteRoutineByDayUseCase,
4748
private val getWriteRoutineEventFlowUseCase: GetWriteRoutineEventFlowUseCase,
49+
private val getEmotionChangeEventFlowUseCase: GetEmotionChangeEventFlowUseCase,
4850
) : MviViewModel<HomeState, HomeSideEffect, HomeIntent>(
4951
initState = HomeState(),
5052
savedStateHandle = savedStateHandle,
@@ -55,6 +57,7 @@ class HomeViewModel @Inject constructor(
5557

5658
init {
5759
observeWriteRoutineEvent()
60+
observeEmotionChangeEvent()
5861
observeWeekChanges()
5962
observeRoutineUpdates()
6063
fetchWeeklyRoutines(container.stateFlow.value.currentWeeks)
@@ -234,7 +237,15 @@ class HomeViewModel @Inject constructor(
234237
private fun observeWriteRoutineEvent() {
235238
viewModelScope.launch {
236239
getWriteRoutineEventFlowUseCase().collect {
237-
fetchWeeklyRoutines(container.stateFlow.value.currentWeeks)
240+
fetchWeeklyRoutines(stateFlow.value.currentWeeks)
241+
}
242+
}
243+
}
244+
245+
private fun observeEmotionChangeEvent() {
246+
viewModelScope.launch {
247+
getEmotionChangeEventFlowUseCase().collect {
248+
getMyEmotion(stateFlow.value.selectedDate)
238249
}
239250
}
240251
}

0 commit comments

Comments
 (0)