Modern Apps git

← Modern-Apps.git

findfamily: add deep-link invite sharing via findfamily://add scheme

Commit
3c6d247b07267dceb42c9ef789551d38626add39
Author
Vayun Mathur <[email protected]>
When
2026-08-06 22:09 UTC (4 months ago)
Parents
c675be9

Diff

findfamily/src/main/AndroidManifest.xml
diff --git a/findfamily/src/main/AndroidManifest.xml b/findfamily/src/main/AndroidManifest.xmlindex 570abe40d8..eb67447385 100644--- a/findfamily/src/main/AndroidManifest.xml+++ b/findfamily/src/main/AndroidManifest.xml@@ -39,12 +39,23 @@             android:configChanges="mcc|mnc|colorMode|density|fontScale|fontWeightAdjustment|keyboard|keyboardHidden|layoutDirection|navigation|orientation|screenLayout|screenSize|smallestScreenSize|touchscreen|uiMode"             android:name=".MainActivity"             android:exported="true"+            android:launchMode="singleTop"             android:theme="@style/Theme.General">             <intent-filter>                 <action android:name="android.intent.action.MAIN" />                  <category android:name="android.intent.category.LAUNCHER" />             </intent-filter>+            <!-- Deep-link invite: findfamily://add/<base26Userid>. Carries only the+                 sender's public id; tapping prefills the Add Person dialog. -->+            <intent-filter>+                <action android:name="android.intent.action.VIEW" />++                <category android:name="android.intent.category.DEFAULT" />+                <category android:name="android.intent.category.BROWSABLE" />++                <data android:scheme="findfamily" android:host="add" />+            </intent-filter>         </activity>          <service
findfamily/src/main/java/com/vayunmathur/findfamily/MainActivity.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/MainActivity.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/MainActivity.ktindex 79f0bf6f63..eeec1f42d7 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/MainActivity.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/MainActivity.kt@@ -1,6 +1,7 @@ package com.vayunmathur.findfamily  import android.Manifest+import android.content.Intent import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.rememberLauncherForActivityResult@@ -52,6 +53,7 @@ import com.vayunmathur.findfamily.ui.MainPage import com.vayunmathur.findfamily.ui.UwbRangingScreen import com.vayunmathur.findfamily.ui.dialogs.AddLinkDialog import com.vayunmathur.findfamily.ui.dialogs.AddPersonDialog+import com.vayunmathur.findfamily.ui.dialogs.decodeBase26 import com.vayunmathur.library.ui.DynamicTheme import com.vayunmathur.library.ui.dialog.DatePickerDialog import com.vayunmathur.library.util.DialogPage@@ -84,8 +86,16 @@ class MainActivity : ComponentActivity() {         FindFamilyViewModelFactory(application, userDao, waypointDao, locationValueDao, temporaryLinkDao)     } +    /**+     * Pending `findfamily://add/<base26>` invite id (already decoded), set on cold+     * start and via [onNewIntent] for warm starts. Read from Compose so a tap routes+     * to the prefilled Add Person dialog; cleared once consumed.+     */+    private val deepLinkAddId = mutableStateOf<Long?>(null)+     override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)+        deepLinkAddId.value = parseAddDeepLink(intent)         // FIRST_PARTY: api.vayunmathur.com + data.vayunmathur.com + findfamily.cc (Cloudflare ISRG+GTS)         NetworkClient.init(this, TrustBundle.FIRST_PARTY)         enableEdgeToEdge()@@ -126,11 +136,38 @@ class MainActivity : ComponentActivity() {                             ?.getLongExtra(EXTRA_UWB_PEER_ID, -1L)                             ?.takeIf { it != -1L }                     }-                    Navigation(platform, ffViewModel, ffViewModel.missingFeatures, deepLinkPeerId)+                    Navigation(+                        platform,+                        ffViewModel,+                        ffViewModel.missingFeatures,+                        deepLinkPeerId,+                        deepLinkAddId.value,+                        onDeepLinkAddConsumed = { deepLinkAddId.value = null },+                    )                 }             }         }     }++    override fun onNewIntent(intent: Intent) {+        super.onNewIntent(intent)+        // singleTop: warm-start links arrive here. Keep getIntent() in sync and+        // surface the invite so Compose routes to the prefilled dialog.+        setIntent(intent)+        parseAddDeepLink(intent)?.let { deepLinkAddId.value = it }+    }++    /**+     * Decodes a `findfamily://add/<base26Userid>` invite to a numeric user id, or+     * null for any other intent. The link carries only the sender's public id.+     */+    private fun parseAddDeepLink(intent: Intent?): Long? {+        val data = intent?.data ?: return null+        if (data.scheme != "findfamily" || data.host != "add") return null+        val segment = data.lastPathSegment?.trim()?.uppercase() ?: return null+        if (segment.isEmpty() || segment.any { it !in 'A'..'Z' }) return null+        return runCatching { segment.decodeBase26() }.getOrNull()+    } }  @Composable@@ -305,6 +342,8 @@ fun Navigation(     ffViewModel: FindFamilyViewModel,     showMissingFeatures: Boolean,     deepLinkUwbPeerId: Long? = null,+    deepLinkAddId: Long? = null,+    onDeepLinkAddConsumed: () -> Unit = {}, ) {     val backStack = rememberNavBackStack<Route>(Route.MainPage()) @@ -320,6 +359,15 @@ fun Navigation(         }     } +    // A tapped invite prefills the Add Person dialog; the user still explicitly+    // accepts, so the connection/crypto flow is unchanged.+    LaunchedEffect(deepLinkAddId) {+        if (deepLinkAddId != null) {+            backStack.add(Route.AddPersonDialog(deepLinkAddId))+            onDeepLinkAddConsumed()+        }+    }+     MainNavigation(backStack) {         entry<Route.MainPage> {             MainPage(platform, backStack, ffViewModel, it.selectedUserId, it.selectedWaypointId)
findfamily/src/main/java/com/vayunmathur/findfamily/ui/dialogs/AddPersonDialog.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/dialogs/AddPersonDialog.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/dialogs/AddPersonDialog.ktindex b1138bb3ad..6ad9df3bca 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/dialogs/AddPersonDialog.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/dialogs/AddPersonDialog.kt@@ -3,10 +3,16 @@ import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.PressInteraction import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.width import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.Card+import com.vayunmathur.library.ui.ExternalIntents+import com.vayunmathur.library.ui.IconShare import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.OutlinedButton import com.vayunmathur.library.ui.OutlinedTextField import com.vayunmathur.library.ui.Text import androidx.compose.runtime.Composable@@ -19,6 +25,7 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import androidx.compose.ui.res.stringResource+import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.window.Dialog import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.findfamily.util.FindFamilyViewModel@@ -49,6 +56,7 @@ fun AddPersonDialog(     }      val userStatus = usersByID[userid.decodeBase26()]?.requestStatus+    val context = LocalContext.current      Dialog({backStack.pop()}) {         Card {@@ -68,6 +76,25 @@ fun AddPersonDialog(                     readOnly = true                 ) +                // Share sheet instead of copy/paste: sends findfamily://add/<myId>,+                // which prefills the recipient's Add Person dialog. The link carries+                // only a public id — never a key — so it's safe to share anywhere.+                OutlinedButton(+                    {+                        val link = "findfamily://add/${Networking.userid.encodeBase26()}"+                        ExternalIntents.shareText(+                            context,+                            link,+                            context.getString(R.string.share_invite_link_chooser),+                        )+                    },+                    Modifier.fillMaxWidth()+                ) {+                    IconShare()+                    Spacer(Modifier.width(8.dp))+                    Text(stringResource(R.string.share_invite_link))+                }+                 OutlinedTextField(                     userid,                     { userid = it },
findfamily/src/main/res/values/strings.xml
diff --git a/findfamily/src/main/res/values/strings.xml b/findfamily/src/main/res/values/strings.xmlindex 5afc60defb..00eae1d433 100644--- a/findfamily/src/main/res/values/strings.xml+++ b/findfamily/src/main/res/values/strings.xml@@ -191,6 +191,10 @@     <string name="accept_location_request">Accept Location Request</string>     <!-- AddPersonDialog: Button to send location sharing request. Verb phrase -->     <string name="request_location">Request Location</string>+    <!-- AddPersonDialog: Button that opens the system share sheet with an invite link. Verb phrase -->+    <string name="share_invite_link">Share invite link</string>+    <!-- AddPersonDialog: Title of the system share chooser for the invite link. Noun phrase -->+    <string name="share_invite_link_chooser">Share FindFamily invite</string>      <!-- Platform: Label for clipboard data when copying ID. Generic noun -->     <string name="clipboard_label">text</string>