Enable edgeToEdge support for compose CallScreen.

This commit is contained in:
Alex Hart
2025-08-14 10:19:33 -03:00
committed by Jeffrey Starke
parent 515f3dd43f
commit 1056e79361
3 changed files with 46 additions and 18 deletions

View File

@@ -6,6 +6,7 @@
package org.thoughtcrime.securesms.components.webrtc.v2
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
@@ -40,6 +41,7 @@ import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.reactions.any.ReactWithAnyEmojiBottomSheetDialogFragment
import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.service.webrtc.state.WebRtcEphemeralState
import org.thoughtcrime.securesms.util.WindowUtil
import org.thoughtcrime.securesms.webrtc.CallParticipantsViewState
import kotlin.time.Duration.Companion.seconds
@@ -61,6 +63,11 @@ class ComposeCallScreenMediator(private val activity: WebRtcCallActivity, viewMo
private val pendingParticipantsViewListener = MutableStateFlow<PendingParticipantsListener>(PendingParticipantsListener.Empty)
init {
WindowUtil.clearTranslucentNavigationBar(activity.window)
WindowUtil.clearTranslucentStatusBar(activity.window)
activity.enableEdgeToEdge()
activity.setContent {
val recipient by viewModel.getRecipientFlow().collectAsStateWithLifecycle(Recipient.UNKNOWN)
val webRtcCallState by callScreenViewModel.callState.collectAsStateWithLifecycle()

View File

@@ -103,7 +103,6 @@ class WebRtcCallActivity : BaseActivity(), SafetyNumberChangeDialog.Callback, Re
private const val VIBRATE_DURATION = 50
}
private lateinit var fullscreenHelper: FullscreenHelper
private lateinit var callScreen: CallScreenMediator
private var videoTooltip: Dismissible? = null
private var switchCameraTooltip: Dismissible? = null
@@ -144,22 +143,17 @@ class WebRtcCallActivity : BaseActivity(), SafetyNumberChangeDialog.Callback, Re
requestWindowFeature(Window.FEATURE_NO_TITLE)
fullscreenHelper = FullscreenHelper(this)
volumeControlStream = AudioManager.STREAM_VOICE_CALL
initializeResources()
initializeViewModel()
initializePictureInPictureParams()
callScreen.setControlsAndInfoVisibilityListener(FadeCallback())
fullscreenHelper.showAndHideWithSystemUI(
window,
findViewById(R.id.call_screen_header_gradient),
findViewById(R.id.webrtc_call_view_toolbar_text),
findViewById(R.id.webrtc_call_view_toolbar_no_text)
)
if (SignalStore.internal.newCallingUi) {
callScreen.setControlsAndInfoVisibilityListener(ComposeCallScreenControlsVisibilityListener())
} else {
callScreen.setControlsAndInfoVisibilityListener(ViewCallScreenControlsVisibilityListener())
}
if (savedInstanceState == null) {
logIntent(callIntent)
@@ -189,7 +183,9 @@ class WebRtcCallActivity : BaseActivity(), SafetyNumberChangeDialog.Callback, Re
initializePendingParticipantFragmentListener()
WindowUtil.setNavigationBarColor(this, ContextCompat.getColor(this, R.color.signal_dark_colorSurface))
if (!SignalStore.internal.newCallingUi) {
WindowUtil.setNavigationBarColor(this, ContextCompat.getColor(this, R.color.signal_dark_colorSurface))
}
if (!hasCameraPermission() && !hasAudioPermission()) {
askCameraAudioPermissions {
@@ -461,13 +457,11 @@ class WebRtcCallActivity : BaseActivity(), SafetyNumberChangeDialog.Callback, Re
private fun initializeResources() {
callScreen = CallScreenMediator.create(this, viewModel)
callScreen.setControlsListener(ControlsListener())
val viewRoot = rootView()
}
private fun initializeViewModel() {
val orientation: Orientation = resolveOrientationFromContext()
if (orientation == Orientation.PORTRAIT_BOTTOM_EDGE) {
if (orientation == Orientation.PORTRAIT_BOTTOM_EDGE && !SignalStore.internal.newCallingUi) {
WindowUtil.setNavigationBarColor(this, ContextCompat.getColor(this, R.color.signal_dark_colorSurface2))
WindowUtil.clearTranslucentNavigationBar(window)
}
@@ -1106,15 +1100,38 @@ class WebRtcCallActivity : BaseActivity(), SafetyNumberChangeDialog.Callback, Re
}
}
private inner class FadeCallback : CallControlsVisibilityListener {
private inner class ComposeCallScreenControlsVisibilityListener : CallControlsVisibilityListener {
override fun onShown() = Unit
override fun onHidden() {
val controlState = viewModel.getWebRtcControls().value
if (!controlState.displayErrorControls()) {
videoTooltip?.dismiss()
}
}
}
private inner class ViewCallScreenControlsVisibilityListener : CallControlsVisibilityListener {
private val fullScreenHelper: FullscreenHelper = FullscreenHelper(this@WebRtcCallActivity)
init {
fullScreenHelper.showAndHideWithSystemUI(
window,
findViewById(R.id.call_screen_header_gradient),
findViewById(R.id.webrtc_call_view_toolbar_text),
findViewById(R.id.webrtc_call_view_toolbar_no_text)
)
}
override fun onShown() {
fullscreenHelper.showSystemUI()
fullScreenHelper.showSystemUI()
}
override fun onHidden() {
val controlState = viewModel.getWebRtcControls().value
if (!controlState.displayErrorControls()) {
fullscreenHelper.hideSystemUI()
fullScreenHelper.hideSystemUI()
videoTooltip?.dismiss()
}
}

View File

@@ -82,6 +82,10 @@ public final class WindowUtil {
setSystemUiFlags(window, View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
public static void clearTranslucentStatusBar(@NonNull Window window) {
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
public static void setStatusBarColor(@NonNull Window window, @ColorInt int color) {
window.setStatusBarColor(color);
}