From 7fa4cf4487790a759af00bd4a7ae5c57efbe3c03 Mon Sep 17 00:00:00 2001 From: ekager Date: Fri, 28 Jun 2019 12:40:38 -0700 Subject: [PATCH] Use sessionId in FIP Integration, use pendingIntent for startActivity --- .../org/mozilla/fenix/browser/BrowserFragment.kt | 14 +++++++++----- .../fenix/components/FindInPageIntegration.kt | 12 +++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) 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 dab4835d48..bcfac0f2bb 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 2ab153887f..ee3c91032f 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 {