@@ -35,6 +35,7 @@ import androidx.core.content.IntentCompat
3535import androidx.core.util.Consumer
3636import androidx.lifecycle.Lifecycle
3737import io.element.android.features.call.api.CallType
38+ import io.element.android.features.call.api.CallType.ExternalUrl
3839import io.element.android.features.call.impl.DefaultElementCallEntryPoint
3940import io.element.android.features.call.impl.di.CallBindings
4041import io.element.android.features.call.impl.pip.PictureInPictureEvents
@@ -49,6 +50,8 @@ import io.element.android.libraries.preferences.api.store.AppPreferencesStore
4950import timber.log.Timber
5051import javax.inject.Inject
5152
53+ private const val loggerTag = " ElementCallActivity"
54+
5255class ElementCallActivity :
5356 AppCompatActivity (),
5457 CallScreenNavigator ,
@@ -132,7 +135,7 @@ class ElementCallActivity :
132135 DisposableEffect (Unit ) {
133136 val listener = Runnable {
134137 if (requestPermissionCallback != null ) {
135- Timber .w(" Ignoring onUserLeaveHint event because user is asked to grant permissions" )
138+ Timber .tag(loggerTag). w(" Ignoring onUserLeaveHint event because user is asked to grant permissions" )
136139 } else {
137140 pipEventSink(PictureInPictureEvents .EnterPictureInPicture )
138141 }
@@ -146,7 +149,7 @@ class ElementCallActivity :
146149 val onPictureInPictureModeChangedListener = Consumer { _: PictureInPictureModeChangedInfo ->
147150 pipEventSink(PictureInPictureEvents .OnPictureInPictureModeChanged (isInPictureInPictureMode))
148151 if (! isInPictureInPictureMode && ! lifecycle.currentState.isAtLeast(Lifecycle .State .STARTED )) {
149- Timber .d(" Exiting PiP mode: Hangup the call" )
152+ Timber .tag(loggerTag). d(" Exiting PiP mode: Hangup the call" )
150153 eventSink?.invoke(CallScreenEvents .Hangup )
151154 }
152155 }
@@ -185,23 +188,23 @@ class ElementCallActivity :
185188
186189 private fun setCallType (intent : Intent ? ) {
187190 val callType = intent?.let {
188- IntentCompat .getParcelableExtra(it, DefaultElementCallEntryPoint .EXTRA_CALL_TYPE , CallType ::class .java)
191+ IntentCompat .getParcelableExtra(intent, DefaultElementCallEntryPoint .EXTRA_CALL_TYPE , CallType ::class .java)
192+ ? : intent.dataString?.let (::parseUrl)?.let (::ExternalUrl )
189193 }
190- val intentUrl = intent?.dataString?.let (::parseUrl)
191- when {
192- // Re-opened the activity but we have no url to load or a cached one, finish the activity
193- intent?.dataString == null && callType == null && webViewTarget.value == null -> finish()
194- callType != null -> {
195- webViewTarget.value = callType
196- presenter = presenterFactory.create(callType, this )
197- }
198- intentUrl != null -> {
199- val fallbackInputs = CallType .ExternalUrl (intentUrl)
200- webViewTarget.value = fallbackInputs
201- presenter = presenterFactory.create(fallbackInputs, this )
202- }
203- // Coming back from notification, do nothing
204- else -> return
194+ val currentCallType = webViewTarget.value
195+ if (currentCallType == null && callType == null ) {
196+ Timber .tag(loggerTag).d(" Re-opened the activity but we have no url to load or a cached one, finish the activity" )
197+ finish()
198+ } else if (currentCallType == null ) {
199+ Timber .tag(loggerTag).d(" Set the call type and create the presenter" )
200+ webViewTarget.value = callType
201+ presenter = presenterFactory.create(callType!! , this )
202+ } else if (callType != currentCallType) {
203+ Timber .tag(loggerTag).d(" User starts another call, restart the Activity" )
204+ setIntent(intent)
205+ recreate()
206+ } else {
207+ Timber .tag(loggerTag).d(" Coming back from notification, do nothing" )
205208 }
206209 }
207210
0 commit comments