SecureBackupRootEvents -> SecureBackupRootEvent

This commit is contained in:
Benoit Marty
2026-08-25 10:21:36 +02:00
parent 2d611475da
commit 28c19e38ce
5 changed files with 22 additions and 22 deletions
@@ -8,9 +8,9 @@
package io.element.android.features.securebackup.impl.root
sealed interface SecureBackupRootEvents {
data object RetryKeyBackupState : SecureBackupRootEvents
data object EnableKeyStorage : SecureBackupRootEvents
data object DisplayKeyStorageDisabledError : SecureBackupRootEvents
data object DismissDialog : SecureBackupRootEvents
sealed interface SecureBackupRootEvent {
data object RetryKeyBackupState : SecureBackupRootEvent
data object EnableKeyStorage : SecureBackupRootEvent
data object DisplayKeyStorageDisabledError : SecureBackupRootEvent
data object DismissDialog : SecureBackupRootEvent
}
@@ -59,15 +59,15 @@ class SecureBackupRootPresenter(
}
}
fun handleEvent(event: SecureBackupRootEvents) {
fun handleEvent(event: SecureBackupRootEvent) {
when (event) {
SecureBackupRootEvents.RetryKeyBackupState -> localCoroutineScope.getKeyBackupStatus(doesBackupExistOnServerAction)
SecureBackupRootEvents.EnableKeyStorage -> localCoroutineScope.enableBackup(enableAction)
SecureBackupRootEvents.DismissDialog -> {
SecureBackupRootEvent.RetryKeyBackupState -> localCoroutineScope.getKeyBackupStatus(doesBackupExistOnServerAction)
SecureBackupRootEvent.EnableKeyStorage -> localCoroutineScope.enableBackup(enableAction)
SecureBackupRootEvent.DismissDialog -> {
enableAction.value = AsyncAction.Uninitialized
displayKeyStorageDisabledError = false
}
SecureBackupRootEvents.DisplayKeyStorageDisabledError -> displayKeyStorageDisabledError = true
SecureBackupRootEvent.DisplayKeyStorageDisabledError -> displayKeyStorageDisabledError = true
}
}
@@ -22,7 +22,7 @@ data class SecureBackupRootState(
val appName: String,
val displayKeyStorageDisabledError: Boolean,
val snackbarMessage: SnackbarMessage?,
val eventSink: (SecureBackupRootEvents) -> Unit,
val eventSink: (SecureBackupRootEvent) -> Unit,
) {
val isKeyStorageEnabled: Boolean
get() = when (backupState) {
@@ -114,12 +114,12 @@ fun SecureBackupRootView(
if (state.doesBackupExistOnServer.data) {
onDisableClick()
} else {
state.eventSink.invoke(SecureBackupRootEvents.EnableKeyStorage)
state.eventSink.invoke(SecureBackupRootEvent.EnableKeyStorage)
}
}
is AsyncData.Loading,
AsyncData.Uninitialized -> Unit
is AsyncData.Failure -> state.eventSink.invoke(SecureBackupRootEvents.RetryKeyBackupState)
is AsyncData.Failure -> state.eventSink.invoke(SecureBackupRootEvent.RetryKeyBackupState)
}
}
BackupState.CREATING,
@@ -154,7 +154,7 @@ fun SecureBackupRootView(
if (state.isKeyStorageEnabled) {
onSetupClick()
} else {
state.eventSink.invoke(SecureBackupRootEvents.DisplayKeyStorageDisabledError)
state.eventSink.invoke(SecureBackupRootEvent.DisplayKeyStorageDisabledError)
}
},
)
@@ -177,7 +177,7 @@ fun SecureBackupRootView(
if (state.isKeyStorageEnabled) {
onChangeClick()
} else {
state.eventSink.invoke(SecureBackupRootEvents.DisplayKeyStorageDisabledError)
state.eventSink.invoke(SecureBackupRootEvent.DisplayKeyStorageDisabledError)
}
},
)
@@ -201,7 +201,7 @@ fun SecureBackupRootView(
if (state.isKeyStorageEnabled) {
onConfirmRecoveryKeyClick()
} else {
state.eventSink.invoke(SecureBackupRootEvents.DisplayKeyStorageDisabledError)
state.eventSink.invoke(SecureBackupRootEvent.DisplayKeyStorageDisabledError)
}
},
)
@@ -212,13 +212,13 @@ fun SecureBackupRootView(
async = state.enableAction,
progressDialog = { },
onSuccess = { },
onErrorDismiss = { state.eventSink.invoke(SecureBackupRootEvents.DismissDialog) }
onErrorDismiss = { state.eventSink.invoke(SecureBackupRootEvent.DismissDialog) }
)
if (state.displayKeyStorageDisabledError) {
ErrorDialog(
title = null,
content = stringResource(id = R.string.screen_chat_backup_key_storage_disabled_error),
onSubmit = { state.eventSink.invoke(SecureBackupRootEvents.DismissDialog) },
onSubmit = { state.eventSink.invoke(SecureBackupRootEvent.DismissDialog) },
)
}
}
@@ -66,7 +66,7 @@ class SecureBackupRootPresenterTest {
val errorState = awaitItem()
assertThat(errorState.doesBackupExistOnServer).isEqualTo(AsyncData.Failure<Boolean>(AN_EXCEPTION))
encryptionService.givenDoesBackupExistOnServerResult(Result.success(false))
errorState.eventSink.invoke(SecureBackupRootEvents.RetryKeyBackupState)
errorState.eventSink.invoke(SecureBackupRootEvent.RetryKeyBackupState)
val loadingState2 = awaitItem()
assertThat(loadingState2.doesBackupExistOnServer).isInstanceOf(AsyncData.Loading::class.java)
val finalState = awaitItem()
@@ -82,9 +82,9 @@ class SecureBackupRootPresenterTest {
}.test {
skipItems(2)
val initialState = awaitItem()
initialState.eventSink(SecureBackupRootEvents.DisplayKeyStorageDisabledError)
initialState.eventSink(SecureBackupRootEvent.DisplayKeyStorageDisabledError)
assertThat(awaitItem().displayKeyStorageDisabledError).isTrue()
initialState.eventSink(SecureBackupRootEvents.DismissDialog)
initialState.eventSink(SecureBackupRootEvent.DismissDialog)
assertThat(awaitItem().displayKeyStorageDisabledError).isFalse()
}
}
@@ -97,7 +97,7 @@ class SecureBackupRootPresenterTest {
}.test {
skipItems(2)
val initialState = awaitItem()
initialState.eventSink(SecureBackupRootEvents.EnableKeyStorage)
initialState.eventSink(SecureBackupRootEvent.EnableKeyStorage)
assertThat(awaitItem().enableAction.isLoading()).isTrue()
assertThat(awaitItem().enableAction.isSuccess()).isTrue()
}