From a3f6eb45b28466ede1df1c10621a13afcab9d7ff Mon Sep 17 00:00:00 2001 From: jinukeu Date: Thu, 1 Feb 2024 09:59:27 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix/#127:=20getLectureEvaluationList=20?= =?UTF-8?q?=EC=9E=84=EA=B3=84=20=EA=B5=AC=EC=97=AD=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LectureEvaluationViewModel.kt | 66 +++++++++++-------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/feature/lectureevaluation/viewerreporter/src/main/java/com/suwiki/feature/lectureevaluation/viewerreporter/LectureEvaluationViewModel.kt b/feature/lectureevaluation/viewerreporter/src/main/java/com/suwiki/feature/lectureevaluation/viewerreporter/LectureEvaluationViewModel.kt index 06b90209..15a4905e 100644 --- a/feature/lectureevaluation/viewerreporter/src/main/java/com/suwiki/feature/lectureevaluation/viewerreporter/LectureEvaluationViewModel.kt +++ b/feature/lectureevaluation/viewerreporter/src/main/java/com/suwiki/feature/lectureevaluation/viewerreporter/LectureEvaluationViewModel.kt @@ -9,6 +9,8 @@ import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.collections.immutable.toPersistentList import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.lastOrNull +import kotlinx.coroutines.sync.Mutex +import kotlinx.coroutines.sync.withLock import org.orbitmvi.orbit.Container import org.orbitmvi.orbit.ContainerHost import org.orbitmvi.orbit.annotation.OrbitExperimental @@ -17,6 +19,7 @@ import org.orbitmvi.orbit.syntax.simple.intent import org.orbitmvi.orbit.syntax.simple.postSideEffect import org.orbitmvi.orbit.syntax.simple.reduce import org.orbitmvi.orbit.viewmodel.container +import timber.log.Timber import javax.inject.Inject @HiltViewModel @@ -27,6 +30,8 @@ class LectureEvaluationViewModel @Inject constructor( override val container: Container = container(LectureEvaluationState()) + private val mutex: Mutex = Mutex() + private val currentState get() = container.stateFlow.value @@ -81,35 +86,37 @@ class LectureEvaluationViewModel @Inject constructor( majorType: String = currentState.selectedOpenMajor, needClear: Boolean, ) = intent { - val currentList = if (needClear) { - page = 1 - reduce { state.copy(isLoading = true) } - emptyList() - } else { - state.lectureEvaluationList - } - - getLectureEvaluationListUseCase( - RetrieveLectureEvaluationAverageListUseCase.Param( - search = search, - option = LectureAlign.entries[alignPosition].query, - page = page, - majorType = majorType, - ), - ).onSuccess { newList -> - handleGetLectureEvaluationListSuccess( - alignPosition = alignPosition, - majorType = majorType, - currentList = currentList, - newList = newList, - ) - }.onFailure { - postSideEffect(LectureEvaluationSideEffect.HandleException(it)) - } - - if (needClear) { - postSideEffect(LectureEvaluationSideEffect.ScrollToTop) - reduce { state.copy(isLoading = false) } + mutex.withLock { + val currentList = if (needClear) { + page = 1 + reduce { state.copy(isLoading = true) } + emptyList() + } else { + state.lectureEvaluationList + } + + getLectureEvaluationListUseCase( + RetrieveLectureEvaluationAverageListUseCase.Param( + search = search, + option = LectureAlign.entries[alignPosition].query, + page = page, + majorType = majorType, + ), + ).onSuccess { newList -> + handleGetLectureEvaluationListSuccess( + alignPosition = alignPosition, + majorType = majorType, + currentList = currentList, + newList = newList, + ) + }.onFailure { + postSideEffect(LectureEvaluationSideEffect.HandleException(it)) + } + + if (needClear) { + postSideEffect(LectureEvaluationSideEffect.ScrollToTop) + reduce { state.copy(isLoading = false) } + } } } @@ -146,6 +153,7 @@ class LectureEvaluationViewModel @Inject constructor( postSideEffect(LectureEvaluationSideEffect.NavigateLectureEvaluationDetail(id)) } } + private fun showOnboardingBottomSheet() = intent { reduce { state.copy(showOnboardingBottomSheet = true) } } fun hideOnboardingBottomSheet() = intent { reduce { state.copy(showOnboardingBottomSheet = false) } } From b4a5ebf80cab6357c63bad83d8cfd05be435c69c Mon Sep 17 00:00:00 2001 From: jinukeu Date: Thu, 1 Feb 2024 10:02:14 +0900 Subject: [PATCH 2/3] =?UTF-8?q?fix/#127:=20getOpenLectureList=20=EC=9E=84?= =?UTF-8?q?=EA=B3=84=20=EA=B5=AC=EC=97=AD=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../openlecture/OpenLectureViewModel.kt | 66 ++++++++++--------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/feature/timetable/src/main/java/com/suwiki/feature/timetable/openlecture/OpenLectureViewModel.kt b/feature/timetable/src/main/java/com/suwiki/feature/timetable/openlecture/OpenLectureViewModel.kt index d37b885a..68697d52 100644 --- a/feature/timetable/src/main/java/com/suwiki/feature/timetable/openlecture/OpenLectureViewModel.kt +++ b/feature/timetable/src/main/java/com/suwiki/feature/timetable/openlecture/OpenLectureViewModel.kt @@ -13,6 +13,8 @@ import com.suwiki.feature.timetable.navigation.argument.toCellEditorArgument import com.suwiki.feature.timetable.openlecture.model.SchoolLevel import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.collections.immutable.toPersistentList +import kotlinx.coroutines.sync.Mutex +import kotlinx.coroutines.sync.withLock import org.orbitmvi.orbit.Container import org.orbitmvi.orbit.ContainerHost import org.orbitmvi.orbit.annotation.OrbitExperimental @@ -29,6 +31,8 @@ class OpenLectureViewModel @Inject constructor( private val insertTimetableCellUseCase: InsertTimetableCellUseCase, ) : ViewModel(), ContainerHost { + private val mutex: Mutex = Mutex() + override val container: Container = container( OpenLectureState(), ) @@ -144,39 +148,41 @@ class OpenLectureViewModel @Inject constructor( majorType: String = currentState.selectedOpenMajor, needClear: Boolean, ) = intent { - val currentList = when { - needClear -> { - reduce { state.copy(isLoading = true) } - cursorId = 0 - isLast = false - emptyList() - } + mutex.withLock { + val currentList = when { + needClear -> { + reduce { state.copy(isLoading = true) } + cursorId = 0 + isLast = false + emptyList() + } - isLast -> return@intent - else -> state.openLectureList - } + isLast -> return@intent + else -> state.openLectureList + } - getOpenLectureListUseCase( - GetOpenLectureListUseCase.Param( - cursorId = cursorId, - keyword = search, - major = if (majorType == "전체") null else majorType, - grade = schoolLevel.query, - ), - ).onSuccess { newData -> - handleGetOpenLectureListSuccess( - schoolLevel = schoolLevel, - majorType = majorType, - currentList = currentList, - newData = newData, - ) - }.onFailure { - postSideEffect(OpenLectureSideEffect.HandleException(it)) - } + getOpenLectureListUseCase( + GetOpenLectureListUseCase.Param( + cursorId = cursorId, + keyword = search, + major = if (majorType == "전체") null else majorType, + grade = schoolLevel.query, + ), + ).onSuccess { newData -> + handleGetOpenLectureListSuccess( + schoolLevel = schoolLevel, + majorType = majorType, + currentList = currentList, + newData = newData, + ) + }.onFailure { + postSideEffect(OpenLectureSideEffect.HandleException(it)) + } - if (needClear) { - postSideEffect(OpenLectureSideEffect.ScrollToTop) - reduce { state.copy(isLoading = false) } + if (needClear) { + postSideEffect(OpenLectureSideEffect.ScrollToTop) + reduce { state.copy(isLoading = false) } + } } } From 465e41808a5427b615d9029f9d09efc9a3931ada Mon Sep 17 00:00:00 2001 From: jinukeu Date: Thu, 1 Feb 2024 10:12:49 +0900 Subject: [PATCH 3/3] chore/#127: ktlint --- .../viewerreporter/LectureEvaluationViewModel.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/feature/lectureevaluation/viewerreporter/src/main/java/com/suwiki/feature/lectureevaluation/viewerreporter/LectureEvaluationViewModel.kt b/feature/lectureevaluation/viewerreporter/src/main/java/com/suwiki/feature/lectureevaluation/viewerreporter/LectureEvaluationViewModel.kt index 15a4905e..a2f74d76 100644 --- a/feature/lectureevaluation/viewerreporter/src/main/java/com/suwiki/feature/lectureevaluation/viewerreporter/LectureEvaluationViewModel.kt +++ b/feature/lectureevaluation/viewerreporter/src/main/java/com/suwiki/feature/lectureevaluation/viewerreporter/LectureEvaluationViewModel.kt @@ -19,7 +19,6 @@ import org.orbitmvi.orbit.syntax.simple.intent import org.orbitmvi.orbit.syntax.simple.postSideEffect import org.orbitmvi.orbit.syntax.simple.reduce import org.orbitmvi.orbit.viewmodel.container -import timber.log.Timber import javax.inject.Inject @HiltViewModel