-
Notifications
You must be signed in to change notification settings - Fork 0
[Refactor/#192] DailyEmotion 데이터 흐름 개선 #193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,23 @@ | ||
| package com.threegap.bitnagil.domain.emotion.model | ||
|
|
||
| import java.time.LocalDate | ||
|
|
||
| data class DailyEmotion( | ||
| val type: EmotionMarbleType?, | ||
| val name: String?, | ||
| val imageUrl: String?, | ||
| val homeMessage: String?, | ||
| ) | ||
| val fetchedDate: LocalDate = LocalDate.MIN, | ||
| ) { | ||
| fun isStale(today: LocalDate): Boolean = fetchedDate != today | ||
|
|
||
| companion object { | ||
| val INIT = DailyEmotion( | ||
| type = null, | ||
| name = null, | ||
| imageUrl = null, | ||
| homeMessage = null, | ||
| fetchedDate = LocalDate.MIN, | ||
| ) | ||
| } | ||
| } |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,8 +2,7 @@ package com.threegap.bitnagil.presentation.screen.home | |
|
|
||
| import android.util.Log | ||
| import androidx.lifecycle.ViewModel | ||
| import com.threegap.bitnagil.domain.emotion.usecase.FetchDailyEmotionUseCase | ||
| import com.threegap.bitnagil.domain.emotion.usecase.GetEmotionChangeEventFlowUseCase | ||
| import com.threegap.bitnagil.domain.emotion.usecase.ObserveDailyEmotionUseCase | ||
| import com.threegap.bitnagil.domain.onboarding.usecase.GetOnBoardingRecommendRoutineEventFlowUseCase | ||
| import com.threegap.bitnagil.domain.routine.model.RoutineCompletionInfo | ||
| import com.threegap.bitnagil.domain.routine.model.RoutineCompletionInfos | ||
|
|
@@ -34,23 +33,37 @@ import javax.inject.Inject | |
|
|
||
| @HiltViewModel | ||
| class HomeViewModel @Inject constructor( | ||
| private val observeDailyEmotionUseCase: ObserveDailyEmotionUseCase, | ||
| private val fetchWeeklyRoutinesUseCase: FetchWeeklyRoutinesUseCase, | ||
| private val fetchUserProfileUseCase: FetchUserProfileUseCase, | ||
| private val fetchDailyEmotionUseCase: FetchDailyEmotionUseCase, | ||
| private val routineCompletionUseCase: RoutineCompletionUseCase, | ||
| private val getWriteRoutineEventFlowUseCase: GetWriteRoutineEventFlowUseCase, | ||
| private val getEmotionChangeEventFlowUseCase: GetEmotionChangeEventFlowUseCase, | ||
| private val getOnBoardingRecommendRoutineEventFlowUseCase: GetOnBoardingRecommendRoutineEventFlowUseCase, | ||
| private val toggleRoutineUseCase: ToggleRoutineUseCase, | ||
| ) : ContainerHost<HomeState, HomeSideEffect>, ViewModel() { | ||
|
|
||
| override val container: Container<HomeState, HomeSideEffect> = container(initialState = HomeState.INIT) | ||
| override val container: Container<HomeState, HomeSideEffect> = | ||
| container( | ||
| initialState = HomeState.INIT, | ||
| buildSettings = { repeatOnSubscribedStopTimeout = 5_000L }, | ||
| ) | ||
|
|
||
| private val pendingChangesByDate = mutableMapOf<String, MutableMap<String, RoutineCompletionInfo>>() | ||
| private val routineSyncTrigger = MutableSharedFlow<String>(extraBufferCapacity = 64) | ||
|
|
||
| init { | ||
| initialize() | ||
| observeDailyEmotion() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [2] RecommendRoutineViewModel에서는 container의 onCreate 블록에 observeDailyEmotion을 배치했는데, 여기에서는 init 블록에 배치한 이유가 있으신가요?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 기술적인 이유보단 |
||
| } | ||
|
|
||
| private fun observeDailyEmotion() { | ||
| intent { | ||
| repeatOnSubscription { | ||
| observeDailyEmotionUseCase() | ||
| .map { it.toUiModel() } | ||
| .collect { reduce { state.copy(dailyEmotion = it) } } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fun selectDate(data: LocalDate) { | ||
|
|
@@ -186,10 +199,8 @@ class HomeViewModel @Inject constructor( | |
| intent { | ||
| coroutineScope { | ||
| launch { fetchUserProfile() } | ||
| launch { fetchDailyEmotion() } | ||
| launch { fetchWeeklyRoutines(state.currentWeeks) } | ||
| launch { observeWriteRoutineEvent() } | ||
| launch { observeEmotionChangeEvent() } | ||
| launch { observeRecommendRoutineEvent() } | ||
| launch { observeWeekChanges() } | ||
| launch { observeRoutineUpdates() } | ||
|
|
@@ -205,14 +216,6 @@ class HomeViewModel @Inject constructor( | |
| } | ||
| } | ||
|
|
||
| private suspend fun observeEmotionChangeEvent() { | ||
| subIntent { | ||
| getEmotionChangeEventFlowUseCase().collect { | ||
| fetchDailyEmotion() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private suspend fun observeRecommendRoutineEvent() { | ||
| subIntent { | ||
| getOnBoardingRecommendRoutineEventFlowUseCase().collect { | ||
|
|
@@ -278,21 +281,6 @@ class HomeViewModel @Inject constructor( | |
| } | ||
| } | ||
|
|
||
| private suspend fun fetchDailyEmotion() { | ||
| subIntent { | ||
| reduce { state.copy(loadingCount = state.loadingCount + 1) } | ||
| fetchDailyEmotionUseCase().fold( | ||
| onSuccess = { | ||
| reduce { state.copy(dailyEmotion = it.toUiModel(), loadingCount = state.loadingCount - 1) } | ||
| }, | ||
| onFailure = { | ||
| Log.e("HomeViewModel", "나의 감정 실패: ${it.message}") | ||
| reduce { state.copy(loadingCount = state.loadingCount - 1) } | ||
| }, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| private fun syncRoutineChangesForDate(dateKey: String) { | ||
| intent { | ||
| val dateChanges = pendingChangesByDate.remove(dateKey) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.