PM-19547: Delay the delete account success dialog to avoid flicker (#4927)

This commit is contained in:
David Perez 2025-03-27 13:52:38 -05:00 committed by GitHub
parent 8dd5a9df9f
commit 5279e6d18c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 13 deletions

View File

@ -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 -> {

View File

@ -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)
}
}