NotificationsOptInEvents -> NotificationsOptInEvent

This commit is contained in:
Benoit Marty
2026-08-25 09:53:16 +02:00
parent 17a3db246f
commit 3ae9ba74b4
5 changed files with 13 additions and 13 deletions
@@ -8,7 +8,7 @@
package io.element.android.features.ftue.impl.notifications package io.element.android.features.ftue.impl.notifications
sealed interface NotificationsOptInEvents { sealed interface NotificationsOptInEvent {
data object ContinueClicked : NotificationsOptInEvents data object ContinueClicked : NotificationsOptInEvent
data object NotNowClicked : NotificationsOptInEvents data object NotNowClicked : NotificationsOptInEvent
} }
@@ -52,16 +52,16 @@ class NotificationsOptInPresenter(
override fun present(): NotificationsOptInState { override fun present(): NotificationsOptInState {
val notificationsPermissionsState = postNotificationPermissionsPresenter.present() val notificationsPermissionsState = postNotificationPermissionsPresenter.present()
fun handleEvent(event: NotificationsOptInEvents) { fun handleEvent(event: NotificationsOptInEvent) {
when (event) { when (event) {
NotificationsOptInEvents.ContinueClicked -> { NotificationsOptInEvent.ContinueClicked -> {
if (notificationsPermissionsState.permissionGranted) { if (notificationsPermissionsState.permissionGranted) {
callback.onNotificationsOptInFinished() callback.onNotificationsOptInFinished()
} else { } else {
notificationsPermissionsState.eventSink(PermissionsEvent.RequestPermissions) notificationsPermissionsState.eventSink(PermissionsEvent.RequestPermissions)
} }
} }
NotificationsOptInEvents.NotNowClicked -> { NotificationsOptInEvent.NotNowClicked -> {
if (buildVersionSdkIntProvider.isAtLeast(Build.VERSION_CODES.TIRAMISU)) { if (buildVersionSdkIntProvider.isAtLeast(Build.VERSION_CODES.TIRAMISU)) {
appCoroutineScope.setPermissionDenied() appCoroutineScope.setPermissionDenied()
} }
@@ -12,5 +12,5 @@ import io.element.android.libraries.permissions.api.PermissionsState
data class NotificationsOptInState( data class NotificationsOptInState(
val notificationsPermissionState: PermissionsState, val notificationsPermissionState: PermissionsState,
val eventSink: (NotificationsOptInEvents) -> Unit val eventSink: (NotificationsOptInEvent) -> Unit
) )
@@ -86,14 +86,14 @@ private fun NotificationsOptInFooter(state: NotificationsOptInState) {
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
text = stringResource(CommonStrings.action_ok), text = stringResource(CommonStrings.action_ok),
onClick = { onClick = {
state.eventSink(NotificationsOptInEvents.ContinueClicked) state.eventSink(NotificationsOptInEvent.ContinueClicked)
} }
) )
TextButton( TextButton(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
text = stringResource(CommonStrings.action_not_now), text = stringResource(CommonStrings.action_not_now),
onClick = { onClick = {
state.eventSink(NotificationsOptInEvents.NotNowClicked) state.eventSink(NotificationsOptInEvent.NotNowClicked)
} }
) )
} }
@@ -55,7 +55,7 @@ class NotificationsOptInPresenterTest {
presenter.present() presenter.present()
}.test { }.test {
val initialState = awaitItem() val initialState = awaitItem()
initialState.eventSink(NotificationsOptInEvents.ContinueClicked) initialState.eventSink(NotificationsOptInEvent.ContinueClicked)
assertThat(awaitItem().notificationsPermissionState.showDialog).isTrue() assertThat(awaitItem().notificationsPermissionState.showDialog).isTrue()
} }
} }
@@ -70,7 +70,7 @@ class NotificationsOptInPresenterTest {
presenter.present() presenter.present()
}.test { }.test {
val initialState = awaitItem() val initialState = awaitItem()
initialState.eventSink(NotificationsOptInEvents.ContinueClicked) initialState.eventSink(NotificationsOptInEvent.ContinueClicked)
assertThat(isFinished).isTrue() assertThat(isFinished).isTrue()
} }
} }
@@ -86,7 +86,7 @@ class NotificationsOptInPresenterTest {
presenter.present() presenter.present()
}.test { }.test {
val initialState = awaitItem() val initialState = awaitItem()
initialState.eventSink(NotificationsOptInEvents.NotNowClicked) initialState.eventSink(NotificationsOptInEvent.NotNowClicked)
assertThat(isFinished).isTrue() assertThat(isFinished).isTrue()
} }
} }
@@ -105,7 +105,7 @@ class NotificationsOptInPresenterTest {
presenter.present() presenter.present()
}.test { }.test {
val initialState = awaitItem() val initialState = awaitItem()
initialState.eventSink(NotificationsOptInEvents.NotNowClicked) initialState.eventSink(NotificationsOptInEvent.NotNowClicked)
// Allow background coroutines to run // Allow background coroutines to run
runCurrent() runCurrent()