From a52c29ec6e9152f0a51701766e0f891f253ca8f2 Mon Sep 17 00:00:00 2001 From: leeseokchan00 <112953135+leeseokchan00@users.noreply.github.com> Date: Thu, 14 Nov 2024 05:04:35 +0900 Subject: [PATCH 1/4] [refactor] #190 toast message --- .../src/main/java/org/sopt/clip/cliplink/ClipLinkFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/feature/clip/src/main/java/org/sopt/clip/cliplink/ClipLinkFragment.kt b/feature/clip/src/main/java/org/sopt/clip/cliplink/ClipLinkFragment.kt index 49914d22..efed8391 100644 --- a/feature/clip/src/main/java/org/sopt/clip/cliplink/ClipLinkFragment.kt +++ b/feature/clip/src/main/java/org/sopt/clip/cliplink/ClipLinkFragment.kt @@ -268,7 +268,7 @@ class ClipLinkFragment : BindingFragment({ FragmentClip DeleteLinkBottomSheetFragment.newInstance( clipId, isFullClipSize, - { requireContext().linkMindSnackBar(binding.vSnack, "클립 하나임", true) }, + { requireContext().linkMindSnackBar(binding.vSnack, "이동할 클립을 하나 이상 생성해 주세요", true) }, handleDeleteButton = { viewModel.deleteLink(linkDTO.toastId) }, From a3866ef8959abba50f6611dfde7c7cf681e46312 Mon Sep 17 00:00:00 2001 From: leeseokchan00 <112953135+leeseokchan00@users.noreply.github.com> Date: Thu, 14 Nov 2024 08:05:37 +0900 Subject: [PATCH 2/4] [refactor] #190 recent saved link --- .../java/org/sopt/home/viewholder/HomeClipViewHolder.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/feature/home/src/main/java/org/sopt/home/viewholder/HomeClipViewHolder.kt b/feature/home/src/main/java/org/sopt/home/viewholder/HomeClipViewHolder.kt index 93395f85..b6e02744 100644 --- a/feature/home/src/main/java/org/sopt/home/viewholder/HomeClipViewHolder.kt +++ b/feature/home/src/main/java/org/sopt/home/viewholder/HomeClipViewHolder.kt @@ -26,10 +26,14 @@ class HomeClipViewHolder( return } with(binding) { + if (data.categoryTitle.isNullOrEmpty()) { + tvLinkClipTitle.isGone = true + } else { + tvLinkClipTitle.isVisible = true + tvLinkClipTitle.text = data.categoryTitle + } tvLinkTitle.text = data.toastTitle tvLinkUrl.text = data.linkUrl - binding.tvLinkTitle.setVisible(!data.categoryTitle.isNullOrEmpty()) - tvLinkClipTitle.text = data.categoryTitle ivLinkThumnail.load(data.thumbnailUrl) tvItemClipLink.setVisible(data.isRead) root.onThrottleClick { From 12ded58ab3ab8a2616e8bee6c1ed21f18a6db068 Mon Sep 17 00:00:00 2001 From: leeseokchan00 <112953135+leeseokchan00@users.noreply.github.com> Date: Thu, 14 Nov 2024 08:40:22 +0900 Subject: [PATCH 3/4] [refactor] #190 clip change --- .../clip/clipchange/ClipChangeFragment.kt | 32 +++++++++++++++---- .../sopt/clip/cliplink/ClipLinkViewModel.kt | 10 ++++++ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/feature/clip/src/main/java/org/sopt/clip/clipchange/ClipChangeFragment.kt b/feature/clip/src/main/java/org/sopt/clip/clipchange/ClipChangeFragment.kt index d6b364a9..32f97528 100644 --- a/feature/clip/src/main/java/org/sopt/clip/clipchange/ClipChangeFragment.kt +++ b/feature/clip/src/main/java/org/sopt/clip/clipchange/ClipChangeFragment.kt @@ -32,6 +32,7 @@ class ClipChangeFragment : getCategoryAll() collectClipState(args) initCloseButtonClickListener() + initNextButtonClickListener() } private fun getCategoryAll() { @@ -76,27 +77,46 @@ class ClipChangeFragment : list.onEach { it.isSelected = false } list[index].isSelected = true binding.btnClipChangeSelectNext.state = LinkMindButtonState.ENABLE + viewModel.updateSelectedCategoryState(toastId, newClipId, true) } else { list.onEach { it.isSelected = false } binding.btnClipChangeSelectNext.state = LinkMindButtonState.DISABLE + viewModel.updateSelectedCategoryState(toastId, newClipId, false) } - - initNextButtonClickListener(toastId, newClipId) } - private fun initNextButtonClickListener(toastId: Long, newClipId: Long) { + private fun initNextButtonClickListener() { binding.btnClipChangeSelectNext.btnClick { - viewModel.patchLinkCategory(toastId = toastId, categoryId = newClipId) + collectSelectedCategoryState() findNavController().popBackStack() } } + private fun collectSelectedCategoryState() { + viewModel.selectedCategory.flowWithLifecycle(viewLifeCycle).onEach { state -> + when (state) { + is UiState.Success -> { + viewModel.patchLinkCategory(toastId = state.data.first, categoryId = state.data.second) + } + + else -> {} + } + }.launchIn(viewLifeCycleScope) + } + private fun initCloseButtonClickListener() { binding.ivClipChangeClose.onThrottleClick { findNavController().popBackStack() } } - private fun excludeCurrentClipId(clipList: List, currentClipId: Long): List = - clipList.filter { it.id != currentClipId } + private fun excludeCurrentClipId(clipList: List, currentClipId: Long): List { + val updatedList = clipList.drop(1) + val currentClip = updatedList.find { it.id == currentClipId } + val resultList = updatedList.filter { it.id != currentClipId }.toMutableList() + currentClip?.let { + resultList.add(0, it) + } + return resultList + } } diff --git a/feature/clip/src/main/java/org/sopt/clip/cliplink/ClipLinkViewModel.kt b/feature/clip/src/main/java/org/sopt/clip/cliplink/ClipLinkViewModel.kt index 9d90c454..1849407e 100644 --- a/feature/clip/src/main/java/org/sopt/clip/cliplink/ClipLinkViewModel.kt +++ b/feature/clip/src/main/java/org/sopt/clip/cliplink/ClipLinkViewModel.kt @@ -42,6 +42,9 @@ class ClipLinkViewModel @Inject constructor( private val _categoryState = MutableStateFlow>>(UiState.Empty) val categoryState: StateFlow>> = _categoryState.asStateFlow() + private val _selectedCategory = MutableStateFlow>>(UiState.Empty) + val selectedCategory: StateFlow>> = _selectedCategory.asStateFlow() + private val _patchLinkCategory = MutableStateFlow>(UiState.Empty) val patchLinkCategory: StateFlow> = _patchLinkCategory.asStateFlow() @@ -99,6 +102,13 @@ class ClipLinkViewModel @Inject constructor( } } + fun updateSelectedCategoryState(toastId: Long, newClipId: Long, isSelected: Boolean) = viewModelScope.launch { + when (isSelected) { + true -> _selectedCategory.emit(UiState.Success(Pair(toastId, newClipId))) + false -> _selectedCategory.emit(UiState.Empty) + } + } + fun initState() { _linkState.value = UiState.Empty _patchLinkCategory.value = UiState.Empty From d0841e8b64d47c40e90b42a2e3cb3e20666061c6 Mon Sep 17 00:00:00 2001 From: leeseokchan00 <112953135+leeseokchan00@users.noreply.github.com> Date: Thu, 14 Nov 2024 08:44:56 +0900 Subject: [PATCH 4/4] [refactor] #190 ktlint --- .../src/main/java/org/sopt/clip/cliplink/ClipLinkViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/feature/clip/src/main/java/org/sopt/clip/cliplink/ClipLinkViewModel.kt b/feature/clip/src/main/java/org/sopt/clip/cliplink/ClipLinkViewModel.kt index 1849407e..a792f120 100644 --- a/feature/clip/src/main/java/org/sopt/clip/cliplink/ClipLinkViewModel.kt +++ b/feature/clip/src/main/java/org/sopt/clip/cliplink/ClipLinkViewModel.kt @@ -108,7 +108,7 @@ class ClipLinkViewModel @Inject constructor( false -> _selectedCategory.emit(UiState.Empty) } } - + fun initState() { _linkState.value = UiState.Empty _patchLinkCategory.value = UiState.Empty