From e9bc37535f746b62c798e31f38ca0eef163029f1 Mon Sep 17 00:00:00 2001 From: jinuemong Date: Sun, 28 Jan 2024 15:40:08 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]:=20Button=20State=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20=EB=B3=80=ED=99=94=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../login/onboarding/LoginOnBoardingDestination.kt | 8 ++++++-- .../main/login/onboarding/LoginOnBoardingState.kt | 10 +++++++--- .../login/onboarding/LoginOnBoardingViewModel.kt | 13 ++++++++++--- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/login/onboarding/LoginOnBoardingDestination.kt b/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/login/onboarding/LoginOnBoardingDestination.kt index 47927b5e..62155c09 100644 --- a/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/login/onboarding/LoginOnBoardingDestination.kt +++ b/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/login/onboarding/LoginOnBoardingDestination.kt @@ -18,8 +18,12 @@ fun NavGraphBuilder.loginOnBoardingDestination( val viewModel: LoginOnBoardingViewModel = hiltViewModel() val model: LoginOnBoardingModel = let { - val state by viewModel.state.collectAsStateWithLifecycle() - LoginOnBoardingModel(state = state) + val loadingState by viewModel.loadingState.collectAsStateWithLifecycle() + val buttonState by viewModel.buttonState.collectAsStateWithLifecycle() + LoginOnBoardingModel( + loadingState = loadingState, + buttonState = buttonState + ) } ErrorObserver(viewModel) diff --git a/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/login/onboarding/LoginOnBoardingState.kt b/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/login/onboarding/LoginOnBoardingState.kt index a1e12cdb..631a92ae 100644 --- a/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/login/onboarding/LoginOnBoardingState.kt +++ b/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/login/onboarding/LoginOnBoardingState.kt @@ -3,10 +3,14 @@ package ac.dnd.bookkeeping.android.presentation.ui.main.login.onboarding import ac.dnd.bookkeeping.android.domain.model.error.ServerException sealed interface LoginOnBoardingState { - data object Init : LoginOnBoardingState - sealed interface Loading : LoginOnBoardingEvent { + sealed interface Loading { + data object Progress : Loading data object Success : Loading data class Failure(val exception: ServerException) : Loading - data class Error(val exception: Throwable) : Loading + } + + sealed interface Button { + data object Default : Button + data object Pressed : Button } } diff --git a/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/login/onboarding/LoginOnBoardingViewModel.kt b/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/login/onboarding/LoginOnBoardingViewModel.kt index 4e2b2d7d..8d628b13 100644 --- a/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/login/onboarding/LoginOnBoardingViewModel.kt +++ b/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/login/onboarding/LoginOnBoardingViewModel.kt @@ -6,6 +6,7 @@ import ac.dnd.bookkeeping.android.presentation.common.util.coroutine.event.Mutab import ac.dnd.bookkeeping.android.presentation.common.util.coroutine.event.asEventFlow import androidx.lifecycle.SavedStateHandle import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow @@ -16,9 +17,13 @@ class LoginOnBoardingViewModel @Inject constructor( private val savedStateHandle: SavedStateHandle, ) : BaseViewModel() { - private val _state: MutableStateFlow = - MutableStateFlow(LoginOnBoardingState.Init) - val state: StateFlow = _state.asStateFlow() + private val _loadingState: MutableStateFlow = + MutableStateFlow(LoginOnBoardingState.Loading.Progress) + val loadingState: StateFlow = _loadingState.asStateFlow() + + private val _buttonState: MutableStateFlow = + MutableStateFlow(LoginOnBoardingState.Button.Default) + val buttonState: StateFlow = _buttonState.asStateFlow() private val _event: MutableEventFlow = MutableEventFlow() val event: EventFlow = _event.asEventFlow() @@ -31,6 +36,8 @@ class LoginOnBoardingViewModel @Inject constructor( private fun goToNextStep() { launch { + _buttonState.emit(LoginOnBoardingState.Button.Pressed) + delay(100L) _event.emit(LoginOnBoardingEvent.GoToNextStep) } }