mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 06:55:41 +00:00
SecureBackupSetupEvents -> SecureBackupSetupEvent
This commit is contained in:
+5
-5
@@ -8,9 +8,9 @@
|
|||||||
|
|
||||||
package io.element.android.features.securebackup.impl.setup
|
package io.element.android.features.securebackup.impl.setup
|
||||||
|
|
||||||
sealed interface SecureBackupSetupEvents {
|
sealed interface SecureBackupSetupEvent {
|
||||||
data object CreateRecoveryKey : SecureBackupSetupEvents
|
data object CreateRecoveryKey : SecureBackupSetupEvent
|
||||||
data object RecoveryKeyHasBeenSaved : SecureBackupSetupEvents
|
data object RecoveryKeyHasBeenSaved : SecureBackupSetupEvent
|
||||||
data object Done : SecureBackupSetupEvents
|
data object Done : SecureBackupSetupEvent
|
||||||
data object DismissDialog : SecureBackupSetupEvents
|
data object DismissDialog : SecureBackupSetupEvent
|
||||||
}
|
}
|
||||||
+5
-5
@@ -53,18 +53,18 @@ class SecureBackupSetupPresenter(
|
|||||||
}
|
}
|
||||||
var showSaveConfirmationDialog by remember { mutableStateOf(false) }
|
var showSaveConfirmationDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
fun handleEvent(event: SecureBackupSetupEvents) {
|
fun handleEvent(event: SecureBackupSetupEvent) {
|
||||||
when (event) {
|
when (event) {
|
||||||
SecureBackupSetupEvents.CreateRecoveryKey -> {
|
SecureBackupSetupEvent.CreateRecoveryKey -> {
|
||||||
coroutineScope.createOrChangeRecoveryKey(stateAndDispatch)
|
coroutineScope.createOrChangeRecoveryKey(stateAndDispatch)
|
||||||
}
|
}
|
||||||
SecureBackupSetupEvents.RecoveryKeyHasBeenSaved ->
|
SecureBackupSetupEvent.RecoveryKeyHasBeenSaved ->
|
||||||
stateAndDispatch.dispatchAction(SecureBackupSetupStateMachine.Event.UserSavedKey)
|
stateAndDispatch.dispatchAction(SecureBackupSetupStateMachine.Event.UserSavedKey)
|
||||||
SecureBackupSetupEvents.DismissDialog -> {
|
SecureBackupSetupEvent.DismissDialog -> {
|
||||||
showSaveConfirmationDialog = false
|
showSaveConfirmationDialog = false
|
||||||
stateAndDispatch.dispatchAction(SecureBackupSetupStateMachine.Event.ClearError)
|
stateAndDispatch.dispatchAction(SecureBackupSetupStateMachine.Event.ClearError)
|
||||||
}
|
}
|
||||||
SecureBackupSetupEvents.Done -> {
|
SecureBackupSetupEvent.Done -> {
|
||||||
showSaveConfirmationDialog = true
|
showSaveConfirmationDialog = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ data class SecureBackupSetupState(
|
|||||||
val recoveryKeyViewState: RecoveryKeyViewState,
|
val recoveryKeyViewState: RecoveryKeyViewState,
|
||||||
val showSaveConfirmationDialog: Boolean,
|
val showSaveConfirmationDialog: Boolean,
|
||||||
val setupState: SetupState,
|
val setupState: SetupState,
|
||||||
val eventSink: (SecureBackupSetupEvents) -> Unit
|
val eventSink: (SecureBackupSetupEvent) -> Unit
|
||||||
)
|
)
|
||||||
|
|
||||||
sealed interface SetupState {
|
sealed interface SetupState {
|
||||||
|
|||||||
+6
-6
@@ -56,7 +56,7 @@ fun SecureBackupSetupView(
|
|||||||
title = stringResource(id = CommonStrings.common_something_went_wrong),
|
title = stringResource(id = CommonStrings.common_something_went_wrong),
|
||||||
content = stringResource(id = CommonStrings.common_something_went_wrong_message),
|
content = stringResource(id = CommonStrings.common_something_went_wrong_message),
|
||||||
onSubmit = {
|
onSubmit = {
|
||||||
state.eventSink.invoke(SecureBackupSetupEvents.DismissDialog)
|
state.eventSink.invoke(SecureBackupSetupEvent.DismissDialog)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -68,7 +68,7 @@ fun SecureBackupSetupView(
|
|||||||
submitText = stringResource(id = CommonStrings.action_continue),
|
submitText = stringResource(id = CommonStrings.action_continue),
|
||||||
onSubmitClick = onSuccess,
|
onSubmitClick = onSuccess,
|
||||||
onDismiss = {
|
onDismiss = {
|
||||||
state.eventSink.invoke(SecureBackupSetupEvents.DismissDialog)
|
state.eventSink.invoke(SecureBackupSetupEvent.DismissDialog)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -123,12 +123,12 @@ private fun Content(
|
|||||||
text = formattedRecoveryKey,
|
text = formattedRecoveryKey,
|
||||||
toastMessage = toastMessage,
|
toastMessage = toastMessage,
|
||||||
)
|
)
|
||||||
state.eventSink.invoke(SecureBackupSetupEvents.RecoveryKeyHasBeenSaved)
|
state.eventSink.invoke(SecureBackupSetupEvent.RecoveryKeyHasBeenSaved)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!state.recoveryKeyViewState.inProgress) {
|
if (!state.recoveryKeyViewState.inProgress) {
|
||||||
{
|
{
|
||||||
state.eventSink.invoke(SecureBackupSetupEvents.CreateRecoveryKey)
|
state.eventSink.invoke(SecureBackupSetupEvent.CreateRecoveryKey)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
@@ -174,7 +174,7 @@ private fun ColumnScope.Buttons(
|
|||||||
chooserTitle = chooserTitle,
|
chooserTitle = chooserTitle,
|
||||||
text = state.setupState.recoveryKey()!!,
|
text = state.setupState.recoveryKey()!!,
|
||||||
)
|
)
|
||||||
state.eventSink.invoke(SecureBackupSetupEvents.RecoveryKeyHasBeenSaved)
|
state.eventSink.invoke(SecureBackupSetupEvent.RecoveryKeyHasBeenSaved)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
Button(
|
Button(
|
||||||
@@ -184,7 +184,7 @@ private fun ColumnScope.Buttons(
|
|||||||
if (state.setupState is SetupState.CreatedAndSaved) {
|
if (state.setupState is SetupState.CreatedAndSaved) {
|
||||||
onFinish()
|
onFinish()
|
||||||
} else {
|
} else {
|
||||||
state.eventSink.invoke(SecureBackupSetupEvents.Done)
|
state.eventSink.invoke(SecureBackupSetupEvent.Done)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
+10
-10
@@ -58,7 +58,7 @@ class SecureBackupSetupPresenterTest {
|
|||||||
presenter.present()
|
presenter.present()
|
||||||
}.test {
|
}.test {
|
||||||
val initialState = awaitItem()
|
val initialState = awaitItem()
|
||||||
initialState.eventSink.invoke(SecureBackupSetupEvents.CreateRecoveryKey)
|
initialState.eventSink.invoke(SecureBackupSetupEvent.CreateRecoveryKey)
|
||||||
val creatingState = awaitItem()
|
val creatingState = awaitItem()
|
||||||
assertThat(creatingState.setupState).isEqualTo(SetupState.Creating)
|
assertThat(creatingState.setupState).isEqualTo(SetupState.Creating)
|
||||||
assertThat(creatingState.recoveryKeyViewState).isEqualTo(
|
assertThat(creatingState.recoveryKeyViewState).isEqualTo(
|
||||||
@@ -80,13 +80,13 @@ class SecureBackupSetupPresenterTest {
|
|||||||
inProgress = false,
|
inProgress = false,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
createdState.eventSink.invoke(SecureBackupSetupEvents.RecoveryKeyHasBeenSaved)
|
createdState.eventSink.invoke(SecureBackupSetupEvent.RecoveryKeyHasBeenSaved)
|
||||||
val createdAndSaveState = awaitItem()
|
val createdAndSaveState = awaitItem()
|
||||||
assertThat(createdAndSaveState.setupState).isInstanceOf(SetupState.CreatedAndSaved::class.java)
|
assertThat(createdAndSaveState.setupState).isInstanceOf(SetupState.CreatedAndSaved::class.java)
|
||||||
createdAndSaveState.eventSink.invoke(SecureBackupSetupEvents.Done)
|
createdAndSaveState.eventSink.invoke(SecureBackupSetupEvent.Done)
|
||||||
val doneState = awaitItem()
|
val doneState = awaitItem()
|
||||||
assertThat(doneState.showSaveConfirmationDialog).isTrue()
|
assertThat(doneState.showSaveConfirmationDialog).isTrue()
|
||||||
doneState.eventSink.invoke(SecureBackupSetupEvents.DismissDialog)
|
doneState.eventSink.invoke(SecureBackupSetupEvent.DismissDialog)
|
||||||
val doneStateCancelled = awaitItem()
|
val doneStateCancelled = awaitItem()
|
||||||
assertThat(doneStateCancelled.showSaveConfirmationDialog).isFalse()
|
assertThat(doneStateCancelled.showSaveConfirmationDialog).isFalse()
|
||||||
}
|
}
|
||||||
@@ -130,12 +130,12 @@ class SecureBackupSetupPresenterTest {
|
|||||||
assertThat(initialState.isChangeRecoveryKeyUserStory).isFalse()
|
assertThat(initialState.isChangeRecoveryKeyUserStory).isFalse()
|
||||||
assertThat(initialState.setupState).isEqualTo(SetupState.Init)
|
assertThat(initialState.setupState).isEqualTo(SetupState.Init)
|
||||||
|
|
||||||
initialState.eventSink(SecureBackupSetupEvents.CreateRecoveryKey)
|
initialState.eventSink(SecureBackupSetupEvent.CreateRecoveryKey)
|
||||||
val creatingState = awaitItem()
|
val creatingState = awaitItem()
|
||||||
assertThat(creatingState.setupState).isEqualTo(SetupState.Creating)
|
assertThat(creatingState.setupState).isEqualTo(SetupState.Creating)
|
||||||
val failedState = awaitItem()
|
val failedState = awaitItem()
|
||||||
assertThat(failedState.setupState).isInstanceOf(SetupState.Error::class.java)
|
assertThat(failedState.setupState).isInstanceOf(SetupState.Error::class.java)
|
||||||
failedState.eventSink(SecureBackupSetupEvents.DismissDialog)
|
failedState.eventSink(SecureBackupSetupEvent.DismissDialog)
|
||||||
|
|
||||||
val finalState = awaitItem()
|
val finalState = awaitItem()
|
||||||
assertThat(finalState.setupState).isEqualTo(SetupState.Init)
|
assertThat(finalState.setupState).isEqualTo(SetupState.Init)
|
||||||
@@ -153,7 +153,7 @@ class SecureBackupSetupPresenterTest {
|
|||||||
presenter.present()
|
presenter.present()
|
||||||
}.test {
|
}.test {
|
||||||
val initialState = awaitItem()
|
val initialState = awaitItem()
|
||||||
initialState.eventSink.invoke(SecureBackupSetupEvents.CreateRecoveryKey)
|
initialState.eventSink.invoke(SecureBackupSetupEvent.CreateRecoveryKey)
|
||||||
val creatingState = awaitItem()
|
val creatingState = awaitItem()
|
||||||
assertThat(creatingState.setupState).isEqualTo(SetupState.Creating)
|
assertThat(creatingState.setupState).isEqualTo(SetupState.Creating)
|
||||||
assertThat(creatingState.recoveryKeyViewState).isEqualTo(
|
assertThat(creatingState.recoveryKeyViewState).isEqualTo(
|
||||||
@@ -174,13 +174,13 @@ class SecureBackupSetupPresenterTest {
|
|||||||
inProgress = false,
|
inProgress = false,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
createdState.eventSink.invoke(SecureBackupSetupEvents.RecoveryKeyHasBeenSaved)
|
createdState.eventSink.invoke(SecureBackupSetupEvent.RecoveryKeyHasBeenSaved)
|
||||||
val createdAndSaveState = awaitItem()
|
val createdAndSaveState = awaitItem()
|
||||||
assertThat(createdAndSaveState.setupState).isInstanceOf(SetupState.CreatedAndSaved::class.java)
|
assertThat(createdAndSaveState.setupState).isInstanceOf(SetupState.CreatedAndSaved::class.java)
|
||||||
createdAndSaveState.eventSink.invoke(SecureBackupSetupEvents.Done)
|
createdAndSaveState.eventSink.invoke(SecureBackupSetupEvent.Done)
|
||||||
val doneState = awaitItem()
|
val doneState = awaitItem()
|
||||||
assertThat(doneState.showSaveConfirmationDialog).isTrue()
|
assertThat(doneState.showSaveConfirmationDialog).isTrue()
|
||||||
doneState.eventSink.invoke(SecureBackupSetupEvents.DismissDialog)
|
doneState.eventSink.invoke(SecureBackupSetupEvent.DismissDialog)
|
||||||
val doneStateCancelled = awaitItem()
|
val doneStateCancelled = awaitItem()
|
||||||
assertThat(doneStateCancelled.showSaveConfirmationDialog).isFalse()
|
assertThat(doneStateCancelled.showSaveConfirmationDialog).isFalse()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user