mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-11 13:11:01 +00:00
Migrate some "selected tab" reads from SessionManager to BrowserStore.
This commit is contained in:
parent
a6495347fd
commit
051988ecff
@ -22,6 +22,7 @@ import kotlinx.coroutines.launch
|
|||||||
import mozilla.appservices.Megazord
|
import mozilla.appservices.Megazord
|
||||||
import mozilla.components.browser.session.Session
|
import mozilla.components.browser.session.Session
|
||||||
import mozilla.components.browser.state.action.SystemAction
|
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.base.crash.Breadcrumb
|
||||||
import mozilla.components.concept.push.PushProcessor
|
import mozilla.components.concept.push.PushProcessor
|
||||||
import mozilla.components.feature.addons.update.GlobalAddonDependencyProvider
|
import mozilla.components.feature.addons.update.GlobalAddonDependencyProvider
|
||||||
@ -398,7 +399,7 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
|
|||||||
onNewTabOverride = {
|
onNewTabOverride = {
|
||||||
_, engineSession, url ->
|
_, engineSession, url ->
|
||||||
val shouldCreatePrivateSession =
|
val shouldCreatePrivateSession =
|
||||||
components.core.sessionManager.selectedSession?.private
|
components.core.store.state.selectedTab?.content?.private
|
||||||
?: components.settings.openLinksInAPrivateTab
|
?: components.settings.openLinksInAPrivateTab
|
||||||
|
|
||||||
val session = Session(url, shouldCreatePrivateSession)
|
val session = Session(url, shouldCreatePrivateSession)
|
||||||
|
@ -68,6 +68,7 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {
|
|||||||
contentLayout = browserLayout,
|
contentLayout = browserLayout,
|
||||||
tabPreview = tabPreview,
|
tabPreview = tabPreview,
|
||||||
toolbarLayout = browserToolbarView.view,
|
toolbarLayout = browserToolbarView.view,
|
||||||
|
store = components.core.store,
|
||||||
sessionManager = components.core.sessionManager
|
sessionManager = components.core.sessionManager
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -19,6 +19,8 @@ import androidx.core.view.isVisible
|
|||||||
import androidx.interpolator.view.animation.LinearOutSlowInInterpolator
|
import androidx.interpolator.view.animation.LinearOutSlowInInterpolator
|
||||||
import mozilla.components.browser.session.Session
|
import mozilla.components.browser.session.Session
|
||||||
import mozilla.components.browser.session.SessionManager
|
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 mozilla.components.support.ktx.android.view.getRectWithViewLocation
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
import org.mozilla.fenix.ext.getRectWithScreenLocation
|
import org.mozilla.fenix.ext.getRectWithScreenLocation
|
||||||
@ -40,6 +42,7 @@ class ToolbarGestureHandler(
|
|||||||
private val contentLayout: View,
|
private val contentLayout: View,
|
||||||
private val tabPreview: TabPreview,
|
private val tabPreview: TabPreview,
|
||||||
private val toolbarLayout: View,
|
private val toolbarLayout: View,
|
||||||
|
private val store: BrowserStore,
|
||||||
private val sessionManager: SessionManager
|
private val sessionManager: SessionManager
|
||||||
) : SwipeGestureListener {
|
) : SwipeGestureListener {
|
||||||
|
|
||||||
@ -145,15 +148,15 @@ class ToolbarGestureHandler(
|
|||||||
|
|
||||||
private fun getDestination(): Destination {
|
private fun getDestination(): Destination {
|
||||||
val isLtr = activity.resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_LTR
|
val isLtr = activity.resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_LTR
|
||||||
val currentSession = sessionManager.selectedSession ?: return Destination.None
|
val currentTab = store.state.selectedTab ?: return Destination.None
|
||||||
val currentIndex = sessionManager.sessionsOfType(currentSession.private).indexOfFirst {
|
val currentIndex = sessionManager.sessionsOfType(currentTab.content.private).indexOfFirst {
|
||||||
it.id == currentSession.id
|
it.id == currentTab.id
|
||||||
}
|
}
|
||||||
|
|
||||||
return if (currentIndex == -1) {
|
return if (currentIndex == -1) {
|
||||||
Destination.None
|
Destination.None
|
||||||
} else {
|
} else {
|
||||||
val sessions = sessionManager.sessionsOfType(currentSession.private)
|
val sessions = sessionManager.sessionsOfType(currentTab.content.private)
|
||||||
val index = when (gestureDirection) {
|
val index = when (gestureDirection) {
|
||||||
GestureDirection.RIGHT_TO_LEFT -> if (isLtr) {
|
GestureDirection.RIGHT_TO_LEFT -> if (isLtr) {
|
||||||
currentIndex + 1
|
currentIndex + 1
|
||||||
|
@ -77,7 +77,7 @@ class DefaultBrowserToolbarController(
|
|||||||
store.updateSearchTermsOfSelectedSession(text)
|
store.updateSearchTermsOfSelectedSession(text)
|
||||||
activity.components.useCases.searchUseCases.defaultSearch.invoke(
|
activity.components.useCases.searchUseCases.defaultSearch.invoke(
|
||||||
text,
|
text,
|
||||||
sessionId = sessionManager.selectedSession?.id
|
sessionId = store.state.selectedTabId
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ import kotlinx.android.synthetic.main.component_browser_top_toolbar.view.*
|
|||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import mozilla.components.browser.domains.autocomplete.ShippedDomainsProvider
|
import mozilla.components.browser.domains.autocomplete.ShippedDomainsProvider
|
||||||
import mozilla.components.browser.session.Session
|
import mozilla.components.browser.session.Session
|
||||||
|
import mozilla.components.browser.state.selector.selectedTab
|
||||||
import mozilla.components.browser.state.state.ExternalAppType
|
import mozilla.components.browser.state.state.ExternalAppType
|
||||||
import mozilla.components.browser.toolbar.BrowserToolbar
|
import mozilla.components.browser.toolbar.BrowserToolbar
|
||||||
import mozilla.components.browser.toolbar.behavior.BrowserToolbarBottomBehavior
|
import mozilla.components.browser.toolbar.behavior.BrowserToolbarBottomBehavior
|
||||||
@ -98,7 +99,6 @@ class BrowserToolbarView(
|
|||||||
}
|
}
|
||||||
|
|
||||||
with(container.context) {
|
with(container.context) {
|
||||||
val sessionManager = components.core.sessionManager
|
|
||||||
val isPinningSupported = components.useCases.webAppUseCases.isPinningSupported()
|
val isPinningSupported = components.useCases.webAppUseCases.isPinningSupported()
|
||||||
|
|
||||||
if (toolbarPosition == ToolbarPosition.TOP) {
|
if (toolbarPosition == ToolbarPosition.TOP) {
|
||||||
@ -206,7 +206,7 @@ class BrowserToolbarView(
|
|||||||
components.core.historyStorage,
|
components.core.historyStorage,
|
||||||
lifecycleOwner,
|
lifecycleOwner,
|
||||||
sessionId = null,
|
sessionId = null,
|
||||||
isPrivate = sessionManager.selectedSession?.private ?: false,
|
isPrivate = components.core.store.state.selectedTab?.content?.private ?: false,
|
||||||
interactor = interactor,
|
interactor = interactor,
|
||||||
engine = components.core.engine
|
engine = components.core.engine
|
||||||
)
|
)
|
||||||
|
@ -13,6 +13,7 @@ import androidx.fragment.app.DialogFragment
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import kotlinx.android.synthetic.main.fragment_create_shortcut.*
|
import kotlinx.android.synthetic.main.fragment_create_shortcut.*
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import mozilla.components.browser.state.selector.selectedTab
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
import org.mozilla.fenix.ext.loadIntoView
|
import org.mozilla.fenix.ext.loadIntoView
|
||||||
import org.mozilla.fenix.ext.requireComponents
|
import org.mozilla.fenix.ext.requireComponents
|
||||||
@ -32,12 +33,12 @@ class CreateShortcutFragment : DialogFragment() {
|
|||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
val session = requireComponents.core.sessionManager.selectedSession
|
val tab = requireComponents.core.store.state.selectedTab
|
||||||
|
|
||||||
if (session == null) {
|
if (tab == null) {
|
||||||
dismiss()
|
dismiss()
|
||||||
} else {
|
} else {
|
||||||
requireComponents.core.icons.loadIntoView(favicon_image, session.url)
|
requireComponents.core.icons.loadIntoView(favicon_image, tab.content.url)
|
||||||
|
|
||||||
cancel_button.setOnClickListener { dismiss() }
|
cancel_button.setOnClickListener { dismiss() }
|
||||||
add_button.setOnClickListener {
|
add_button.setOnClickListener {
|
||||||
@ -52,7 +53,7 @@ class CreateShortcutFragment : DialogFragment() {
|
|||||||
updateAddButtonEnabledState()
|
updateAddButtonEnabledState()
|
||||||
}
|
}
|
||||||
|
|
||||||
shortcut_text.setText(session.title)
|
shortcut_text.setText(tab.content.title)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user