Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor] #190 qa #191

Merged
merged 4 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class ClipChangeFragment :
getCategoryAll()
collectClipState(args)
initCloseButtonClickListener()
initNextButtonClickListener()
}

private fun getCategoryAll() {
Expand Down Expand Up @@ -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<Clip>, currentClipId: Long): List<Clip> =
clipList.filter { it.id != currentClipId }
private fun excludeCurrentClipId(clipList: List<Clip>, currentClipId: Long): List<Clip> {
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class ClipLinkFragment : BindingFragment<FragmentClipLinkBinding>({ FragmentClip
DeleteLinkBottomSheetFragment.newInstance(
clipId,
isFullClipSize,
{ requireContext().linkMindSnackBar(binding.vSnack, "ํด๋ฆฝ ํ•˜๋‚˜์ž„", true) },
{ requireContext().linkMindSnackBar(binding.vSnack, "์ด๋™ํ•  ํด๋ฆฝ์„ ํ•˜๋‚˜ ์ด์ƒ ์ƒ์„ฑํ•ด ์ฃผ์„ธ์š”", true) },
handleDeleteButton = {
viewModel.deleteLink(linkDTO.toastId)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class ClipLinkViewModel @Inject constructor(
private val _categoryState = MutableStateFlow<UiState<List<Category>>>(UiState.Empty)
val categoryState: StateFlow<UiState<List<Category>>> = _categoryState.asStateFlow()

private val _selectedCategory = MutableStateFlow<UiState<Pair<Long, Long>>>(UiState.Empty)
val selectedCategory: StateFlow<UiState<Pair<Long, Long>>> = _selectedCategory.asStateFlow()

private val _patchLinkCategory = MutableStateFlow<UiState<Long>>(UiState.Empty)
val patchLinkCategory: StateFlow<UiState<Long>> = _patchLinkCategory.asStateFlow()

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading