diff --git a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt index dab4835d4..bcfac0f2b 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt @@ -108,6 +108,7 @@ class BrowserFragment : Fragment(), BackHandler { private var tabCollectionObserver: Observer>? = null private var sessionObserver: Session.Observer? = null private var sessionManagerObserver: SessionManager.Observer? = null + private var pendingOpenInBrowserIntent: Intent? = null private val sessionFeature = ViewBoundFeatureWrapper() private val contextMenuFeature = ViewBoundFeatureWrapper() @@ -272,7 +273,7 @@ class BrowserFragment : Fragment(), BackHandler { findInPageIntegration.set( feature = FindInPageIntegration( - requireComponents.core.sessionManager, view.findInPageView, view.engineView, toolbar + requireComponents.core.sessionManager, customTabSessionId, view.findInPageView, view.engineView, toolbar ), owner = this, view = view @@ -450,6 +451,7 @@ class BrowserFragment : Fragment(), BackHandler { @SuppressWarnings("ComplexMethod") override fun onResume() { + super.onResume() sessionObserver = subscribeToSession() sessionManagerObserver = subscribeToSessions() tabCollectionObserver = subscribeToTabCollections() @@ -458,7 +460,6 @@ class BrowserFragment : Fragment(), BackHandler { getSessionById()?.let { updateBookmarkState(it) } if (getSessionById() == null) findNavController(this).popBackStack(R.id.homeFragment, false) - super.onResume() context?.components?.core?.let { val preferredColorScheme = it.getPreferredColorScheme() if (it.engine.settings.preferredColorScheme != preferredColorScheme) { @@ -629,6 +630,10 @@ class BrowserFragment : Fragment(), BackHandler { sessionManagerObserver?.let { requireComponents.core.sessionManager.unregister(it) } + pendingOpenInBrowserIntent?.let { + startActivity(it) + pendingOpenInBrowserIntent = null + } } override fun onBackPressed(): Boolean { @@ -760,14 +765,13 @@ class BrowserFragment : Fragment(), BackHandler { ToolbarMenu.Item.OpenInFenix -> { // To not get a "Display Already Acquired" error we need to force remove the engineView here swipeRefresh?.removeView(engineView as View) - val intent = Intent(context, IntentReceiverActivity::class.java) - intent.action = Intent.ACTION_VIEW + pendingOpenInBrowserIntent = Intent(context, IntentReceiverActivity::class.java) + pendingOpenInBrowserIntent?.action = Intent.ACTION_VIEW getSessionById()?.customTabConfig = null getSessionById()?.let { requireComponents.core.sessionManager.select(it) } activity?.finish() - startActivity(intent) } } } diff --git a/app/src/main/java/org/mozilla/fenix/components/FindInPageIntegration.kt b/app/src/main/java/org/mozilla/fenix/components/FindInPageIntegration.kt index 2ab153887..ee3c91032 100644 --- a/app/src/main/java/org/mozilla/fenix/components/FindInPageIntegration.kt +++ b/app/src/main/java/org/mozilla/fenix/components/FindInPageIntegration.kt @@ -9,6 +9,7 @@ import android.util.AttributeSet import android.view.View import androidx.coordinatorlayout.widget.CoordinatorLayout import mozilla.components.browser.session.SessionManager +import mozilla.components.browser.session.runWithSessionIdOrSelected import mozilla.components.browser.toolbar.BrowserToolbar import mozilla.components.concept.engine.EngineView import mozilla.components.feature.findinpage.FindInPageFeature @@ -21,6 +22,7 @@ import org.mozilla.fenix.test.Mockable @Mockable class FindInPageIntegration( private val sessionManager: SessionManager, + private val sessionId: String? = null, private val view: FindInPageView, engineView: EngineView, private val toolbar: BrowserToolbar @@ -49,11 +51,11 @@ class FindInPageIntegration( } private fun launch() { - val session = sessionManager.selectedSession ?: return - - toolbar.visibility = View.GONE - view.asView().visibility = View.VISIBLE - feature.bind(session) + sessionManager.runWithSessionIdOrSelected(sessionId) { + toolbar.visibility = View.GONE + view.asView().visibility = View.VISIBLE + feature.bind(it) + } } companion object {