Skip to content

Commit 64b1f30

Browse files
authored
Merge pull request #3833 from element-hq/feature/bma/elementCallSwitch
ElementCall: allow user to switch to another call.
2 parents 2873a68 + d09df1b commit 64b1f30

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/ElementCallActivity.kt

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import androidx.core.content.IntentCompat
3535
import androidx.core.util.Consumer
3636
import androidx.lifecycle.Lifecycle
3737
import io.element.android.features.call.api.CallType
38+
import io.element.android.features.call.api.CallType.ExternalUrl
3839
import io.element.android.features.call.impl.DefaultElementCallEntryPoint
3940
import io.element.android.features.call.impl.di.CallBindings
4041
import io.element.android.features.call.impl.pip.PictureInPictureEvents
@@ -44,11 +45,14 @@ import io.element.android.features.call.impl.pip.PipView
4445
import io.element.android.features.call.impl.services.CallForegroundService
4546
import io.element.android.features.call.impl.utils.CallIntentDataParser
4647
import io.element.android.libraries.architecture.bindings
48+
import io.element.android.libraries.core.log.logger.LoggerTag
4749
import io.element.android.libraries.designsystem.theme.ElementThemeApp
4850
import io.element.android.libraries.preferences.api.store.AppPreferencesStore
4951
import timber.log.Timber
5052
import javax.inject.Inject
5153

54+
private val loggerTag = LoggerTag("ElementCallActivity")
55+
5256
class ElementCallActivity :
5357
AppCompatActivity(),
5458
CallScreenNavigator,
@@ -132,7 +136,7 @@ class ElementCallActivity :
132136
DisposableEffect(Unit) {
133137
val listener = Runnable {
134138
if (requestPermissionCallback != null) {
135-
Timber.w("Ignoring onUserLeaveHint event because user is asked to grant permissions")
139+
Timber.tag(loggerTag.value).w("Ignoring onUserLeaveHint event because user is asked to grant permissions")
136140
} else {
137141
pipEventSink(PictureInPictureEvents.EnterPictureInPicture)
138142
}
@@ -146,7 +150,7 @@ class ElementCallActivity :
146150
val onPictureInPictureModeChangedListener = Consumer { _: PictureInPictureModeChangedInfo ->
147151
pipEventSink(PictureInPictureEvents.OnPictureInPictureModeChanged(isInPictureInPictureMode))
148152
if (!isInPictureInPictureMode && !lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) {
149-
Timber.d("Exiting PiP mode: Hangup the call")
153+
Timber.tag(loggerTag.value).d("Exiting PiP mode: Hangup the call")
150154
eventSink?.invoke(CallScreenEvents.Hangup)
151155
}
152156
}
@@ -185,23 +189,23 @@ class ElementCallActivity :
185189

186190
private fun setCallType(intent: Intent?) {
187191
val callType = intent?.let {
188-
IntentCompat.getParcelableExtra(it, DefaultElementCallEntryPoint.EXTRA_CALL_TYPE, CallType::class.java)
192+
IntentCompat.getParcelableExtra(intent, DefaultElementCallEntryPoint.EXTRA_CALL_TYPE, CallType::class.java)
193+
?: intent.dataString?.let(::parseUrl)?.let(::ExternalUrl)
189194
}
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
195+
val currentCallType = webViewTarget.value
196+
if (currentCallType == null && callType == null) {
197+
Timber.tag(loggerTag.value).d("Re-opened the activity but we have no url to load or a cached one, finish the activity")
198+
finish()
199+
} else if (currentCallType == null) {
200+
Timber.tag(loggerTag.value).d("Set the call type and create the presenter")
201+
webViewTarget.value = callType
202+
presenter = presenterFactory.create(callType!!, this)
203+
} else if (callType != currentCallType) {
204+
Timber.tag(loggerTag.value).d("User starts another call, restart the Activity")
205+
setIntent(intent)
206+
recreate()
207+
} else {
208+
Timber.tag(loggerTag.value).d("Coming back from notification, do nothing")
205209
}
206210
}
207211

0 commit comments

Comments
 (0)