diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt index 5c08c62849..cc89ba3658 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt @@ -93,6 +93,7 @@ import io.element.android.libraries.designsystem.theme.components.Scaffold import io.element.android.libraries.designsystem.theme.components.Text import io.element.android.libraries.designsystem.theme.components.TopAppBar import io.element.android.libraries.designsystem.utils.CommonDrawables +import io.element.android.libraries.designsystem.utils.KeepScreenOn import io.element.android.libraries.designsystem.utils.LogCompositions import io.element.android.libraries.designsystem.utils.OnLifecycleEvent import io.element.android.libraries.designsystem.utils.snackbar.SnackbarHost @@ -124,6 +125,8 @@ fun MessagesView( state.voiceMessageComposerState.eventSink(VoiceMessageComposerEvents.LifecycleEvent(event)) } + KeepScreenOn(state.voiceMessageComposerState.keepScreenOn) + AttachmentStateView( state = state.composerState.attachmentsState, onPreviewAttachments = onPreviewAttachments, diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/voicemessages/composer/VoiceMessageComposerPresenter.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/voicemessages/composer/VoiceMessageComposerPresenter.kt index c8edec15a6..7cde5739ba 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/voicemessages/composer/VoiceMessageComposerPresenter.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/voicemessages/composer/VoiceMessageComposerPresenter.kt @@ -64,6 +64,7 @@ class VoiceMessageComposerPresenter @Inject constructor( override fun present(): VoiceMessageComposerState { val localCoroutineScope = rememberCoroutineScope() val recorderState by voiceRecorder.state.collectAsState(initial = VoiceRecorderState.Idle) + val keepScreenOn by remember { derivedStateOf { recorderState is VoiceRecorderState.Recording } } val permissionState = permissionsPresenter.present() var isSending by remember { mutableStateOf(false) } @@ -191,6 +192,7 @@ class VoiceMessageComposerPresenter @Inject constructor( else -> VoiceMessageState.Idle }, showPermissionRationaleDialog = permissionState.showDialog, + keepScreenOn = keepScreenOn, eventSink = handleEvents, ) } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/voicemessages/composer/VoiceMessageComposerState.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/voicemessages/composer/VoiceMessageComposerState.kt index fc7f0ad15f..055fa28177 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/voicemessages/composer/VoiceMessageComposerState.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/voicemessages/composer/VoiceMessageComposerState.kt @@ -23,6 +23,7 @@ import io.element.android.libraries.textcomposer.model.VoiceMessageState data class VoiceMessageComposerState( val voiceMessageState: VoiceMessageState, val showPermissionRationaleDialog: Boolean, + val keepScreenOn: Boolean, val eventSink: (VoiceMessageComposerEvents) -> Unit, ) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/voicemessages/composer/VoiceMessageComposerStateProvider.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/voicemessages/composer/VoiceMessageComposerStateProvider.kt index 150381461b..f9856005bb 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/voicemessages/composer/VoiceMessageComposerStateProvider.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/voicemessages/composer/VoiceMessageComposerStateProvider.kt @@ -30,10 +30,12 @@ internal open class VoiceMessageComposerStateProvider : PreviewParameterProvider internal fun aVoiceMessageComposerState( voiceMessageState: VoiceMessageState = VoiceMessageState.Idle, + keepScreenOn: Boolean = false, showPermissionRationaleDialog: Boolean = false, ) = VoiceMessageComposerState( voiceMessageState = voiceMessageState, showPermissionRationaleDialog = showPermissionRationaleDialog, + keepScreenOn = keepScreenOn, eventSink = {}, ) diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/voicemessages/composer/VoiceMessageComposerPresenterTest.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/voicemessages/composer/VoiceMessageComposerPresenterTest.kt index c0d1723c36..b35f5c66b3 100644 --- a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/voicemessages/composer/VoiceMessageComposerPresenterTest.kt +++ b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/voicemessages/composer/VoiceMessageComposerPresenterTest.kt @@ -101,6 +101,30 @@ class VoiceMessageComposerPresenterTest { } } + @Test + fun `present - recording keeps screen on`() = runTest { + val presenter = createVoiceMessageComposerPresenter() + moleculeFlow(RecompositionMode.Immediate) { + presenter.present() + }.test { + awaitItem().apply { + eventSink(VoiceMessageComposerEvents.RecordButtonEvent(PressEvent.PressStart)) + assertThat(keepScreenOn).isFalse() + } + + awaitItem().apply { + assertThat(keepScreenOn).isTrue() + eventSink(VoiceMessageComposerEvents.RecordButtonEvent(PressEvent.LongPressEnd)) + } + + val finalState = awaitItem().apply { + assertThat(keepScreenOn).isFalse() + } + + testPauseAndDestroy(finalState) + } + } + @Test fun `present - abort recording`() = runTest { val presenter = createVoiceMessageComposerPresenter()