From 8a7505843a2686bd12596112b6a3036e33352638 Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Thu, 14 Jan 2021 19:21:44 +0100 Subject: [PATCH] [fenix] Migrate some "selected tab" reads from SessionManager to BrowserStore. --- .../main/java/org/mozilla/fenix/FenixApplication.kt | 3 ++- .../java/org/mozilla/fenix/browser/BrowserFragment.kt | 1 + .../mozilla/fenix/browser/ToolbarGestureHandler.kt | 11 +++++++---- .../components/toolbar/BrowserToolbarController.kt | 2 +- .../fenix/components/toolbar/BrowserToolbarView.kt | 4 ++-- .../mozilla/fenix/shortcut/CreateShortcutFragment.kt | 9 +++++---- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt index cbb9e1ea24..ee7109f1f4 100644 --- a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt +++ b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt @@ -22,6 +22,7 @@ import kotlinx.coroutines.launch import mozilla.appservices.Megazord import mozilla.components.browser.session.Session import mozilla.components.browser.state.action.SystemAction +import mozilla.components.browser.state.selector.selectedTab import mozilla.components.concept.base.crash.Breadcrumb import mozilla.components.concept.push.PushProcessor import mozilla.components.feature.addons.update.GlobalAddonDependencyProvider @@ -398,7 +399,7 @@ open class FenixApplication : LocaleAwareApplication(), Provider { onNewTabOverride = { _, engineSession, url -> val shouldCreatePrivateSession = - components.core.sessionManager.selectedSession?.private + components.core.store.state.selectedTab?.content?.private ?: components.settings.openLinksInAPrivateTab val session = Session(url, shouldCreatePrivateSession) 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 ec7db68bc6..f5e8a3fe95 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt @@ -68,6 +68,7 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler { contentLayout = browserLayout, tabPreview = tabPreview, toolbarLayout = browserToolbarView.view, + store = components.core.store, sessionManager = components.core.sessionManager ) ) diff --git a/app/src/main/java/org/mozilla/fenix/browser/ToolbarGestureHandler.kt b/app/src/main/java/org/mozilla/fenix/browser/ToolbarGestureHandler.kt index 8c4effc116..da19ec7852 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/ToolbarGestureHandler.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/ToolbarGestureHandler.kt @@ -19,6 +19,8 @@ import androidx.core.view.isVisible import androidx.interpolator.view.animation.LinearOutSlowInInterpolator import mozilla.components.browser.session.Session import mozilla.components.browser.session.SessionManager +import mozilla.components.browser.state.selector.selectedTab +import mozilla.components.browser.state.store.BrowserStore import mozilla.components.support.ktx.android.view.getRectWithViewLocation import org.mozilla.fenix.R import org.mozilla.fenix.ext.getRectWithScreenLocation @@ -40,6 +42,7 @@ class ToolbarGestureHandler( private val contentLayout: View, private val tabPreview: TabPreview, private val toolbarLayout: View, + private val store: BrowserStore, private val sessionManager: SessionManager ) : SwipeGestureListener { @@ -145,15 +148,15 @@ class ToolbarGestureHandler( private fun getDestination(): Destination { val isLtr = activity.resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_LTR - val currentSession = sessionManager.selectedSession ?: return Destination.None - val currentIndex = sessionManager.sessionsOfType(currentSession.private).indexOfFirst { - it.id == currentSession.id + val currentTab = store.state.selectedTab ?: return Destination.None + val currentIndex = sessionManager.sessionsOfType(currentTab.content.private).indexOfFirst { + it.id == currentTab.id } return if (currentIndex == -1) { Destination.None } else { - val sessions = sessionManager.sessionsOfType(currentSession.private) + val sessions = sessionManager.sessionsOfType(currentTab.content.private) val index = when (gestureDirection) { GestureDirection.RIGHT_TO_LEFT -> if (isLtr) { currentIndex + 1 diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt index 079796a256..69c3848658 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt @@ -77,7 +77,7 @@ class DefaultBrowserToolbarController( store.updateSearchTermsOfSelectedSession(text) activity.components.useCases.searchUseCases.defaultSearch.invoke( text, - sessionId = sessionManager.selectedSession?.id + sessionId = store.state.selectedTabId ) } diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt index 2726180e92..97d103e6f6 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt @@ -24,6 +24,7 @@ import kotlinx.android.synthetic.main.component_browser_top_toolbar.view.* import kotlinx.coroutines.ExperimentalCoroutinesApi import mozilla.components.browser.domains.autocomplete.ShippedDomainsProvider import mozilla.components.browser.session.Session +import mozilla.components.browser.state.selector.selectedTab import mozilla.components.browser.state.state.ExternalAppType import mozilla.components.browser.toolbar.BrowserToolbar import mozilla.components.browser.toolbar.behavior.BrowserToolbarBottomBehavior @@ -98,7 +99,6 @@ class BrowserToolbarView( } with(container.context) { - val sessionManager = components.core.sessionManager val isPinningSupported = components.useCases.webAppUseCases.isPinningSupported() if (toolbarPosition == ToolbarPosition.TOP) { @@ -206,7 +206,7 @@ class BrowserToolbarView( components.core.historyStorage, lifecycleOwner, sessionId = null, - isPrivate = sessionManager.selectedSession?.private ?: false, + isPrivate = components.core.store.state.selectedTab?.content?.private ?: false, interactor = interactor, engine = components.core.engine ) diff --git a/app/src/main/java/org/mozilla/fenix/shortcut/CreateShortcutFragment.kt b/app/src/main/java/org/mozilla/fenix/shortcut/CreateShortcutFragment.kt index 836bfce84d..c7289d93ec 100644 --- a/app/src/main/java/org/mozilla/fenix/shortcut/CreateShortcutFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/shortcut/CreateShortcutFragment.kt @@ -13,6 +13,7 @@ import androidx.fragment.app.DialogFragment import androidx.lifecycle.lifecycleScope import kotlinx.android.synthetic.main.fragment_create_shortcut.* import kotlinx.coroutines.launch +import mozilla.components.browser.state.selector.selectedTab import org.mozilla.fenix.R import org.mozilla.fenix.ext.loadIntoView import org.mozilla.fenix.ext.requireComponents @@ -32,12 +33,12 @@ class CreateShortcutFragment : DialogFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - val session = requireComponents.core.sessionManager.selectedSession + val tab = requireComponents.core.store.state.selectedTab - if (session == null) { + if (tab == null) { dismiss() } else { - requireComponents.core.icons.loadIntoView(favicon_image, session.url) + requireComponents.core.icons.loadIntoView(favicon_image, tab.content.url) cancel_button.setOnClickListener { dismiss() } add_button.setOnClickListener { @@ -52,7 +53,7 @@ class CreateShortcutFragment : DialogFragment() { updateAddButtonEnabledState() } - shortcut_text.setText(session.title) + shortcut_text.setText(tab.content.title) } }