@@ -3,9 +3,7 @@ package com.threegap.bitnagil.presentation.setting
33import androidx.lifecycle.SavedStateHandle
44import androidx.lifecycle.viewModelScope
55import com.threegap.bitnagil.domain.auth.usecase.LogoutUseCase
6- import com.threegap.bitnagil.domain.auth.usecase.WithdrawalUseCase
76import com.threegap.bitnagil.presentation.common.mviviewmodel.MviViewModel
8- import com.threegap.bitnagil.presentation.setting.model.ConfirmDialogType
97import com.threegap.bitnagil.presentation.setting.model.mvi.SettingIntent
108import com.threegap.bitnagil.presentation.setting.model.mvi.SettingSideEffect
119import com.threegap.bitnagil.presentation.setting.model.mvi.SettingState
@@ -20,7 +18,6 @@ import javax.inject.Inject
2018class SettingViewModel @Inject constructor(
2119 savedStateHandle : SavedStateHandle ,
2220 private val logoutUseCase : LogoutUseCase ,
23- private val withdrawalUseCase : WithdrawalUseCase ,
2421) : MviViewModel<SettingState, SettingSideEffect, SettingIntent>(
2522 initState = SettingState .Init ,
2623 savedStateHandle = savedStateHandle,
@@ -49,57 +46,45 @@ class SettingViewModel @Inject constructor(
4946 }
5047
5148 is SettingIntent .ShowConfirmDialog -> {
52- return state.copy(showConfirmDialog = intent.type )
49+ return state.copy(logoutConfirmDialogVisible = true )
5350 }
5451
5552 is SettingIntent .HideConfirmDialog -> {
56- return state.copy(showConfirmDialog = null )
53+ return state.copy(logoutConfirmDialogVisible = false )
5754 }
5855
5956 SettingIntent .LogoutSuccess -> {
6057 sendSideEffect(SettingSideEffect .NavigateToLogin )
6158 return null
6259 }
60+
6361 SettingIntent .LogoutLoading -> {
6462 return state.copy(loading = true )
6563 }
64+
6665 SettingIntent .LogoutFailure -> {
6766 return state.copy(loading = false )
6867 }
69- SettingIntent .WithdrawalSuccess -> {
70- sendSideEffect(SettingSideEffect .NavigateToLogin )
71- return null
72- }
73- SettingIntent .WithdrawalLoading -> {
74- return state.copy(loading = true )
75- }
76- SettingIntent .WithdrawalFailure -> {
77- return state.copy(loading = false )
78- }
7968 }
8069 }
8170
8271 fun showLogoutDialog () {
83- sendIntent(SettingIntent .ShowConfirmDialog (ConfirmDialogType .LOGOUT ))
84- }
85-
86- fun showWithdrawalDialog () {
87- sendIntent(SettingIntent .ShowConfirmDialog (ConfirmDialogType .WITHDRAW ))
72+ sendIntent(SettingIntent .ShowConfirmDialog )
8873 }
8974
9075 fun hideConfirmDialog () {
9176 sendIntent(SettingIntent .HideConfirmDialog )
9277 }
9378
94- fun confirmDialogAction () {
95- val currentDialogType = container.stateFlow.value.showConfirmDialog
96-
79+ fun logout () {
9780 sendIntent(SettingIntent .HideConfirmDialog )
98-
99- when (currentDialogType) {
100- ConfirmDialogType .LOGOUT -> executeLogout()
101- ConfirmDialogType .WITHDRAW -> executeWithdrawal()
102- null -> {}
81+ viewModelScope.launch {
82+ sendIntent(SettingIntent .LogoutLoading )
83+ logoutUseCase().onSuccess {
84+ sendIntent(SettingIntent .LogoutSuccess )
85+ }.onFailure {
86+ sendIntent(SettingIntent .LogoutFailure )
87+ }
10388 }
10489 }
10590
@@ -118,26 +103,4 @@ class SettingViewModel @Inject constructor(
118103 delay(1000L )
119104 }
120105 }
121-
122- private fun executeLogout () {
123- viewModelScope.launch {
124- sendIntent(SettingIntent .LogoutLoading )
125- logoutUseCase().onSuccess {
126- sendIntent(SettingIntent .LogoutSuccess )
127- }.onFailure {
128- sendIntent(SettingIntent .LogoutFailure )
129- }
130- }
131- }
132-
133- private fun executeWithdrawal () {
134- viewModelScope.launch {
135- sendIntent(SettingIntent .WithdrawalLoading )
136- withdrawalUseCase().onSuccess {
137- sendIntent(SettingIntent .WithdrawalSuccess )
138- }.onFailure {
139- sendIntent(SettingIntent .WithdrawalFailure )
140- }
141- }
142- }
143106}
0 commit comments