ElementCall: allow user to switch to another call.

This commit is contained in:
Benoit Marty 2024-11-07 18:33:37 +01:00
parent 9042ed6458
commit f66193e317

View file

@ -35,6 +35,7 @@ import androidx.core.content.IntentCompat
import androidx.core.util.Consumer import androidx.core.util.Consumer
import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle
import io.element.android.features.call.api.CallType import io.element.android.features.call.api.CallType
import io.element.android.features.call.api.CallType.ExternalUrl
import io.element.android.features.call.impl.DefaultElementCallEntryPoint import io.element.android.features.call.impl.DefaultElementCallEntryPoint
import io.element.android.features.call.impl.di.CallBindings import io.element.android.features.call.impl.di.CallBindings
import io.element.android.features.call.impl.pip.PictureInPictureEvents import io.element.android.features.call.impl.pip.PictureInPictureEvents
@ -49,6 +50,8 @@ import io.element.android.libraries.preferences.api.store.AppPreferencesStore
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
private const val loggerTag = "ElementCallActivity"
class ElementCallActivity : class ElementCallActivity :
AppCompatActivity(), AppCompatActivity(),
CallScreenNavigator, CallScreenNavigator,
@ -132,7 +135,7 @@ class ElementCallActivity :
DisposableEffect(Unit) { DisposableEffect(Unit) {
val listener = Runnable { val listener = Runnable {
if (requestPermissionCallback != null) { if (requestPermissionCallback != null) {
Timber.w("Ignoring onUserLeaveHint event because user is asked to grant permissions") Timber.tag(loggerTag).w("Ignoring onUserLeaveHint event because user is asked to grant permissions")
} else { } else {
pipEventSink(PictureInPictureEvents.EnterPictureInPicture) pipEventSink(PictureInPictureEvents.EnterPictureInPicture)
} }
@ -146,7 +149,7 @@ class ElementCallActivity :
val onPictureInPictureModeChangedListener = Consumer { _: PictureInPictureModeChangedInfo -> val onPictureInPictureModeChangedListener = Consumer { _: PictureInPictureModeChangedInfo ->
pipEventSink(PictureInPictureEvents.OnPictureInPictureModeChanged(isInPictureInPictureMode)) pipEventSink(PictureInPictureEvents.OnPictureInPictureModeChanged(isInPictureInPictureMode))
if (!isInPictureInPictureMode && !lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) { if (!isInPictureInPictureMode && !lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) {
Timber.d("Exiting PiP mode: Hangup the call") Timber.tag(loggerTag).d("Exiting PiP mode: Hangup the call")
eventSink?.invoke(CallScreenEvents.Hangup) eventSink?.invoke(CallScreenEvents.Hangup)
} }
} }
@ -185,23 +188,23 @@ class ElementCallActivity :
private fun setCallType(intent: Intent?) { private fun setCallType(intent: Intent?) {
val callType = intent?.let { val callType = intent?.let {
IntentCompat.getParcelableExtra(it, DefaultElementCallEntryPoint.EXTRA_CALL_TYPE, CallType::class.java) IntentCompat.getParcelableExtra(intent, DefaultElementCallEntryPoint.EXTRA_CALL_TYPE, CallType::class.java)
?: intent.dataString?.let(::parseUrl)?.let(::ExternalUrl)
} }
val intentUrl = intent?.dataString?.let(::parseUrl) val currentCallType = webViewTarget.value
when { if (currentCallType == null && callType == null) {
// Re-opened the activity but we have no url to load or a cached one, finish the activity Timber.tag(loggerTag).d("Re-opened the activity but we have no url to load or a cached one, finish the activity")
intent?.dataString == null && callType == null && webViewTarget.value == null -> finish() finish()
callType != null -> { } else if (currentCallType == null) {
webViewTarget.value = callType Timber.tag(loggerTag).d("Set the call type and create the presenter")
presenter = presenterFactory.create(callType, this) webViewTarget.value = callType
} presenter = presenterFactory.create(callType!!, this)
intentUrl != null -> { } else if (callType != currentCallType) {
val fallbackInputs = CallType.ExternalUrl(intentUrl) Timber.tag(loggerTag).d("User starts another call, restart the Activity")
webViewTarget.value = fallbackInputs setIntent(intent)
presenter = presenterFactory.create(fallbackInputs, this) recreate()
} } else {
// Coming back from notification, do nothing Timber.tag(loggerTag).d("Coming back from notification, do nothing")
else -> return
} }
} }