From a81e6677e725d12a5fc1274db5eaa1b376b704ef Mon Sep 17 00:00:00 2001 From: ki960213 Date: Thu, 2 Nov 2023 01:41:43 +0900 Subject: [PATCH] =?UTF-8?q?feat(ChildCommentViewModel):=20=EC=83=88?= =?UTF-8?q?=EB=A1=9C=EA=B3=A0=EC=B9=A8=20=EC=8B=9C=EC=97=94=20=EB=84=A4?= =?UTF-8?q?=ED=8A=B8=EC=9B=8C=ED=81=AC=20=EC=97=90=EB=9F=AC=EC=97=90=20?= =?UTF-8?q?=EC=9D=98=ED=95=B4=20=EC=83=88=EB=A1=9C=EA=B3=A0=EC=B9=A8=20?= =?UTF-8?q?=ED=95=A0=20=EC=88=98=20=EC=97=86=EC=96=B4=EB=8F=84=20=EB=84=A4?= =?UTF-8?q?=ED=8A=B8=EC=9B=8C=ED=81=AC=20=ED=99=94=EB=A9=B4=EC=9D=84=20?= =?UTF-8?q?=EB=B3=B4=EC=97=AC=EC=A3=BC=EC=A7=80=20=EC=95=8A=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/emmsale/presentation/base/BaseViewModel.kt | 6 ++++-- .../ui/childCommentList/ChildCommentViewModel.kt | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/android/2023-emmsale/app/src/main/java/com/emmsale/presentation/base/BaseViewModel.kt b/android/2023-emmsale/app/src/main/java/com/emmsale/presentation/base/BaseViewModel.kt index 6ccbb5eb3..df6fbb328 100644 --- a/android/2023-emmsale/app/src/main/java/com/emmsale/presentation/base/BaseViewModel.kt +++ b/android/2023-emmsale/app/src/main/java/com/emmsale/presentation/base/BaseViewModel.kt @@ -29,12 +29,13 @@ abstract class BaseViewModel : ViewModel() { onSuccess: ((T) -> Unit)? = null, onFailure: ((code: Int, message: String?) -> Unit)? = null, onLoading: (suspend () -> Unit)? = null, + onNetworkError: (() -> Unit)? = null, ): Job = viewModelScope.launch { val loadingJob = launch { onLoading?.invoke() ?: changeToLoadingState() } when (val result = getResult()) { is Failure -> onFailure?.invoke(result.code, result.message) NetworkError -> { - changeToNetworkErrorState() + onNetworkError?.invoke() ?: changeToNetworkErrorState() return@launch } @@ -50,11 +51,12 @@ abstract class BaseViewModel : ViewModel() { onSuccess: ((T) -> Unit)? = null, onFailure: ((code: Int, message: String?) -> Unit)? = null, onLoading: (suspend () -> Unit)? = null, + onNetworkError: (() -> Unit)? = null, ): Job = viewModelScope.launch { val loadingJob = launch { onLoading?.invoke() ?: changeToLoadingState() } when (val result = command()) { is Failure -> onFailure?.invoke(result.code, result.message) - NetworkError -> onRequestFailByNetworkError() + NetworkError -> onNetworkError?.invoke() ?: onRequestFailByNetworkError() is Success -> { refresh().join() onSuccess?.invoke(result.data) diff --git a/android/2023-emmsale/app/src/main/java/com/emmsale/presentation/ui/childCommentList/ChildCommentViewModel.kt b/android/2023-emmsale/app/src/main/java/com/emmsale/presentation/ui/childCommentList/ChildCommentViewModel.kt index e9a6d1a3e..6aa300ed8 100644 --- a/android/2023-emmsale/app/src/main/java/com/emmsale/presentation/ui/childCommentList/ChildCommentViewModel.kt +++ b/android/2023-emmsale/app/src/main/java/com/emmsale/presentation/ui/childCommentList/ChildCommentViewModel.kt @@ -123,6 +123,7 @@ class ChildCommentViewModel @Inject constructor( onSuccess = { _comments.value = ChildCommentsUiState.create(uid, parentComment = it) }, onFailure = { _, _ -> }, onLoading = {}, + onNetworkError = ::onRequestFailByNetworkError, ) override fun changeToLoadingState() {