1
0
Fork 0

Use sessionId in FIP Integration, use pendingIntent for startActivity

master
ekager 2019-06-28 12:40:38 -07:00 committed by Emily Kager
parent 6d0a4fdb4d
commit 7fa4cf4487
2 changed files with 16 additions and 10 deletions

View File

@ -108,6 +108,7 @@ class BrowserFragment : Fragment(), BackHandler {
private var tabCollectionObserver: Observer<List<TabCollection>>? = null private var tabCollectionObserver: Observer<List<TabCollection>>? = null
private var sessionObserver: Session.Observer? = null private var sessionObserver: Session.Observer? = null
private var sessionManagerObserver: SessionManager.Observer? = null private var sessionManagerObserver: SessionManager.Observer? = null
private var pendingOpenInBrowserIntent: Intent? = null
private val sessionFeature = ViewBoundFeatureWrapper<SessionFeature>() private val sessionFeature = ViewBoundFeatureWrapper<SessionFeature>()
private val contextMenuFeature = ViewBoundFeatureWrapper<ContextMenuFeature>() private val contextMenuFeature = ViewBoundFeatureWrapper<ContextMenuFeature>()
@ -272,7 +273,7 @@ class BrowserFragment : Fragment(), BackHandler {
findInPageIntegration.set( findInPageIntegration.set(
feature = FindInPageIntegration( feature = FindInPageIntegration(
requireComponents.core.sessionManager, view.findInPageView, view.engineView, toolbar requireComponents.core.sessionManager, customTabSessionId, view.findInPageView, view.engineView, toolbar
), ),
owner = this, owner = this,
view = view view = view
@ -450,6 +451,7 @@ class BrowserFragment : Fragment(), BackHandler {
@SuppressWarnings("ComplexMethod") @SuppressWarnings("ComplexMethod")
override fun onResume() { override fun onResume() {
super.onResume()
sessionObserver = subscribeToSession() sessionObserver = subscribeToSession()
sessionManagerObserver = subscribeToSessions() sessionManagerObserver = subscribeToSessions()
tabCollectionObserver = subscribeToTabCollections() tabCollectionObserver = subscribeToTabCollections()
@ -458,7 +460,6 @@ class BrowserFragment : Fragment(), BackHandler {
getSessionById()?.let { updateBookmarkState(it) } getSessionById()?.let { updateBookmarkState(it) }
if (getSessionById() == null) findNavController(this).popBackStack(R.id.homeFragment, false) if (getSessionById() == null) findNavController(this).popBackStack(R.id.homeFragment, false)
super.onResume()
context?.components?.core?.let { context?.components?.core?.let {
val preferredColorScheme = it.getPreferredColorScheme() val preferredColorScheme = it.getPreferredColorScheme()
if (it.engine.settings.preferredColorScheme != preferredColorScheme) { if (it.engine.settings.preferredColorScheme != preferredColorScheme) {
@ -629,6 +630,10 @@ class BrowserFragment : Fragment(), BackHandler {
sessionManagerObserver?.let { sessionManagerObserver?.let {
requireComponents.core.sessionManager.unregister(it) requireComponents.core.sessionManager.unregister(it)
} }
pendingOpenInBrowserIntent?.let {
startActivity(it)
pendingOpenInBrowserIntent = null
}
} }
override fun onBackPressed(): Boolean { override fun onBackPressed(): Boolean {
@ -760,14 +765,13 @@ class BrowserFragment : Fragment(), BackHandler {
ToolbarMenu.Item.OpenInFenix -> { ToolbarMenu.Item.OpenInFenix -> {
// To not get a "Display Already Acquired" error we need to force remove the engineView here // To not get a "Display Already Acquired" error we need to force remove the engineView here
swipeRefresh?.removeView(engineView as View) swipeRefresh?.removeView(engineView as View)
val intent = Intent(context, IntentReceiverActivity::class.java) pendingOpenInBrowserIntent = Intent(context, IntentReceiverActivity::class.java)
intent.action = Intent.ACTION_VIEW pendingOpenInBrowserIntent?.action = Intent.ACTION_VIEW
getSessionById()?.customTabConfig = null getSessionById()?.customTabConfig = null
getSessionById()?.let { getSessionById()?.let {
requireComponents.core.sessionManager.select(it) requireComponents.core.sessionManager.select(it)
} }
activity?.finish() activity?.finish()
startActivity(intent)
} }
} }
} }

View File

@ -9,6 +9,7 @@ import android.util.AttributeSet
import android.view.View import android.view.View
import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.coordinatorlayout.widget.CoordinatorLayout
import mozilla.components.browser.session.SessionManager import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.session.runWithSessionIdOrSelected
import mozilla.components.browser.toolbar.BrowserToolbar import mozilla.components.browser.toolbar.BrowserToolbar
import mozilla.components.concept.engine.EngineView import mozilla.components.concept.engine.EngineView
import mozilla.components.feature.findinpage.FindInPageFeature import mozilla.components.feature.findinpage.FindInPageFeature
@ -21,6 +22,7 @@ import org.mozilla.fenix.test.Mockable
@Mockable @Mockable
class FindInPageIntegration( class FindInPageIntegration(
private val sessionManager: SessionManager, private val sessionManager: SessionManager,
private val sessionId: String? = null,
private val view: FindInPageView, private val view: FindInPageView,
engineView: EngineView, engineView: EngineView,
private val toolbar: BrowserToolbar private val toolbar: BrowserToolbar
@ -49,11 +51,11 @@ class FindInPageIntegration(
} }
private fun launch() { private fun launch() {
val session = sessionManager.selectedSession ?: return sessionManager.runWithSessionIdOrSelected(sessionId) {
toolbar.visibility = View.GONE
toolbar.visibility = View.GONE view.asView().visibility = View.VISIBLE
view.asView().visibility = View.VISIBLE feature.bind(it)
feature.bind(session) }
} }
companion object { companion object {