@@ -9,11 +9,11 @@ import android.content.Intent
99import android.net.Uri
1010import android.os.Bundle
1111import androidx.compose.runtime.Composable
12- import androidx.compose.runtime.LaunchedEffect
1312import androidx.compose.runtime.getValue
1413import androidx.compose.runtime.mutableStateOf
1514import androidx.compose.runtime.remember
1615import androidx.compose.runtime.setValue
16+ import androidx.core.content.IntentCompat
1717import androidx.core.os.BundleCompat
1818import androidx.lifecycle.viewmodel.navigation3.rememberViewModelStoreNavEntryDecorator
1919import androidx.navigation3.runtime.entry
@@ -32,15 +32,30 @@ import at.bitfire.icsdroid.ui.screen.SubscriptionsScreen
3232import java.util.ServiceLoader
3333
3434/* *
35- * Computes the correct initial destination from some intent extras :
35+ * Computes the correct initial destination from some intent:
3636 * - If [AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE] is present -> [Destination.AddSubscription]
3737 * - Otherwise: [Destination.SubscriptionList]
3838 */
39- private fun calculateInitialDestination (intentExtras : Bundle ? ): Destination {
40- return if (intentExtras?.containsKey(AccountManager .KEY_ACCOUNT_AUTHENTICATOR_RESPONSE ) == true ) {
39+ private fun calculateInitialDestination (intent : Intent ): Destination {
40+ val extras = intent.extras ? : Bundle .EMPTY
41+ val text = extras.getString(Intent .EXTRA_TEXT )
42+ ?.trim()
43+ ?.takeUnless { it.isEmpty() }
44+ val stream = BundleCompat .getParcelable(extras, Intent .EXTRA_STREAM , Uri ::class .java)
45+ ?.toString()
46+ val data = intent.dataString
47+
48+ return if (extras.containsKey(AccountManager .KEY_ACCOUNT_AUTHENTICATOR_RESPONSE )) {
4149 // If KEY_ACCOUNT_AUTHENTICATOR_RESPONSE was given, intent was launched from authenticator,
4250 // open the add subscription screen
4351 Destination .AddSubscription ()
52+ } else if (text != null || stream != null || data != null ) {
53+ // If a URL was given, open the add subscription screen
54+ Destination .AddSubscription (
55+ title = extras.getString(" title" ),
56+ color = extras.takeIf { it.containsKey(" color" ) }?.getInt(" color" , - 1 ),
57+ url = text ? : stream ? : data
58+ )
4459 } else {
4560 // If no condition matches, show the subscriptions list
4661 Destination .SubscriptionList
@@ -50,20 +65,20 @@ private fun calculateInitialDestination(intentExtras: Bundle?): Destination {
5065@Composable
5166fun MainApp (
5267 savedInstanceState : Bundle ? ,
53- intentExtras : Bundle ? ,
68+ intent : Intent ,
5469 onFinish : () -> Unit ,
5570) {
5671 // If EXTRA_PERMISSION is true, request the calendar permissions
57- val requestPermissions = intentExtras?.getBoolean (EXTRA_REQUEST_CALENDAR_PERMISSION , false ) == true
72+ val requestPermissions = intent.getBooleanExtra (EXTRA_REQUEST_CALENDAR_PERMISSION , false )
5873
5974 // show error message from calling intent, if available
6075 var showingErrorMessage by remember {
61- mutableStateOf(savedInstanceState == null && intentExtras?.containsKey (EXTRA_ERROR_MESSAGE ) == true )
76+ mutableStateOf(savedInstanceState == null && intent.hasExtra (EXTRA_ERROR_MESSAGE ))
6277 }
63- if (showingErrorMessage && intentExtras != null ) {
78+ if (showingErrorMessage) {
6479 AlertDialog (
65- intentExtras.getString (EXTRA_ERROR_MESSAGE )!! ,
66- BundleCompat .getSerializable(intentExtras , EXTRA_THROWABLE , Throwable ::class .java)
80+ intent.getStringExtra (EXTRA_ERROR_MESSAGE )!! ,
81+ IntentCompat .getSerializableExtra(intent , EXTRA_THROWABLE , Throwable ::class .java)
6782 ) { showingErrorMessage = false }
6883 }
6984
@@ -75,7 +90,7 @@ fun MainApp(
7590 if (show) service.Content ()
7691 }
7792
78- val backStack = rememberNavBackStack(calculateInitialDestination(intentExtras ))
93+ val backStack = rememberNavBackStack(calculateInitialDestination(intent ))
7994
8095 fun goBack (depth : Int = 1) {
8196 if (backStack.size <= 1 ) onFinish()
@@ -98,22 +113,10 @@ fun MainApp(
98113 )
99114 }
100115 entry<Destination .AddSubscription > { destination ->
101- var url: String? = null
102- LaunchedEffect (intentExtras) {
103- if (intentExtras != null ) {
104- intentExtras.getString(Intent .EXTRA_TEXT )
105- ?.trim()
106- ?.let { url = it }
107- BundleCompat .getParcelable(intentExtras, Intent .EXTRA_STREAM , Uri ::class .java)
108- ?.toString()
109- ?.let { url = it }
110- }
111- }
112-
113116 AddSubscriptionScreen (
114117 title = destination.title,
115118 color = destination.color,
116- url = url,
119+ url = destination. url,
117120 onBackRequested = { goBack() }
118121 )
119122 }
0 commit comments