RageshakeDetectionEvents -> RageshakeDetectionEvent
This commit is contained in:
parent
f5dd10388e
commit
7a366a0c88
6 changed files with 33 additions and 33 deletions
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -15,5 +15,5 @@ data class RageshakeDetectionState(
|
|||
val showDialog: Boolean,
|
||||
val isStarted: Boolean,
|
||||
val preferenceState: RageshakePreferencesState,
|
||||
val eventSink: (RageshakeDetectionEvents) -> Unit
|
||||
val eventSink: (RageshakeDetectionEvent) -> Unit
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue