Skip to content

Commit

Permalink
Merge pull request #162 from Link-MIND/refactor/#159-qa
Browse files Browse the repository at this point in the history
[refactor] : #159 버튼 중복 클릭
  • Loading branch information
lsakee authored Mar 7, 2024
2 parents 02cee44 + b091b2e commit c9a2dec
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {

defaultConfig {
applicationId = "org.sopt.linkmind"
versionCode = 7
versionCode = 8
versionName = "1.0.1"
}
viewBinding.enable = true
Expand Down
2 changes: 2 additions & 0 deletions core/ui/src/main/java/org/sopt/ui/base/BindingFragment.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.sopt.ui.base

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -13,6 +14,7 @@ abstract class BindingFragment<T : ViewBinding>(
private var _binding: T? = null
protected val binding
get() = requireNotNull(_binding) {
Log.d("error", "$_binding")
}

override fun onCreateView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ class WebViewFragment : BindingFragment<FragmentWebviewBinding>({ FragmentWebvie
wbClip.webViewClient = object : WebViewClient() {
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
super.onPageStarted(view, url, favicon)

runCatching { updateColors() }
}
}
Expand Down
3 changes: 3 additions & 0 deletions feature/home/src/main/java/org/sopt/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>({ FragmentHomeBinding.
"featureSaveLink://ClipLinkFragment/${viewModel.container.stateFlow.value.categoryId}/${viewModel.container.stateFlow.value.categoryName}",
)
is HomeSideEffect.ShowBottomSheet -> showHomeBottomSheet()
is HomeSideEffect.NavigateWebView -> navigateToDestination(
"featureSaveLink://webViewFragment?site=${viewModel.container.stateFlow.value.url},,,${0},,,false",
)
is HomeSideEffect.NavigateWebView -> {
val encodedURL = URLEncoder.encode(viewModel.container.stateFlow.value.url, StandardCharsets.UTF_8.toString())
navigateToDestination(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package org.sopt.savelink.ui.savelinksetclip
import android.os.Bundle
import android.view.View
import androidx.fragment.app.viewModels
import androidx.lifecycle.viewModelScope
import androidx.navigation.fragment.findNavController
import dagger.hilt.android.AndroidEntryPoint
import designsystem.components.bottomsheet.LinkMindBottomSheet
import designsystem.components.button.state.LinkMindButtonState
import designsystem.components.dialog.LinkMindDialog
import designsystem.components.toast.linkMindSnackBar
import kotlinx.coroutines.launch
import org.orbitmvi.orbit.viewmodel.observe
import org.sopt.mainfeature.R
import org.sopt.savelink.databinding.FragmentSaveLinkSetClipBinding
Expand Down Expand Up @@ -111,7 +113,9 @@ class SaveLinkSetClipFragment : BindingFragment<FragmentSaveLinkSetClipBinding>(
binding.btnSaveLinkComplete.apply {
btnClick {
if (state == LinkMindButtonState.DISABLE) return@btnClick
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)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ class TimerFragment : BindingFragment<FragmentTimerBinding>({ FragmentTimerBindi
is UiState.Failure -> {}
is UiState.Empty -> {}
is UiState.Loading -> {}
else -> {}
}
}.launchIn(viewLifeCycleScope)
}
Expand Down

0 comments on commit c9a2dec

Please sign in to comment.