From f9e9bc86d26bc687ed15f89e741cfd1159d1adc4 Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Mon, 8 Jul 2024 09:39:34 +1000 Subject: [PATCH] Showing floating video inset only when there is at least one video stream active, hiding it when both are inactive --- .../securesms/calls/WebRtcCallActivity.kt | 19 +++++++++++++++++-- .../securesms/webrtc/CallManager.kt | 4 +--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/calls/WebRtcCallActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/calls/WebRtcCallActivity.kt index 8d14d6a6aa..598ce624bd 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/calls/WebRtcCallActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/calls/WebRtcCallActivity.kt @@ -247,6 +247,12 @@ class WebRtcCallActivity : PassphraseRequiredActionBarActivity(), SensorEventLis } } + /** + * We need to track the device's orientation so we can calculate whether or not to rotate the video streams + * This works a lot better than using `OrientationEventListener > onOrientationChanged' + * which gives us a rotation angle that doesn't take into account pitch vs roll, so tipping the device from front to back would + * trigger the video rotation logic, while we really only want it when the device is in portrait or landscape. + */ override fun onSensorChanged(event: SensorEvent) { if (event.sensor.type == Sensor.TYPE_ROTATION_VECTOR) { // Get the quaternion from the rotation vector sensor @@ -268,7 +274,6 @@ class WebRtcCallActivity : PassphraseRequiredActionBarActivity(), SensorEventLis if (currentOrientation != lastOrientation) { lastOrientation = currentOrientation - Log.d("", "*********** orientation: $currentOrientation") viewModel.deviceOrientation = currentOrientation } } @@ -422,12 +427,22 @@ class WebRtcCallActivity : PassphraseRequiredActionBarActivity(), SensorEventLis } } - // handle video windows + // handle video state launch { viewModel.videoState.collect { state -> binding.floatingRenderer.removeAllViews() binding.fullscreenRenderer.removeAllViews() + // the floating video inset (empty or not) should be shown + // the moment we have either of the video streams + if(!state.userVideoEnabled && !state.remoteVideoEnabled){ + binding.floatingRendererContainer.isVisible = false + binding.swapViewIcon.isVisible = false + } else { + binding.floatingRendererContainer.isVisible = true + binding.swapViewIcon.isVisible = true + } + // handle fullscreen video window if(state.showFullscreenVideo()){ viewModel.fullscreenRenderer?.let { surfaceView -> diff --git a/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt b/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt index 6a46722f18..5b9d0a8aa7 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt @@ -628,9 +628,7 @@ class CallManager( _videoState.value = _videoState.value.copy(swapped = videoSwapped) handleMirroring() -//todo TOM received rotated video shouldn't be full scale - //todo TOM make sure the swap icon is visible - //todo TOM Should we show the 'no video' inset straight away? + //todo TOM floating inset loses its rounded corners when the second surfaceview is added //todo TOM ios rotates the controls in landscape ( just the buttons though, not the whole ui??) if (!videoSwapped) {