Keep screen on during voice message recording (#1684)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
|
||||
@@ -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 = {},
|
||||
)
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user