mirror of
https://github.com/bitwarden/android.git
synced 2024-11-23 09:56:11 +03:00
Minor cleanup of LoginWithDeviceViewModel (#881)
This commit is contained in:
parent
c88b01ea11
commit
2be47c5b0f
1 changed files with 14 additions and 23 deletions
|
@ -50,16 +50,7 @@ class LoginWithDeviceViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleErrorDialogDismissed() {
|
private fun handleErrorDialogDismissed() {
|
||||||
val viewState = mutableStateFlow.value.viewState as? LoginWithDeviceState.ViewState.Content
|
updateContent { it.copy(shouldShowErrorDialog = false) }
|
||||||
if (viewState != null) {
|
|
||||||
mutableStateFlow.update {
|
|
||||||
it.copy(
|
|
||||||
viewState = viewState.copy(
|
|
||||||
shouldShowErrorDialog = false,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleResendNotificationClicked() {
|
private fun handleResendNotificationClicked() {
|
||||||
|
@ -87,7 +78,6 @@ class LoginWithDeviceViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
is AuthRequestResult.Error -> {
|
is AuthRequestResult.Error -> {
|
||||||
|
|
||||||
mutableStateFlow.update {
|
mutableStateFlow.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
viewState = LoginWithDeviceState.ViewState.Content(
|
viewState = LoginWithDeviceState.ViewState.Content(
|
||||||
|
@ -115,18 +105,19 @@ class LoginWithDeviceViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setIsResendNotificationLoading(isLoading: Boolean) {
|
private fun setIsResendNotificationLoading(isLoading: Boolean) {
|
||||||
when (val viewState = mutableStateFlow.value.viewState) {
|
updateContent { it.copy(isResendNotificationLoading = isLoading) }
|
||||||
is LoginWithDeviceState.ViewState.Content -> {
|
}
|
||||||
mutableStateFlow.update {
|
|
||||||
it.copy(
|
private inline fun updateContent(
|
||||||
viewState = viewState.copy(
|
crossinline block: (
|
||||||
isResendNotificationLoading = isLoading,
|
LoginWithDeviceState.ViewState.Content,
|
||||||
),
|
) -> LoginWithDeviceState.ViewState.Content?,
|
||||||
)
|
) {
|
||||||
}
|
val currentViewState = state.viewState
|
||||||
}
|
val updatedContent = (currentViewState as? LoginWithDeviceState.ViewState.Content)
|
||||||
else -> Unit
|
?.let(block)
|
||||||
}
|
?: return
|
||||||
|
mutableStateFlow.update { it.copy(viewState = updatedContent) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue