Rename WebPipApi to PipController
This commit is contained in:
parent
0b2edcb6d1
commit
306043876f
8 changed files with 29 additions and 29 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<WebPipApi?>(null) }
|
||||
var pipController by remember { mutableStateOf<PipController?>(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") }
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package io.element.android.features.call.impl.utils
|
||||
|
||||
interface WebPipApi {
|
||||
interface PipController {
|
||||
suspend fun canEnterPip(): Boolean
|
||||
fun enterPip()
|
||||
fun exitPip()
|
||||
|
|
@ -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 ->
|
||||
Loading…
Add table
Add a link
Reference in a new issue