Browse Source
Also only use eventSink to communicate with the Presenter, instead of having public methods. Change WeakReference to an Activity to a listener and update tests.pull/3334/head
Benoit Marty
4 weeks ago
committed by
Benoit Marty
10 changed files with 317 additions and 79 deletions
@ -0,0 +1,23 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2024 New Vector Ltd |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0 |
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package io.element.android.features.call.impl.pip |
||||||
|
|
||||||
|
interface PipActivity { |
||||||
|
fun setPipParams() |
||||||
|
fun enterPipMode(): Boolean |
||||||
|
fun hangUp() |
||||||
|
} |
@ -0,0 +1,23 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2024 New Vector Ltd |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0 |
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package io.element.android.features.call.impl.utils |
||||||
|
|
||||||
|
interface WebPipApi { |
||||||
|
suspend fun canEnterPip(): Boolean |
||||||
|
fun enterPip() |
||||||
|
fun exitPip() |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2024 New Vector Ltd |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0 |
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package io.element.android.features.call.impl.utils |
||||||
|
|
||||||
|
import android.webkit.WebView |
||||||
|
import kotlin.coroutines.resume |
||||||
|
import kotlin.coroutines.suspendCoroutine |
||||||
|
|
||||||
|
class WebViewWebPipApi( |
||||||
|
private val webView: WebView, |
||||||
|
) : WebPipApi { |
||||||
|
override suspend fun canEnterPip(): Boolean { |
||||||
|
return suspendCoroutine { continuation -> |
||||||
|
webView.evaluateJavascript("controls.canEnterPip()") { result -> |
||||||
|
continuation.resume(result == "true") |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun enterPip() { |
||||||
|
webView.evaluateJavascript("controls.enablePip()", null) |
||||||
|
} |
||||||
|
|
||||||
|
override fun exitPip() { |
||||||
|
webView.evaluateJavascript("controls.disablePip()", null) |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,29 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2024 New Vector Ltd |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0 |
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package io.element.android.features.call.impl.pip |
||||||
|
|
||||||
|
import io.element.android.tests.testutils.lambda.lambdaError |
||||||
|
|
||||||
|
class FakePipActivity( |
||||||
|
private val setPipParamsResult: () -> Unit = { lambdaError() }, |
||||||
|
private val enterPipModeResult: () -> Boolean = { lambdaError() }, |
||||||
|
private val handUpResult: () -> Unit = { lambdaError() } |
||||||
|
) : PipActivity { |
||||||
|
override fun setPipParams() = setPipParamsResult() |
||||||
|
override fun enterPipMode(): Boolean = enterPipModeResult() |
||||||
|
override fun hangUp() = handUpResult() |
||||||
|
} |
@ -0,0 +1,32 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2024 New Vector Ltd |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0 |
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package io.element.android.features.call.impl.pip |
||||||
|
|
||||||
|
import io.element.android.features.call.impl.utils.WebPipApi |
||||||
|
import io.element.android.tests.testutils.lambda.lambdaError |
||||||
|
|
||||||
|
class FakeWebPipApi( |
||||||
|
private val canEnterPipResult: () -> Boolean = { lambdaError() }, |
||||||
|
private val enterPipResult: () -> Unit = { lambdaError() }, |
||||||
|
private val exitPipResult: () -> Unit = { lambdaError() }, |
||||||
|
) : WebPipApi { |
||||||
|
override suspend fun canEnterPip(): Boolean = canEnterPipResult() |
||||||
|
|
||||||
|
override fun enterPip() = enterPipResult() |
||||||
|
|
||||||
|
override fun exitPip() = exitPipResult() |
||||||
|
} |
Loading…
Reference in new issue