mirror of
https://github.com/bitwarden/android.git
synced 2025-12-11 13:57:03 -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.Text
|
||||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
@ -20,6 +21,8 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
private const val KEY_STATE = "state"
|
private const val KEY_STATE = "state"
|
||||||
|
|
||||||
|
private const val SUCCESS_DIALOG_DELAY = 550L
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* View model for the [DeleteAccountScreen].
|
* View model for the [DeleteAccountScreen].
|
||||||
*/
|
*/
|
||||||
@ -115,7 +118,17 @@ class DeleteAccountViewModel @Inject constructor(
|
|||||||
) {
|
) {
|
||||||
when (val result = action.result) {
|
when (val result = action.result) {
|
||||||
DeleteAccountResult.Success -> {
|
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 -> {
|
is DeleteAccountResult.Error -> {
|
||||||
|
|||||||
@ -87,18 +87,23 @@ class DeleteAccountViewModelTest : BaseViewModelTest() {
|
|||||||
authRepo.deleteAccountWithMasterPassword(masterPassword)
|
authRepo.deleteAccountWithMasterPassword(masterPassword)
|
||||||
} returns DeleteAccountResult.Success
|
} returns DeleteAccountResult.Success
|
||||||
|
|
||||||
viewModel.trySendAction(
|
viewModel.stateFlow.test {
|
||||||
DeleteAccountAction.DeleteAccountConfirmDialogClick(
|
assertEquals(DEFAULT_STATE, awaitItem())
|
||||||
masterPassword,
|
viewModel.trySendAction(
|
||||||
),
|
action = DeleteAccountAction.DeleteAccountConfirmDialogClick(masterPassword),
|
||||||
)
|
)
|
||||||
|
assertEquals(
|
||||||
assertEquals(
|
DEFAULT_STATE.copy(dialog = DeleteAccountState.DeleteAccountDialog.Loading),
|
||||||
DEFAULT_STATE.copy(dialog = DeleteAccountState.DeleteAccountDialog.DeleteSuccess),
|
awaitItem(),
|
||||||
viewModel.stateFlow.value,
|
)
|
||||||
)
|
assertEquals(
|
||||||
|
DEFAULT_STATE.copy(
|
||||||
coVerify {
|
dialog = DeleteAccountState.DeleteAccountDialog.DeleteSuccess,
|
||||||
|
),
|
||||||
|
awaitItem(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
coVerify(exactly = 1) {
|
||||||
authRepo.deleteAccountWithMasterPassword(masterPassword)
|
authRepo.deleteAccountWithMasterPassword(masterPassword)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user