From aed9b5546c315317b9922a99f2c61d4cc954b819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Saleniuk?= Date: Mon, 24 Jun 2024 18:01:31 +0200 Subject: [PATCH] move handling sending video feed to separate function --- .../ui/calling/ongoing/OngoingCallScreen.kt | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/app/src/main/kotlin/com/wire/android/ui/calling/ongoing/OngoingCallScreen.kt b/app/src/main/kotlin/com/wire/android/ui/calling/ongoing/OngoingCallScreen.kt index 76d26ddef69..f46bc09c891 100644 --- a/app/src/main/kotlin/com/wire/android/ui/calling/ongoing/OngoingCallScreen.kt +++ b/app/src/main/kotlin/com/wire/android/ui/calling/ongoing/OngoingCallScreen.kt @@ -58,6 +58,7 @@ import androidx.lifecycle.LifecycleEventObserver import androidx.lifecycle.LifecycleOwner import com.wire.android.R import com.wire.android.ui.LocalActivity +import com.wire.android.ui.calling.CallState import com.wire.android.ui.calling.ConversationName import com.wire.android.ui.calling.SharedCallingViewModel import com.wire.android.ui.calling.controlbuttons.CameraButton @@ -163,25 +164,36 @@ fun OngoingCallScreen( hideDialog = permissionPermanentlyDeniedDialogState::dismiss ) + HandleSendingVideoFeed( + callState = sharedCallingViewModel.callState, + pauseSendingVideoFeed = ongoingCallViewModel::pauseSendingVideoFeed, + startSendingVideoFeed = ongoingCallViewModel::startSendingVideoFeed, + stopSendingVideoFeed = ongoingCallViewModel::stopSendingVideoFeed, + clearVideoPreview = sharedCallingViewModel::clearVideoPreview, + ) +} + +@Composable +private fun HandleSendingVideoFeed( + callState: CallState, + pauseSendingVideoFeed: () -> Unit, + startSendingVideoFeed: () -> Unit, + stopSendingVideoFeed: () -> Unit, + clearVideoPreview: () -> Unit, +) { // Pause the video feed when the lifecycle is paused and resume it when the lifecycle is resumed. val lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current DisposableEffect(lifecycleOwner) { val observer = LifecycleEventObserver { _, event -> - if (event == Lifecycle.Event.ON_PAUSE && - sharedCallingViewModel.callState.callStatus == CallStatus.ESTABLISHED && - sharedCallingViewModel.callState.isCameraOn - ) { - ongoingCallViewModel.pauseSendingVideoFeed() + if (event == Lifecycle.Event.ON_PAUSE && callState.callStatus == CallStatus.ESTABLISHED && callState.isCameraOn) { + pauseSendingVideoFeed() } - if (event == Lifecycle.Event.ON_RESUME && - sharedCallingViewModel.callState.callStatus == CallStatus.ESTABLISHED && - sharedCallingViewModel.callState.isCameraOn - ) { - ongoingCallViewModel.startSendingVideoFeed() + if (event == Lifecycle.Event.ON_RESUME && callState.callStatus == CallStatus.ESTABLISHED && callState.isCameraOn) { + startSendingVideoFeed() } if (event == Lifecycle.Event.ON_DESTROY) { - sharedCallingViewModel.clearVideoPreview() + clearVideoPreview() } } @@ -193,11 +205,11 @@ fun OngoingCallScreen( } // Start/stop sending video feed based on the camera state when the call is established. - LaunchedEffect(sharedCallingViewModel.callState.callStatus, sharedCallingViewModel.callState.isCameraOn) { - if (sharedCallingViewModel.callState.callStatus == CallStatus.ESTABLISHED) { - when (sharedCallingViewModel.callState.isCameraOn) { - true -> ongoingCallViewModel.startSendingVideoFeed() - false -> ongoingCallViewModel.stopSendingVideoFeed() + LaunchedEffect(callState.callStatus, callState.isCameraOn) { + if (callState.callStatus == CallStatus.ESTABLISHED) { + when (callState.isCameraOn) { + true -> startSendingVideoFeed() + false -> stopSendingVideoFeed() } } }