From 87211e5591ec4b57d6679e057672f20dd79c6b2f Mon Sep 17 00:00:00 2001 From: Gokulakrishna Sudharsan Date: Tue, 9 Apr 2024 20:06:04 +0530 Subject: [PATCH] Handle new intent when a link is shared from another app using long press - Fixes #628 --- .../main/java/fulguris/browser/TabsManager.kt | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/fulguris/browser/TabsManager.kt b/app/src/main/java/fulguris/browser/TabsManager.kt index e4814a971..38b736717 100644 --- a/app/src/main/java/fulguris/browser/TabsManager.kt +++ b/app/src/main/java/fulguris/browser/TabsManager.kt @@ -272,6 +272,15 @@ class TabsManager @Inject constructor( } } + /** + * + */ + private fun launchNewTabAndActivate(url: String) { + newTab(UrlInitializer(url), true) + shouldClose = true + lastTab()?.isNewTab = true + } + /** * Initialize the state of the [TabsManager] based on previous state of the browser. * @@ -1114,8 +1123,14 @@ class TabsManager @Inject constructor( if ("text/plain" == intent.type) { // Get shared text val clue = intent.getStringExtra(Intent.EXTRA_TEXT) - // Put it in the address bar if any - clue?.let { iWebBrowser.setAddressBarText(it) } + + //Fix for #628 - Handle when a link is long pressed on another app and shared to Fulguris + if (clue != null && URLUtil.isNetworkUrl(clue.trim())) { + launchNewTabAndActivate(clue) + } else { + // Put it in the address bar if any + clue?.let { iWebBrowser.setAddressBarText(it) } + } } // Cancel other operation as we won't open a tab here null @@ -1135,9 +1150,7 @@ class TabsManager @Inject constructor( lastTab()?.isNewTab = true } } else { - newTab(UrlInitializer(url), true) - shouldClose = true - lastTab()?.isNewTab = true + launchNewTabAndActivate(url) } } }