Skip to content

Commit

Permalink
PR Feedback :
Browse files Browse the repository at this point in the history
- 회원 탈퇴 시 동의항목 체크 selector로 변경
- 액티비티에 있던 로직들 뷰모델로 변경
  • Loading branch information
likppi10 committed Aug 27, 2022
1 parent 91f309a commit ad86f6e
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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<Event> = MutableStateFlow(Event.None)
val event: StateFlow<Event> = _event.asStateFlow()

val withdrawalFirstCheck: MutableStateFlow<Boolean> = MutableStateFlow(false)
val withdrawalSecondCheck: MutableStateFlow<Boolean> = MutableStateFlow(false)
val withdrawalThirdCheck: MutableStateFlow<Boolean> = MutableStateFlow(false)
val withdrawalCheck: MutableStateFlow<Boolean> = 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
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_baseline_check_circle_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="@color/red_500"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM10,17l-5,-5 1.41,-1.41L10,14.17l7.59,-7.59L19,8l-9,9z"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_baseline_uncheck_circle_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="@color/gray_300"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM10,17l-5,-5 1.41,-1.41L10,14.17l7.59,-7.59L19,8l-9,9z"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/selector_bg_checkbox.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_baseline_uncheck_circle_24" android:state_enabled="true" android:state_checked="false"/>
<item android:drawable="@drawable/ic_baseline_check_circle_24" android:state_checked="true" />
</selector>
29 changes: 18 additions & 11 deletions app/src/main/res/layout/activity_withdrawal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,16 @@
app:layout_constraintTop_toBottomOf="@+id/divide_view"
/>

<ImageView
<CheckBox
android:id="@+id/withdrawal_first_check"
android:layout_width="@dimen/dp_size_28"
android:layout_height="@dimen/dp_size_28"
android:layout_marginStart="@dimen/dp_size_12"
android:layout_marginTop="@dimen/dp_size_16"
android:background="@drawable/selector_bg_checkbox"
android:button="@android:color/transparent"
android:checked="@{viewModel.withdrawalFirstCheck}"
android:onClick="@{() -> viewModel.onClickWithdrawalFirstCheck()}"
android:src="@drawable/icon_check_disabled"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/withdrawal_check_text"
/>
Expand All @@ -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"
/>

<ImageView
<CheckBox
android:id="@+id/withdrawal_second_check"
android:layout_width="@dimen/dp_size_28"
android:layout_height="@dimen/dp_size_28"
android:layout_marginStart="@dimen/dp_size_12"
android:layout_marginTop="@dimen/dp_size_16"
android:background="@drawable/selector_bg_checkbox"
android:button="@android:color/transparent"
android:checked="@{viewModel.withdrawalSecondCheck}"
android:onClick="@{() -> viewModel.onClickWithdrawalSecondCheck()}"
android:src="@drawable/icon_check_disabled"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/withdrawal_first_check_text"
/>
Expand All @@ -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"
/>

<ImageView
<CheckBox
android:id="@+id/withdrawal_third_check"
android:layout_width="@dimen/dp_size_28"
android:layout_height="@dimen/dp_size_28"
android:layout_marginStart="@dimen/dp_size_12"
android:layout_marginTop="@dimen/dp_size_16"
android:background="@drawable/selector_bg_checkbox"
android:button="@android:color/transparent"
android:checked="@{viewModel.withdrawalThirdCheck}"
android:onClick="@{() -> viewModel.onClickWithdrawalThirdCheck()}"
android:src="@drawable/icon_check_disabled"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/withdrawal_second_check_text"
/>
Expand All @@ -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"
/>

<com.ftw.hometerview.design.MainButton
android:id="@+id/withdrawal_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dp_size_32"
android:layout_marginHorizontal="@dimen/dp_size_16"
android:layout_marginBottom="@dimen/dp_size_32"
android:enabled="@{viewModel.withdrawalCheck}"
android:text="@string/withdrawal_button_text"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
Expand Down

0 comments on commit ad86f6e

Please sign in to comment.