diff --git a/appnav/src/main/kotlin/io/element/android/appnav/root/RootView.kt b/appnav/src/main/kotlin/io/element/android/appnav/root/RootView.kt index 2bc76d7a5b..23f0d7f44a 100644 --- a/appnav/src/main/kotlin/io/element/android/appnav/root/RootView.kt +++ b/appnav/src/main/kotlin/io/element/android/appnav/root/RootView.kt @@ -17,7 +17,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.PreviewParameter import io.element.android.features.rageshake.api.crash.CrashDetectionEvents import io.element.android.features.rageshake.api.crash.CrashDetectionView -import io.element.android.features.rageshake.api.detection.RageshakeDetectionEvents +import io.element.android.features.rageshake.api.detection.RageshakeDetectionEvent import io.element.android.features.rageshake.api.detection.RageshakeDetectionView import io.element.android.libraries.designsystem.preview.ElementPreview import io.element.android.libraries.designsystem.preview.PreviewsDayNight @@ -40,7 +40,7 @@ fun RootView( fun onOpenBugReport() { state.crashDetectionState.eventSink(CrashDetectionEvents.ResetAppHasCrashed) - state.rageshakeDetectionState.eventSink(RageshakeDetectionEvents.Dismiss) + state.rageshakeDetectionState.eventSink(RageshakeDetectionEvent.Dismiss) onOpenBugReport.invoke() } diff --git a/features/rageshake/api/src/main/kotlin/io/element/android/features/rageshake/api/detection/RageshakeDetectionEvents.kt b/features/rageshake/api/src/main/kotlin/io/element/android/features/rageshake/api/detection/RageshakeDetectionEvent.kt similarity index 60% rename from features/rageshake/api/src/main/kotlin/io/element/android/features/rageshake/api/detection/RageshakeDetectionEvents.kt rename to features/rageshake/api/src/main/kotlin/io/element/android/features/rageshake/api/detection/RageshakeDetectionEvent.kt index 921ae861f2..83ae545d95 100644 --- a/features/rageshake/api/src/main/kotlin/io/element/android/features/rageshake/api/detection/RageshakeDetectionEvents.kt +++ b/features/rageshake/api/src/main/kotlin/io/element/android/features/rageshake/api/detection/RageshakeDetectionEvent.kt @@ -10,10 +10,10 @@ package io.element.android.features.rageshake.api.detection import io.element.android.features.rageshake.api.screenshot.ImageResult -sealed interface RageshakeDetectionEvents { - data object Dismiss : RageshakeDetectionEvents - data object Disable : RageshakeDetectionEvents - data object StartDetection : RageshakeDetectionEvents - data object StopDetection : RageshakeDetectionEvents - data class ProcessScreenshot(val imageResult: ImageResult) : RageshakeDetectionEvents +sealed interface RageshakeDetectionEvent { + data object Dismiss : RageshakeDetectionEvent + data object Disable : RageshakeDetectionEvent + data object StartDetection : RageshakeDetectionEvent + data object StopDetection : RageshakeDetectionEvent + data class ProcessScreenshot(val imageResult: ImageResult) : RageshakeDetectionEvent } diff --git a/features/rageshake/api/src/main/kotlin/io/element/android/features/rageshake/api/detection/RageshakeDetectionState.kt b/features/rageshake/api/src/main/kotlin/io/element/android/features/rageshake/api/detection/RageshakeDetectionState.kt index a240fed687..2e458e983a 100644 --- a/features/rageshake/api/src/main/kotlin/io/element/android/features/rageshake/api/detection/RageshakeDetectionState.kt +++ b/features/rageshake/api/src/main/kotlin/io/element/android/features/rageshake/api/detection/RageshakeDetectionState.kt @@ -15,5 +15,5 @@ data class RageshakeDetectionState( val showDialog: Boolean, val isStarted: Boolean, val preferenceState: RageshakePreferencesState, - val eventSink: (RageshakeDetectionEvents) -> Unit + val eventSink: (RageshakeDetectionEvent) -> Unit ) diff --git a/features/rageshake/api/src/main/kotlin/io/element/android/features/rageshake/api/detection/RageshakeDetectionView.kt b/features/rageshake/api/src/main/kotlin/io/element/android/features/rageshake/api/detection/RageshakeDetectionView.kt index dff6d9b716..745a362637 100644 --- a/features/rageshake/api/src/main/kotlin/io/element/android/features/rageshake/api/detection/RageshakeDetectionView.kt +++ b/features/rageshake/api/src/main/kotlin/io/element/android/features/rageshake/api/detection/RageshakeDetectionView.kt @@ -35,22 +35,22 @@ fun RageshakeDetectionView( val context = LocalContext.current OnLifecycleEvent { _, event -> when (event) { - Lifecycle.Event.ON_RESUME -> eventSink(RageshakeDetectionEvents.StartDetection) - Lifecycle.Event.ON_PAUSE -> eventSink(RageshakeDetectionEvents.StopDetection) + Lifecycle.Event.ON_RESUME -> eventSink(RageshakeDetectionEvent.StartDetection) + Lifecycle.Event.ON_PAUSE -> eventSink(RageshakeDetectionEvent.StopDetection) else -> Unit } } when { state.takeScreenshot -> TakeScreenshot( - onScreenshot = { eventSink(RageshakeDetectionEvents.ProcessScreenshot(it)) } + onScreenshot = { eventSink(RageshakeDetectionEvent.ProcessScreenshot(it)) } ) state.showDialog -> { LaunchedEffect(Unit) { context.vibrate() } RageshakeDialogContent( - onNoClick = { eventSink(RageshakeDetectionEvents.Dismiss) }, - onDisableClick = { eventSink(RageshakeDetectionEvents.Disable) }, + onNoClick = { eventSink(RageshakeDetectionEvent.Dismiss) }, + onDisableClick = { eventSink(RageshakeDetectionEvent.Disable) }, onYesClick = onOpenBugReport ) } diff --git a/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/detection/DefaultRageshakeDetectionPresenter.kt b/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/detection/DefaultRageshakeDetectionPresenter.kt index e7251c8700..3fa0a7ef6b 100644 --- a/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/detection/DefaultRageshakeDetectionPresenter.kt +++ b/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/detection/DefaultRageshakeDetectionPresenter.kt @@ -16,7 +16,7 @@ import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.saveable.rememberSaveable import dev.zacsweers.metro.AppScope import dev.zacsweers.metro.ContributesBinding -import io.element.android.features.rageshake.api.detection.RageshakeDetectionEvents +import io.element.android.features.rageshake.api.detection.RageshakeDetectionEvent import io.element.android.features.rageshake.api.detection.RageshakeDetectionPresenter import io.element.android.features.rageshake.api.detection.RageshakeDetectionState import io.element.android.features.rageshake.api.preferences.RageshakePreferencesEvents @@ -48,16 +48,16 @@ class DefaultRageshakeDetectionPresenter( mutableStateOf(false) } - fun handleEvent(event: RageshakeDetectionEvents) { + fun handleEvent(event: RageshakeDetectionEvent) { when (event) { - RageshakeDetectionEvents.Disable -> { + RageshakeDetectionEvent.Disable -> { preferencesState.eventSink(RageshakePreferencesEvents.SetIsEnabled(false)) showDialog.value = false } - RageshakeDetectionEvents.StartDetection -> isStarted.value = true - RageshakeDetectionEvents.StopDetection -> isStarted.value = false - is RageshakeDetectionEvents.ProcessScreenshot -> localCoroutineScope.processScreenshot(takeScreenshot, showDialog, event.imageResult) - RageshakeDetectionEvents.Dismiss -> showDialog.value = false + RageshakeDetectionEvent.StartDetection -> isStarted.value = true + RageshakeDetectionEvent.StopDetection -> isStarted.value = false + is RageshakeDetectionEvent.ProcessScreenshot -> localCoroutineScope.processScreenshot(takeScreenshot, showDialog, event.imageResult) + RageshakeDetectionEvent.Dismiss -> showDialog.value = false } } diff --git a/features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/detection/RageshakeDetectionPresenterTest.kt b/features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/detection/RageshakeDetectionPresenterTest.kt index d76ab73aa8..9db39e0ee9 100644 --- a/features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/detection/RageshakeDetectionPresenterTest.kt +++ b/features/rageshake/impl/src/test/kotlin/io/element/android/features/rageshake/impl/detection/RageshakeDetectionPresenterTest.kt @@ -13,7 +13,7 @@ import app.cash.molecule.RecompositionMode import app.cash.molecule.moleculeFlow import app.cash.turbine.test import com.google.common.truth.Truth.assertThat -import io.element.android.features.rageshake.api.detection.RageshakeDetectionEvents +import io.element.android.features.rageshake.api.detection.RageshakeDetectionEvent import io.element.android.features.rageshake.api.screenshot.ImageResult import io.element.android.features.rageshake.impl.preferences.DefaultRageshakePreferencesPresenter import io.element.android.features.rageshake.impl.rageshake.FakeRageShake @@ -87,9 +87,9 @@ class RageshakeDetectionPresenterTest { }.test { skipItems(1) val initialState = awaitItem() - initialState.eventSink.invoke(RageshakeDetectionEvents.StartDetection) + initialState.eventSink.invoke(RageshakeDetectionEvent.StartDetection) assertThat(awaitItem().isStarted).isTrue() - initialState.eventSink.invoke(RageshakeDetectionEvents.StopDetection) + initialState.eventSink.invoke(RageshakeDetectionEvent.StopDetection) assertThat(awaitItem().isStarted).isFalse() } } @@ -114,15 +114,15 @@ class RageshakeDetectionPresenterTest { skipItems(1) val initialState = awaitItem() assertThat(initialState.isStarted).isFalse() - initialState.eventSink.invoke(RageshakeDetectionEvents.StartDetection) + initialState.eventSink.invoke(RageshakeDetectionEvent.StartDetection) assertThat(awaitItem().isStarted).isTrue() rageshake.triggerPhoneRageshake() assertThat(awaitItem().takeScreenshot).isTrue() initialState.eventSink.invoke( - RageshakeDetectionEvents.ProcessScreenshot(ImageResult.Success(aBitmap)) + RageshakeDetectionEvent.ProcessScreenshot(ImageResult.Success(aBitmap)) ) assertThat(awaitItem().showDialog).isTrue() - initialState.eventSink.invoke(RageshakeDetectionEvents.Dismiss) + initialState.eventSink.invoke(RageshakeDetectionEvent.Dismiss) val finalState = awaitItem() assertThat(finalState.showDialog).isFalse() assertThat(rageshakeDataStore.isEnabled().first()).isTrue() @@ -149,15 +149,15 @@ class RageshakeDetectionPresenterTest { skipItems(1) val initialState = awaitItem() assertThat(initialState.isStarted).isFalse() - initialState.eventSink.invoke(RageshakeDetectionEvents.StartDetection) + initialState.eventSink.invoke(RageshakeDetectionEvent.StartDetection) assertThat(awaitItem().isStarted).isTrue() rageshake.triggerPhoneRageshake() assertThat(awaitItem().takeScreenshot).isTrue() initialState.eventSink.invoke( - RageshakeDetectionEvents.ProcessScreenshot(ImageResult.Error(AN_EXCEPTION)) + RageshakeDetectionEvent.ProcessScreenshot(ImageResult.Error(AN_EXCEPTION)) ) assertThat(awaitItem().showDialog).isTrue() - initialState.eventSink.invoke(RageshakeDetectionEvents.Dismiss) + initialState.eventSink.invoke(RageshakeDetectionEvent.Dismiss) val finalState = awaitItem() assertThat(finalState.showDialog).isFalse() assertThat(rageshakeDataStore.isEnabled().first()).isTrue() @@ -184,15 +184,15 @@ class RageshakeDetectionPresenterTest { skipItems(1) val initialState = awaitItem() assertThat(initialState.isStarted).isFalse() - initialState.eventSink.invoke(RageshakeDetectionEvents.StartDetection) + initialState.eventSink.invoke(RageshakeDetectionEvent.StartDetection) assertThat(awaitItem().isStarted).isTrue() rageshake.triggerPhoneRageshake() assertThat(awaitItem().takeScreenshot).isTrue() initialState.eventSink.invoke( - RageshakeDetectionEvents.ProcessScreenshot(ImageResult.Success(aBitmap)) + RageshakeDetectionEvent.ProcessScreenshot(ImageResult.Success(aBitmap)) ) assertThat(awaitItem().showDialog).isTrue() - initialState.eventSink.invoke(RageshakeDetectionEvents.Disable) + initialState.eventSink.invoke(RageshakeDetectionEvent.Disable) skipItems(1) assertThat(awaitItem().showDialog).isFalse() assertThat(rageshakeDataStore.isEnabled().first()).isFalse()