From 894bbf626de4ca1ce6b90f3d6ef506b6ca8f29b4 Mon Sep 17 00:00:00 2001 From: lsakee <93514333+lsakee@users.noreply.github.com> Date: Wed, 6 Mar 2024 23:08:31 +0900 Subject: [PATCH] =?UTF-8?q?[refactor]=20:=20#159=20=EB=B2=84=ED=8A=BC=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=20=ED=81=B4=EB=A6=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SaveLinkSetClipFragment.kt | 14 +++------- .../ui/savelinksetclip/SetLinkViewModel.kt | 27 ++++++++++++------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/feature/savelink/src/main/java/org/sopt/savelink/ui/savelinksetclip/SaveLinkSetClipFragment.kt b/feature/savelink/src/main/java/org/sopt/savelink/ui/savelinksetclip/SaveLinkSetClipFragment.kt index 5b6325d9..c97e2434 100644 --- a/feature/savelink/src/main/java/org/sopt/savelink/ui/savelinksetclip/SaveLinkSetClipFragment.kt +++ b/feature/savelink/src/main/java/org/sopt/savelink/ui/savelinksetclip/SaveLinkSetClipFragment.kt @@ -1,6 +1,7 @@ package org.sopt.savelink.ui.savelinksetclip import android.os.Bundle +import android.util.Log import android.view.View import androidx.fragment.app.viewModels import androidx.lifecycle.viewModelScope @@ -11,8 +12,6 @@ import designsystem.components.button.state.LinkMindButtonState import designsystem.components.dialog.LinkMindDialog import designsystem.components.toast.linkMindSnackBar import kotlinx.coroutines.launch -import kotlinx.coroutines.sync.Mutex -import kotlinx.coroutines.sync.withLock import org.orbitmvi.orbit.viewmodel.observe import org.sopt.mainfeature.R import org.sopt.savelink.databinding.FragmentSaveLinkSetClipBinding @@ -110,18 +109,13 @@ class SaveLinkSetClipFragment : BindingFragment( viewModel.showDialog() } } - private val mutex = Mutex() + private fun onClickCompleteBtn() { binding.btnSaveLinkComplete.apply { btnClick { if (state == LinkMindButtonState.DISABLE) return@btnClick - - if (!mutex.isLocked) { - viewModel.viewModelScope.launch { - mutex.withLock { - viewModel.saveLink(viewModel.container.stateFlow.value.url, viewModel.container.stateFlow.value.categoryId) - } - } + viewModel.viewModelScope.launch { + viewModel.saveLink(viewModel.container.stateFlow.value.url, viewModel.container.stateFlow.value.categoryId) } } } diff --git a/feature/savelink/src/main/java/org/sopt/savelink/ui/savelinksetclip/SetLinkViewModel.kt b/feature/savelink/src/main/java/org/sopt/savelink/ui/savelinksetclip/SetLinkViewModel.kt index fe3cab1c..760dfac3 100644 --- a/feature/savelink/src/main/java/org/sopt/savelink/ui/savelinksetclip/SetLinkViewModel.kt +++ b/feature/savelink/src/main/java/org/sopt/savelink/ui/savelinksetclip/SetLinkViewModel.kt @@ -5,6 +5,8 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch +import kotlinx.coroutines.sync.Mutex +import kotlinx.coroutines.sync.withLock import org.orbitmvi.orbit.Container import org.orbitmvi.orbit.ContainerHost import org.orbitmvi.orbit.syntax.simple.intent @@ -85,17 +87,22 @@ class SetLinkViewModel @Inject constructor( } } + private val mutex = Mutex() fun saveLink(linkUrl: String, categoryId: Long?) = viewModelScope.launch { - saveLinkUseCase( - PostSaveLinkUseCase.Param( - linkUrl = linkUrl, - categoryId = if (categoryId == 0.toLong()) null else categoryId, - ), - ).onSuccess { - navigateSetLink() - if (it != 201) showSnackBar() - }.onFailure { - showSnackBar() + if (!mutex.isLocked) { + mutex.withLock { + saveLinkUseCase( + PostSaveLinkUseCase.Param( + linkUrl = linkUrl, + categoryId = if (categoryId == 0.toLong()) null else categoryId, + ), + ).onSuccess { + navigateSetLink() + if (it != 201) showSnackBar() + }.onFailure { + showSnackBar() + } + } } }