From 77a42f2198c5c4e888ee28a87c02af8244ab87d4 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 15 Jul 2024 16:45:57 +0200 Subject: [PATCH] Call in PiP: when closing PiP, hang up the call. The Activity is actually not destroyed as I expected. --- .../features/call/impl/ui/ElementCallActivity.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/ElementCallActivity.kt b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/ElementCallActivity.kt index b0d41efe9e..3af6c7cf95 100644 --- a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/ElementCallActivity.kt +++ b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/ElementCallActivity.kt @@ -32,6 +32,7 @@ import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.compose.runtime.mutableStateOf import androidx.core.content.IntentCompat +import androidx.lifecycle.Lifecycle import io.element.android.features.call.api.CallType import io.element.android.features.call.impl.DefaultElementCallEntryPoint import io.element.android.features.call.impl.di.CallBindings @@ -41,6 +42,7 @@ import io.element.android.features.call.impl.utils.CallIntentDataParser import io.element.android.libraries.architecture.bindings import io.element.android.libraries.designsystem.theme.ElementThemeApp import io.element.android.libraries.preferences.api.store.AppPreferencesStore +import timber.log.Timber import javax.inject.Inject class ElementCallActivity : AppCompatActivity(), CallScreenNavigator { @@ -63,6 +65,8 @@ class ElementCallActivity : AppCompatActivity(), CallScreenNavigator { private var isDarkMode = false private val webViewTarget = mutableStateOf(null) + private var eventSink: ((CallScreenEvents) -> Unit)? = null + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -91,6 +95,7 @@ class ElementCallActivity : AppCompatActivity(), CallScreenNavigator { val pipState = pictureInPicturePresenter.present() ElementThemeApp(appPreferencesStore) { val state = presenter.present() + eventSink = state.eventSink CallScreenView( state = state, pipState = pipState, @@ -111,6 +116,11 @@ class ElementCallActivity : AppCompatActivity(), CallScreenNavigator { override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean, newConfig: Configuration) { super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig) pictureInPicturePresenter.onPictureInPictureModeChanged(isInPictureInPictureMode) + + if (!isInPictureInPictureMode && !lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) { + Timber.d("Exiting PiP mode: Hangup the call") + eventSink?.invoke(CallScreenEvents.Hangup) + } } override fun onNewIntent(intent: Intent) {