Skip to content

Commit

Permalink
[refactor] #185 refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
leeseokchan00 committed Nov 6, 2024
1 parent 75d6ae7 commit e0add56
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
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,21 +77,33 @@ 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()
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 @@ -196,14 +196,14 @@ class WebViewFragment : BindingFragment<FragmentWebviewBinding>({ FragmentWebvie
}
}

private fun initShareBtnClickListener(){
private fun initShareBtnClickListener() {
binding.ivShared.onThrottleClick {
val toasterShareIntent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, args.site)
type = "text/plain"
}
startActivity(Intent.createChooser(toasterShareIntent,null))
startActivity(Intent.createChooser(toasterShareIntent, null))
}
}

Expand Down
2 changes: 1 addition & 1 deletion feature/home/src/main/java/org/sopt/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>({ FragmentHomeBinding.
navigateToSetting()
navigateToSearch()
navigateToAllClip()
viewModel.checkMarketUpdateState()
}

private fun initView() {
Expand Down Expand Up @@ -89,7 +90,6 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>({ FragmentHomeBinding.
getRecentSavedClip()
getWeekBestLink()
getPopupListInfo()
checkMarketUpdateState()
}
}

Expand Down
3 changes: 2 additions & 1 deletion feature/home/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_arrow_black_svg"
android:paddingBottom="7dp"
android:paddingStart="40dp"
android:paddingEnd="26dp"
android:paddingVertical="7dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="@id/tv_home_user_clip_name"/>

Expand Down

0 comments on commit e0add56

Please sign in to comment.