mirror of
https://github.com/bitwarden/android.git
synced 2025-12-10 09:56:45 -06:00
PM-19547: Delay the delete account success dialog to avoid flicker (#4927)
This commit is contained in:
parent
8dd5a9df9f
commit
5279e6d18c
@ -11,6 +11,7 @@ import com.x8bit.bitwarden.ui.platform.base.BaseViewModel
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.Text
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.update
|
||||
@ -20,6 +21,8 @@ import javax.inject.Inject
|
||||
|
||||
private const val KEY_STATE = "state"
|
||||
|
||||
private const val SUCCESS_DIALOG_DELAY = 550L
|
||||
|
||||
/**
|
||||
* View model for the [DeleteAccountScreen].
|
||||
*/
|
||||
@ -115,7 +118,17 @@ class DeleteAccountViewModel @Inject constructor(
|
||||
) {
|
||||
when (val result = action.result) {
|
||||
DeleteAccountResult.Success -> {
|
||||
updateDialogState(DeleteAccountState.DeleteAccountDialog.DeleteSuccess)
|
||||
viewModelScope.launch {
|
||||
// When deleting an account, the current activity is recreated and therefore
|
||||
// the composition takes place twice. Adding this delay prevents the dialog
|
||||
// from flashing when it is re-created.
|
||||
delay(timeMillis = SUCCESS_DIALOG_DELAY)
|
||||
sendAction(
|
||||
action = DeleteAccountAction.Internal.UpdateDialogState(
|
||||
dialog = DeleteAccountState.DeleteAccountDialog.DeleteSuccess,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
is DeleteAccountResult.Error -> {
|
||||
|
||||
@ -87,18 +87,23 @@ class DeleteAccountViewModelTest : BaseViewModelTest() {
|
||||
authRepo.deleteAccountWithMasterPassword(masterPassword)
|
||||
} returns DeleteAccountResult.Success
|
||||
|
||||
viewModel.trySendAction(
|
||||
DeleteAccountAction.DeleteAccountConfirmDialogClick(
|
||||
masterPassword,
|
||||
),
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(dialog = DeleteAccountState.DeleteAccountDialog.DeleteSuccess),
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
|
||||
coVerify {
|
||||
viewModel.stateFlow.test {
|
||||
assertEquals(DEFAULT_STATE, awaitItem())
|
||||
viewModel.trySendAction(
|
||||
action = DeleteAccountAction.DeleteAccountConfirmDialogClick(masterPassword),
|
||||
)
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(dialog = DeleteAccountState.DeleteAccountDialog.Loading),
|
||||
awaitItem(),
|
||||
)
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(
|
||||
dialog = DeleteAccountState.DeleteAccountDialog.DeleteSuccess,
|
||||
),
|
||||
awaitItem(),
|
||||
)
|
||||
}
|
||||
coVerify(exactly = 1) {
|
||||
authRepo.deleteAccountWithMasterPassword(masterPassword)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user