Skip to content

Commit 4244167

Browse files
authored
Merge pull request #64 from YAPP-Github/feature/#63-refresh_home
[Feature/#63] 루틴 등록/수정시 홈 화면 리프레시 기능 구현
2 parents ea90e62 + 5bdd146 commit 4244167

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

data/src/main/java/com/threegap/bitnagil/data/writeroutine/repositoryImpl/WriteRoutineRepositoryImpl.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import com.threegap.bitnagil.data.writeroutine.model.request.RegisterRoutineRequ
77
import com.threegap.bitnagil.domain.writeroutine.model.RepeatDay
88
import com.threegap.bitnagil.domain.writeroutine.model.SubRoutineDiff
99
import com.threegap.bitnagil.domain.writeroutine.model.Time
10+
import com.threegap.bitnagil.domain.writeroutine.model.WriteRoutineEvent
1011
import com.threegap.bitnagil.domain.writeroutine.repository.WriteRoutineRepository
12+
import kotlinx.coroutines.flow.Flow
13+
import kotlinx.coroutines.flow.MutableSharedFlow
14+
import kotlinx.coroutines.flow.asSharedFlow
1115
import javax.inject.Inject
1216

1317
class WriteRoutineRepositoryImpl @Inject constructor(
@@ -20,7 +24,11 @@ class WriteRoutineRepositoryImpl @Inject constructor(
2024
executionTime = startTime.toFormattedString(),
2125
subRoutineName = subRoutines,
2226
)
23-
return writeRoutineDataSource.registerRoutine(request)
27+
return writeRoutineDataSource.registerRoutine(request).also {
28+
if (it.isSuccess) {
29+
_writeRoutineEventFlow.emit(WriteRoutineEvent.AddRoutine)
30+
}
31+
}
2432
}
2533

2634
override suspend fun editRoutine(
@@ -40,6 +48,13 @@ class WriteRoutineRepositoryImpl @Inject constructor(
4048
},
4149
)
4250

43-
return writeRoutineDataSource.editRoutine(request)
51+
return writeRoutineDataSource.editRoutine(request).also {
52+
if (it.isSuccess) {
53+
_writeRoutineEventFlow.emit(WriteRoutineEvent.EditRoutine(routineId))
54+
}
55+
}
4456
}
57+
58+
private val _writeRoutineEventFlow = MutableSharedFlow<WriteRoutineEvent>()
59+
override suspend fun getWriteRoutineEventFlow(): Flow<WriteRoutineEvent> = _writeRoutineEventFlow.asSharedFlow()
4560
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.threegap.bitnagil.domain.writeroutine.model
2+
3+
sealed interface WriteRoutineEvent {
4+
data object AddRoutine : WriteRoutineEvent
5+
data class EditRoutine(val routineId: String) : WriteRoutineEvent
6+
}

domain/src/main/java/com/threegap/bitnagil/domain/writeroutine/repository/WriteRoutineRepository.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package com.threegap.bitnagil.domain.writeroutine.repository
33
import com.threegap.bitnagil.domain.writeroutine.model.RepeatDay
44
import com.threegap.bitnagil.domain.writeroutine.model.SubRoutineDiff
55
import com.threegap.bitnagil.domain.writeroutine.model.Time
6+
import com.threegap.bitnagil.domain.writeroutine.model.WriteRoutineEvent
7+
import kotlinx.coroutines.flow.Flow
68

79
interface WriteRoutineRepository {
810
suspend fun registerRoutine(
@@ -19,4 +21,6 @@ interface WriteRoutineRepository {
1921
startTime: Time,
2022
subRoutines: List<SubRoutineDiff>,
2123
): Result<Unit>
24+
25+
suspend fun getWriteRoutineEventFlow(): Flow<WriteRoutineEvent>
2226
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.threegap.bitnagil.domain.writeroutine.usecase
2+
3+
import com.threegap.bitnagil.domain.writeroutine.model.WriteRoutineEvent
4+
import com.threegap.bitnagil.domain.writeroutine.repository.WriteRoutineRepository
5+
import kotlinx.coroutines.flow.Flow
6+
import javax.inject.Inject
7+
8+
class GetWriteRoutineEventFlowUseCase @Inject constructor(
9+
private val repository: WriteRoutineRepository,
10+
) {
11+
suspend operator fun invoke(): Flow<WriteRoutineEvent> = repository.getWriteRoutineEventFlow()
12+
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.threegap.bitnagil.domain.routine.usecase.DeleteRoutineUseCase
1111
import com.threegap.bitnagil.domain.routine.usecase.FetchWeeklyRoutinesUseCase
1212
import com.threegap.bitnagil.domain.routine.usecase.RoutineCompletionUseCase
1313
import com.threegap.bitnagil.domain.user.usecase.FetchUserProfileUseCase
14+
import com.threegap.bitnagil.domain.writeroutine.usecase.GetWriteRoutineEventFlowUseCase
1415
import com.threegap.bitnagil.presentation.common.mviviewmodel.MviViewModel
1516
import com.threegap.bitnagil.presentation.home.model.EmotionBallType
1617
import com.threegap.bitnagil.presentation.home.model.HomeIntent
@@ -43,6 +44,7 @@ class HomeViewModel @Inject constructor(
4344
private val routineCompletionUseCase: RoutineCompletionUseCase,
4445
private val deleteRoutineUseCase: DeleteRoutineUseCase,
4546
private val deleteRoutineByDayUseCase: DeleteRoutineByDayUseCase,
47+
private val getWriteRoutineEventFlowUseCase: GetWriteRoutineEventFlowUseCase,
4648
) : MviViewModel<HomeState, HomeSideEffect, HomeIntent>(
4749
initState = HomeState(),
4850
savedStateHandle = savedStateHandle,
@@ -52,6 +54,7 @@ class HomeViewModel @Inject constructor(
5254
private val routineSyncTrigger = MutableSharedFlow<LocalDate>()
5355

5456
init {
57+
observeWriteRoutineEvent()
5558
observeWeekChanges()
5659
observeRoutineUpdates()
5760
fetchWeeklyRoutines(container.stateFlow.value.currentWeeks)
@@ -228,6 +231,14 @@ class HomeViewModel @Inject constructor(
228231
return newState
229232
}
230233

234+
private fun observeWriteRoutineEvent() {
235+
viewModelScope.launch {
236+
getWriteRoutineEventFlowUseCase().collect {
237+
fetchWeeklyRoutines(container.stateFlow.value.currentWeeks)
238+
}
239+
}
240+
}
241+
231242
@OptIn(FlowPreview::class)
232243
private fun observeWeekChanges() {
233244
viewModelScope.launch {

0 commit comments

Comments
 (0)