Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep screen on during voice message recording #1684

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -124,6 +125,8 @@ fun MessagesView(
state.voiceMessageComposerState.eventSink(VoiceMessageComposerEvents.LifecycleEvent(event))
}

KeepScreenOn(state.voiceMessageComposerState.keepScreenOn)

AttachmentStateView(
state = state.composerState.attachmentsState,
onPreviewAttachments = onPreviewAttachments,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down Expand Up @@ -191,6 +192,7 @@ class VoiceMessageComposerPresenter @Inject constructor(
else -> VoiceMessageState.Idle
},
showPermissionRationaleDialog = permissionState.showDialog,
keepScreenOn = keepScreenOn,
eventSink = handleEvents,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Original file line number Diff line number Diff line change
Expand Up @@ -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 = {},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading