diff --git a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/pip/PictureInPictureEvents.kt b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/pip/PictureInPictureEvents.kt index be376aa079..4d29f757ea 100644 --- a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/pip/PictureInPictureEvents.kt +++ b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/pip/PictureInPictureEvents.kt @@ -16,10 +16,10 @@ package io.element.android.features.call.impl.pip -import io.element.android.features.call.impl.utils.WebPipApi +import io.element.android.features.call.impl.utils.PipController sealed interface PictureInPictureEvents { - data class SetupWebPipApi(val webPipApi: WebPipApi) : PictureInPictureEvents + data class SetPipController(val pipController: PipController) : PictureInPictureEvents data object EnterPictureInPicture : PictureInPictureEvents data class OnPictureInPictureModeChanged(val isInPip: Boolean) : PictureInPictureEvents } diff --git a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/pip/PictureInPicturePresenter.kt b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/pip/PictureInPicturePresenter.kt index 78d347d715..e6422f2dd6 100644 --- a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/pip/PictureInPicturePresenter.kt +++ b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/pip/PictureInPicturePresenter.kt @@ -22,7 +22,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue -import io.element.android.features.call.impl.utils.WebPipApi +import io.element.android.features.call.impl.utils.PipController import io.element.android.libraries.architecture.Presenter import io.element.android.libraries.core.log.logger.LoggerTag import kotlinx.coroutines.launch @@ -41,25 +41,25 @@ class PictureInPicturePresenter @Inject constructor( override fun present(): PictureInPictureState { val coroutineScope = rememberCoroutineScope() var isInPictureInPicture by remember { mutableStateOf(false) } - var webPipApi by remember { mutableStateOf(null) } + var pipController by remember { mutableStateOf(null) } fun handleEvent(event: PictureInPictureEvents) { when (event) { - is PictureInPictureEvents.SetupWebPipApi -> { - webPipApi = event.webPipApi + is PictureInPictureEvents.SetPipController -> { + pipController = event.pipController } PictureInPictureEvents.EnterPictureInPicture -> { coroutineScope.launch { - switchToPip(webPipApi) + switchToPip(pipController) } } is PictureInPictureEvents.OnPictureInPictureModeChanged -> { Timber.tag(loggerTag.value).d("onPictureInPictureModeChanged: ${event.isInPip}") isInPictureInPicture = event.isInPip if (event.isInPip) { - webPipApi?.enterPip() + pipController?.enterPip() } else { - webPipApi?.exitPip() + pipController?.exitPip() } } } @@ -85,12 +85,12 @@ class PictureInPicturePresenter @Inject constructor( /** * Enters Picture-in-Picture mode, if allowed by Element Call. */ - private suspend fun switchToPip(webPipApi: WebPipApi?) { + private suspend fun switchToPip(pipController: PipController?) { if (isPipSupported) { - if (webPipApi == null) { + if (pipController == null) { Timber.tag(loggerTag.value).w("webPipApi is not available") } - if (webPipApi == null || webPipApi.canEnterPip()) { + if (pipController == null || pipController.canEnterPip()) { Timber.tag(loggerTag.value).d("Switch to PiP mode") pipActivity?.enterPipMode() ?.also { Timber.tag(loggerTag.value).d("Switch to PiP mode result: $it") } diff --git a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/CallScreenView.kt b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/CallScreenView.kt index e81d386dc5..5c3d02b8ac 100644 --- a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/CallScreenView.kt +++ b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/CallScreenView.kt @@ -40,7 +40,7 @@ import io.element.android.features.call.impl.pip.PictureInPictureEvents import io.element.android.features.call.impl.pip.PictureInPictureState import io.element.android.features.call.impl.pip.PictureInPictureStateProvider import io.element.android.features.call.impl.pip.aPictureInPictureState -import io.element.android.features.call.impl.utils.WebViewWebPipApi +import io.element.android.features.call.impl.utils.WebViewPipController import io.element.android.features.call.impl.utils.WebViewWidgetMessageInterceptor import io.element.android.libraries.architecture.AsyncData import io.element.android.libraries.designsystem.components.ProgressDialog @@ -96,9 +96,9 @@ internal fun CallScreenView( } CallWebView( modifier = Modifier - .padding(padding) - .consumeWindowInsets(padding) - .fillMaxSize(), + .padding(padding) + .consumeWindowInsets(padding) + .fillMaxSize(), url = state.urlState, userAgent = state.userAgent, onPermissionsRequest = { request -> @@ -109,8 +109,8 @@ internal fun CallScreenView( onWebViewCreate = { webView -> val interceptor = WebViewWidgetMessageInterceptor(webView) state.eventSink(CallScreenEvents.SetupMessageChannels(interceptor)) - val webPipApi = WebViewWebPipApi(webView) - pipState.eventSink(PictureInPictureEvents.SetupWebPipApi(webPipApi)) + val pipController = WebViewPipController(webView) + pipState.eventSink(PictureInPictureEvents.SetPipController(pipController)) } ) when (state.urlState) { diff --git a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebPipApi.kt b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/PipController.kt similarity index 96% rename from features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebPipApi.kt rename to features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/PipController.kt index af1cc6b3f9..01e23ab727 100644 --- a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebPipApi.kt +++ b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/PipController.kt @@ -16,7 +16,7 @@ package io.element.android.features.call.impl.utils -interface WebPipApi { +interface PipController { suspend fun canEnterPip(): Boolean fun enterPip() fun exitPip() diff --git a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebViewWebPipApi.kt b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebViewPipController.kt similarity index 96% rename from features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebViewWebPipApi.kt rename to features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebViewPipController.kt index baf682d6b3..2a90965c8c 100644 --- a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebViewWebPipApi.kt +++ b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebViewPipController.kt @@ -20,9 +20,9 @@ import android.webkit.WebView import kotlin.coroutines.resume import kotlin.coroutines.suspendCoroutine -class WebViewWebPipApi( +class WebViewPipController( private val webView: WebView, -) : WebPipApi { +) : PipController { override suspend fun canEnterPip(): Boolean { return suspendCoroutine { continuation -> webView.evaluateJavascript("controls.canEnterPip()") { result -> diff --git a/features/call/impl/src/test/kotlin/io/element/android/features/call/impl/pip/FakeWebPipApi.kt b/features/call/impl/src/test/kotlin/io/element/android/features/call/impl/pip/FakePipController.kt similarity index 90% rename from features/call/impl/src/test/kotlin/io/element/android/features/call/impl/pip/FakeWebPipApi.kt rename to features/call/impl/src/test/kotlin/io/element/android/features/call/impl/pip/FakePipController.kt index ca752cd8ce..086feecd39 100644 --- a/features/call/impl/src/test/kotlin/io/element/android/features/call/impl/pip/FakeWebPipApi.kt +++ b/features/call/impl/src/test/kotlin/io/element/android/features/call/impl/pip/FakePipController.kt @@ -16,14 +16,14 @@ package io.element.android.features.call.impl.pip -import io.element.android.features.call.impl.utils.WebPipApi +import io.element.android.features.call.impl.utils.PipController import io.element.android.tests.testutils.lambda.lambdaError -class FakeWebPipApi( +class FakePipController( private val canEnterPipResult: () -> Boolean = { lambdaError() }, private val enterPipResult: () -> Unit = { lambdaError() }, private val exitPipResult: () -> Unit = { lambdaError() }, -) : WebPipApi { +) : PipController { override suspend fun canEnterPip(): Boolean = canEnterPipResult() override fun enterPip() = enterPipResult() diff --git a/features/call/impl/src/test/kotlin/io/element/android/features/call/impl/pip/PictureInPicturePresenterTest.kt b/features/call/impl/src/test/kotlin/io/element/android/features/call/impl/pip/PictureInPicturePresenterTest.kt index 2343f2cb70..a5fb1f8beb 100644 --- a/features/call/impl/src/test/kotlin/io/element/android/features/call/impl/pip/PictureInPicturePresenterTest.kt +++ b/features/call/impl/src/test/kotlin/io/element/android/features/call/impl/pip/PictureInPicturePresenterTest.kt @@ -92,7 +92,7 @@ class PictureInPicturePresenterTest { presenter.present() }.test { val initialState = awaitItem() - initialState.eventSink(PictureInPictureEvents.SetupWebPipApi(FakeWebPipApi(canEnterPipResult = { false }))) + initialState.eventSink(PictureInPictureEvents.SetPipController(FakePipController(canEnterPipResult = { false }))) initialState.eventSink(PictureInPictureEvents.EnterPictureInPicture) handUpResult.assertions().isCalledOnce() } @@ -115,8 +115,8 @@ class PictureInPicturePresenterTest { }.test { val initialState = awaitItem() initialState.eventSink( - PictureInPictureEvents.SetupWebPipApi( - FakeWebPipApi( + PictureInPictureEvents.SetPipController( + FakePipController( canEnterPipResult = { true }, enterPipResult = enterPipResult, exitPipResult = exitPipResult, diff --git a/features/call/impl/src/test/kotlin/io/element/android/features/call/impl/ui/CallScreenViewTest.kt b/features/call/impl/src/test/kotlin/io/element/android/features/call/impl/ui/CallScreenViewTest.kt index e92e9cc4e6..ec75b9a1fa 100644 --- a/features/call/impl/src/test/kotlin/io/element/android/features/call/impl/ui/CallScreenViewTest.kt +++ b/features/call/impl/src/test/kotlin/io/element/android/features/call/impl/ui/CallScreenViewTest.kt @@ -52,7 +52,7 @@ class CallScreenViewTest { eventsRecorder.assertTrue(0) { it is CallScreenEvents.SetupMessageChannels } eventsRecorder.assertTrue(1) { it == CallScreenEvents.Hangup } pipEventsRecorder.assertSize(1) - pipEventsRecorder.assertTrue(0) { it is PictureInPictureEvents.SetupWebPipApi } + pipEventsRecorder.assertTrue(0) { it is PictureInPictureEvents.SetPipController } } @Test @@ -72,7 +72,7 @@ class CallScreenViewTest { eventsRecorder.assertSize(1) eventsRecorder.assertTrue(0) { it is CallScreenEvents.SetupMessageChannels } pipEventsRecorder.assertSize(2) - pipEventsRecorder.assertTrue(0) { it is PictureInPictureEvents.SetupWebPipApi } + pipEventsRecorder.assertTrue(0) { it is PictureInPictureEvents.SetPipController } pipEventsRecorder.assertTrue(1) { it == PictureInPictureEvents.EnterPictureInPicture } } }