Skip to content

Commit

Permalink
[FEAT/#49] connect observer and delete distinctUtilChanged
Browse files Browse the repository at this point in the history
  • Loading branch information
chattymin committed Sep 10, 2024
1 parent eb9eeb8 commit 94a149c
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class RhythmFragment : BaseFragment<FragmentRhythmBinding>(R.layout.fragment_rhy
initPlayBtnListener()
initStopBtnListener()
initWearableSyncBtnListener()
observeStepCount()
observeRhythmLevel()
observeRhythmUrlState()
observeDownloadState()
Expand Down Expand Up @@ -119,6 +120,12 @@ class RhythmFragment : BaseFragment<FragmentRhythmBinding>(R.layout.fragment_rhy
}
}

private fun observeStepCount() {
viewModel.stepCount.flowWithLifecycle(lifecycle).distinctUntilChanged().onEach { level ->
binding.tvRhythmStep.text = viewModel.stepCount.value.toString()
}.launchIn(lifecycleScope)
}

private fun observeRhythmLevel() {
viewModel.rhythmLevel.flowWithLifecycle(lifecycle).distinctUntilChanged().onEach { level ->
if (level == LEVEL_UNDEFINED) return@onEach
Expand Down Expand Up @@ -237,8 +244,7 @@ class RhythmFragment : BaseFragment<FragmentRhythmBinding>(R.layout.fragment_rhy
}

private fun observeRecordSaveState() {
viewModel.isRecordSaved.flowWithLifecycle(lifecycle).distinctUntilChanged()
.onEach { isSuccess ->
viewModel.isRecordSaved.flowWithLifecycle(lifecycle).onEach { isSuccess ->
if (isSuccess) {
toast(stringOf(R.string.rhythm_toast_save_success))
} else {
Expand Down

0 comments on commit 94a149c

Please sign in to comment.