Let MainActivity manage Element Call https links.

This commit is contained in:
Benoit Marty 2024-05-02 15:37:57 +02:00
parent b055452ae7
commit 0fb89bd4b2
4 changed files with 42 additions and 12 deletions

View file

@ -34,15 +34,10 @@
android:configChanges="screenSize|screenLayout|orientation|keyboardHidden|keyboard|navigation|uiMode"
android:launchMode="singleTask">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!--
Note: intent-filter for https://call.element.io link is now managed by the MainActivity.
-->
<data android:scheme="https" />
<data android:host="call.element.io" />
</intent-filter>
<!-- Custom scheme to handle urls from other domains in the format: element://call?url=https%3A%2F%2Felement.io -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />

View file

@ -17,6 +17,7 @@
package io.element.android.features.call.ui
import android.Manifest
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
@ -35,6 +36,7 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.core.app.ActivityOptionsCompat
import androidx.core.content.IntentCompat
import com.bumble.appyx.core.integrationpoint.NodeComponentActivity
import io.element.android.compound.theme.ElementTheme
@ -47,6 +49,7 @@ import io.element.android.features.call.di.CallBindings
import io.element.android.features.call.utils.CallIntentDataParser
import io.element.android.features.preferences.api.store.AppPreferencesStore
import io.element.android.libraries.architecture.bindings
import io.element.android.libraries.core.bool.orFalse
import javax.inject.Inject
class ElementCallActivity : NodeComponentActivity(), CallScreenNavigator {
@ -63,6 +66,26 @@ class ElementCallActivity : NodeComponentActivity(), CallScreenNavigator {
}
context.startActivity(intent)
}
/**
* Eventually start the ElementCallActivity, and return true if it's the case.
*/
fun maybeStart(
activity: Activity,
intent: Intent?,
): Boolean {
return intent?.data
?.takeIf { uri -> uri.scheme == "https" && uri.host == "call.element.io" }
?.let { uri ->
val callIntent = Intent(activity, ElementCallActivity::class.java).apply {
data = uri
}
// Disable animation since MainActivity has already been animated.
val options = ActivityOptionsCompat.makeCustomAnimation(activity, 0, 0)
activity.startActivity(callIntent, options.toBundle())
true
}.orFalse()
}
}
@Inject lateinit var callIntentDataParser: CallIntentDataParser