diff --git a/app/src/main/java/com/ftw/hometerview/ui/withdrawal/WithdrawalActivity.kt b/app/src/main/java/com/ftw/hometerview/ui/withdrawal/WithdrawalActivity.kt index dfaf6ec..8bce959 100644 --- a/app/src/main/java/com/ftw/hometerview/ui/withdrawal/WithdrawalActivity.kt +++ b/app/src/main/java/com/ftw/hometerview/ui/withdrawal/WithdrawalActivity.kt @@ -40,19 +40,6 @@ class WithdrawalActivity : AppCompatActivity() { } private fun observe() { - lifecycleScope.launch { - repeatOnLifecycle(Lifecycle.State.STARTED) { - viewModel.event.collect { event -> - when (event) { - WithdrawalViewModel.Event.None -> {} - WithdrawalViewModel.Event.OnClickWithdrawalFirstCheck -> onClickWithdrawalFirstCheck() - WithdrawalViewModel.Event.OnClickWithdrawalSecondCheck -> onClickWithdrawalSecondCheck() - WithdrawalViewModel.Event.OnClickWithdrawalThirdCheck -> onClickWithdrawalThirdCheck() - } - } - } - } - lifecycleScope.launch { repeatOnLifecycle(Lifecycle.State.STARTED) { viewModel.withdrawalCheck.collect { showBanner -> @@ -61,45 +48,4 @@ class WithdrawalActivity : AppCompatActivity() { } } } - - private fun onClickWithdrawalFirstCheck() { - if (viewModel.withdrawalFirstCheck.value) { - viewModel.withdrawalFirstCheck.value = false - binding.withdrawalFirstCheck.setImageResource(R.drawable.icon_check_disabled) - } else { - viewModel.withdrawalFirstCheck.value = true - binding.withdrawalFirstCheck.setImageResource(R.drawable.icon_check_enabled) - } - viewModel.withdrawalCheck.value = withdrawalCheck() - } - - private fun onClickWithdrawalSecondCheck() { - if (viewModel.withdrawalSecondCheck.value) { - viewModel.withdrawalSecondCheck.value = false - binding.withdrawalSecondCheck.setImageResource(R.drawable.icon_check_disabled) - } else { - viewModel.withdrawalSecondCheck.value = true - binding.withdrawalSecondCheck.setImageResource(R.drawable.icon_check_enabled) - } - viewModel.withdrawalCheck.value = withdrawalCheck() - } - - private fun onClickWithdrawalThirdCheck() { - if (viewModel.withdrawalThirdCheck.value) { - viewModel.withdrawalThirdCheck.value = false - binding.withdrawalThirdCheck.setImageResource(R.drawable.icon_check_disabled) - } else { - viewModel.withdrawalThirdCheck.value = true - binding.withdrawalThirdCheck.setImageResource(R.drawable.icon_check_enabled) - } - viewModel.withdrawalCheck.value = withdrawalCheck() - } - - private fun withdrawalCheck(): Boolean { - if (viewModel.withdrawalFirstCheck.value - && viewModel.withdrawalSecondCheck.value - && viewModel.withdrawalThirdCheck.value - ) return true - return false - } } diff --git a/app/src/main/java/com/ftw/hometerview/ui/withdrawal/WithdrawalViewModel.kt b/app/src/main/java/com/ftw/hometerview/ui/withdrawal/WithdrawalViewModel.kt index 2150203..ebc38ba 100644 --- a/app/src/main/java/com/ftw/hometerview/ui/withdrawal/WithdrawalViewModel.kt +++ b/app/src/main/java/com/ftw/hometerview/ui/withdrawal/WithdrawalViewModel.kt @@ -1,42 +1,43 @@ package com.ftw.hometerview.ui.withdrawal +import com.ftw.hometerview.BR +import com.ftw.hometerview.R +import com.ftw.hometerview.adapter.RecyclerItem import com.ftw.hometerview.dispatcher.Dispatcher -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.asStateFlow +import com.ftw.hometerview.ui.main.favorite.favoritelist.FavoriteBuildingItem +import com.ftw.hometerview.ui.main.favorite.favoritelist.FavoriteBuildingsViewModel +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.flow.* class WithdrawalViewModel( dispatcher: Dispatcher ) { - sealed class Event { - object None : Event() - object OnClickWithdrawalFirstCheck : Event() - object OnClickWithdrawalSecondCheck : Event() - object OnClickWithdrawalThirdCheck : Event() - } - - private val _event: MutableStateFlow = MutableStateFlow(Event.None) - val event: StateFlow = _event.asStateFlow() - val withdrawalFirstCheck: MutableStateFlow = MutableStateFlow(false) val withdrawalSecondCheck: MutableStateFlow = MutableStateFlow(false) val withdrawalThirdCheck: MutableStateFlow = MutableStateFlow(false) val withdrawalCheck: MutableStateFlow = MutableStateFlow(false) fun onClickWithdrawalFirstCheck() { - _event.value = Event.OnClickWithdrawalFirstCheck - _event.value = Event.None + withdrawalFirstCheck.value = !withdrawalFirstCheck.value + withdrawalCheck.value = withdrawalCheck() } fun onClickWithdrawalSecondCheck() { - _event.value = Event.OnClickWithdrawalSecondCheck - _event.value = Event.None + withdrawalSecondCheck.value = !withdrawalSecondCheck.value + withdrawalCheck.value = withdrawalCheck() } fun onClickWithdrawalThirdCheck() { - _event.value = Event.OnClickWithdrawalThirdCheck - _event.value = Event.None + withdrawalThirdCheck.value = !withdrawalThirdCheck.value + withdrawalCheck.value = withdrawalCheck() } + private fun withdrawalCheck(): Boolean { + if (withdrawalFirstCheck.value + && withdrawalSecondCheck.value + && withdrawalThirdCheck.value + ) return true + return false + } } diff --git a/app/src/main/res/drawable/ic_baseline_check_circle_24.xml b/app/src/main/res/drawable/ic_baseline_check_circle_24.xml new file mode 100644 index 0000000..625e95e --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_check_circle_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_baseline_uncheck_circle_24.xml b/app/src/main/res/drawable/ic_baseline_uncheck_circle_24.xml new file mode 100644 index 0000000..bc5180a --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_uncheck_circle_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/selector_bg_checkbox.xml b/app/src/main/res/drawable/selector_bg_checkbox.xml new file mode 100644 index 0000000..03582ee --- /dev/null +++ b/app/src/main/res/drawable/selector_bg_checkbox.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/layout/activity_withdrawal.xml b/app/src/main/res/layout/activity_withdrawal.xml index 7ce6f62..52d5c47 100644 --- a/app/src/main/res/layout/activity_withdrawal.xml +++ b/app/src/main/res/layout/activity_withdrawal.xml @@ -67,14 +67,16 @@ app:layout_constraintTop_toBottomOf="@+id/divide_view" /> - @@ -83,25 +85,27 @@ android:id="@+id/withdrawal_first_check_text" android:layout_width="0dp" android:layout_height="wrap_content" + android:layout_marginStart="@dimen/dp_size_16" android:layout_marginEnd="@dimen/dp_size_16" android:fontFamily="@font/pretendard_regular" android:text="@string/withdrawal_first_check_text" android:textColor="@color/gray_900" android:textSize="@dimen/sp_size_12" - android:layout_marginStart="@dimen/dp_size_16" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/withdrawal_first_check" app:layout_constraintTop_toTopOf="@+id/withdrawal_first_check" /> - @@ -110,25 +114,27 @@ android:id="@+id/withdrawal_second_check_text" android:layout_width="0dp" android:layout_height="wrap_content" + android:layout_marginStart="@dimen/dp_size_16" android:layout_marginEnd="@dimen/dp_size_16" android:fontFamily="@font/pretendard_regular" android:text="@string/withdrawal_second_check_text" android:textColor="@color/gray_900" android:textSize="@dimen/sp_size_12" - android:layout_marginStart="@dimen/dp_size_16" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/withdrawal_second_check" app:layout_constraintTop_toTopOf="@+id/withdrawal_second_check" /> - @@ -137,23 +143,24 @@ android:id="@+id/withdrawal_third_check_text" android:layout_width="0dp" android:layout_height="wrap_content" + android:layout_marginStart="@dimen/dp_size_16" android:layout_marginEnd="@dimen/dp_size_16" android:fontFamily="@font/pretendard_regular" android:text="@string/withdrawal_third_check_text" android:textColor="@color/gray_900" android:textSize="@dimen/sp_size_12" - android:layout_marginStart="@dimen/dp_size_16" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/withdrawal_third_check" app:layout_constraintTop_toTopOf="@+id/withdrawal_third_check" /> - +