-
-
Notifications
You must be signed in to change notification settings - Fork 266
Deeplinking improvement #256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,26 +13,24 @@ import androidx.compose.runtime.setValue | |
| import androidx.compose.ui.tooling.preview.Preview | ||
| import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen | ||
| import androidx.core.util.Consumer | ||
| import zed.rainxch.githubstore.app.deeplink.DeepLinkParser | ||
|
|
||
| class MainActivity : ComponentActivity() { | ||
|
|
||
| private var deepLinkUri by mutableStateOf<String?>(null) | ||
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| installSplashScreen() | ||
|
|
||
| enableEdgeToEdge() | ||
|
|
||
| super.onCreate(savedInstanceState) | ||
|
|
||
| deepLinkUri = intent?.data?.toString() | ||
| handleIncomingIntent(intent) | ||
|
|
||
| setContent { | ||
| DisposableEffect(Unit) { | ||
| val listener = Consumer<Intent> { newIntent -> | ||
| newIntent.data?.toString()?.let { | ||
| deepLinkUri = it | ||
| } | ||
| handleIncomingIntent(newIntent) | ||
| } | ||
| addOnNewIntentListener(listener) | ||
| onDispose { | ||
|
|
@@ -43,6 +41,23 @@ class MainActivity : ComponentActivity() { | |
| App(deepLinkUri = deepLinkUri) | ||
| } | ||
| } | ||
|
|
||
| private fun handleIncomingIntent(intent: Intent?) { | ||
| if (intent == null) return | ||
|
|
||
| val uriString = when (intent.action) { | ||
| Intent.ACTION_VIEW -> intent.data?.toString() | ||
|
|
||
| Intent.ACTION_SEND -> { | ||
| val sharedText = intent.getStringExtra(Intent.EXTRA_TEXT) | ||
| sharedText?.let { DeepLinkParser.extractSupportedUrl(it) } | ||
| } | ||
|
|
||
| else -> null | ||
| } | ||
|
|
||
| uriString?.let { deepLinkUri = it } | ||
| } | ||
|
Comment on lines
+45
to
+60
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good centralized handling; but re-sharing the same URL is silently ignored.
A simple fix is to reset the URI after navigation and use a wrapper to ensure uniqueness: Sketch: reset after consumptionIn // After navigating in LaunchedEffect:
// signal back to clear the deep link so a repeated share is recognizedOr in - private var deepLinkUri by mutableStateOf<String?>(null)
+ private var deepLinkUri by mutableStateOf<Pair<String, Long>?>(null)- uriString?.let { deepLinkUri = it }
+ uriString?.let { deepLinkUri = it to System.currentTimeMillis() }Then key 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| @Preview | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
App will appear in the share sheet for all plain/HTML text shares.
The SEND intent-filter with
text/plainandtext/htmlcannot be scoped to specific domains at the manifest level, so the app shows up whenever a user shares any text — articles, notes, non-GitHub links, etc. When the shared text doesn't contain a supported URL,extractSupportedUrlreturnsnulland nothing happens, but the user gets no feedback explaining why.Consider adding a brief Toast or Snackbar in
handleIncomingIntentwhenACTION_SENDyields no supported URL, so the user understands the share was intentionally ignored.🤖 Prompt for AI Agents