Skip to content

Commit

Permalink
[Feat]: Button State에 따른 변화 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jinuemong committed Jan 28, 2024
1 parent 0e41461 commit e9bc375
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,9 +17,13 @@ class LoginOnBoardingViewModel @Inject constructor(
private val savedStateHandle: SavedStateHandle,
) : BaseViewModel() {

private val _state: MutableStateFlow<LoginOnBoardingState> =
MutableStateFlow(LoginOnBoardingState.Init)
val state: StateFlow<LoginOnBoardingState> = _state.asStateFlow()
private val _loadingState: MutableStateFlow<LoginOnBoardingState.Loading> =
MutableStateFlow(LoginOnBoardingState.Loading.Progress)
val loadingState: StateFlow<LoginOnBoardingState.Loading> = _loadingState.asStateFlow()

private val _buttonState: MutableStateFlow<LoginOnBoardingState.Button> =
MutableStateFlow(LoginOnBoardingState.Button.Default)
val buttonState: StateFlow<LoginOnBoardingState.Button> = _buttonState.asStateFlow()

private val _event: MutableEventFlow<LoginOnBoardingEvent> = MutableEventFlow()
val event: EventFlow<LoginOnBoardingEvent> = _event.asEventFlow()
Expand All @@ -31,6 +36,8 @@ class LoginOnBoardingViewModel @Inject constructor(

private fun goToNextStep() {
launch {
_buttonState.emit(LoginOnBoardingState.Button.Pressed)
delay(100L)
_event.emit(LoginOnBoardingEvent.GoToNextStep)
}
}
Expand Down

0 comments on commit e9bc375

Please sign in to comment.