Commit 46aa6a00 authored by Gabriel Luong's avatar Gabriel Luong Committed by Jonathan Almeida
Browse files

For #10342 - Part 3: Use the TopSitesUseCase in the BrowserToolbarController...

For #10342 - Part 3: Use the TopSitesUseCase in the BrowserToolbarController and SessionControlController

Use the provided `addPinnedSites` and `removeTopSites` use cases in `BrowserToolbarController` and `SessionControlController`.
parent d824dd1e
......@@ -241,7 +241,6 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
bookmarkTapped = { viewLifecycleOwner.lifecycleScope.launch { bookmarkTapped(it) } },
scope = viewLifecycleOwner.lifecycleScope,
tabCollectionStorage = requireComponents.core.tabCollectionStorage,
topSiteStorage = requireComponents.core.topSiteStorage,
onTabCounterClicked = {
thumbnailsFeature.get()?.requestScreenshot()
findNavController().nav(
......
......@@ -53,7 +53,8 @@ class Components(private val context: Context) {
core.sessionManager,
core.store,
search.searchEngineManager,
core.webAppShortcutManager
core.webAppShortcutManager,
core.topSiteStorage
)
}
val intentProcessors by lazy {
......
......@@ -20,6 +20,8 @@ import mozilla.components.feature.session.SessionUseCases
import mozilla.components.feature.session.SettingsUseCases
import mozilla.components.feature.session.TrackingProtectionUseCases
import mozilla.components.feature.tabs.TabsUseCases
import mozilla.components.feature.top.sites.TopSitesStorage
import mozilla.components.feature.top.sites.TopSitesUseCases
import org.mozilla.fenix.utils.Mockable
/**
......@@ -34,7 +36,8 @@ class UseCases(
private val sessionManager: SessionManager,
private val store: BrowserStore,
private val searchEngineManager: SearchEngineManager,
private val shortcutManager: WebAppShortcutManager
private val shortcutManager: WebAppShortcutManager,
private val topSitesStorage: TopSitesStorage
) {
/**
* Use cases that provide engine interactions for a given browser session.
......@@ -69,4 +72,9 @@ class UseCases(
val engineSessionUseCases by lazy { EngineSessionUseCases(sessionManager) }
val trackingProtectionUseCases by lazy { TrackingProtectionUseCases(store, engine) }
/**
* Use cases that provide top sites management.
*/
val topSitesUseCase by lazy { TopSitesUseCases(topSitesStorage) }
}
......@@ -34,7 +34,6 @@ import org.mozilla.fenix.browser.readermode.ReaderModeController
import org.mozilla.fenix.collections.SaveCollectionStep
import org.mozilla.fenix.components.FenixSnackbar
import org.mozilla.fenix.components.TabCollectionStorage
import org.mozilla.fenix.components.TopSiteStorage
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getRootView
......@@ -75,7 +74,6 @@ class DefaultBrowserToolbarController(
private val bookmarkTapped: (Session) -> Unit,
private val scope: CoroutineScope,
private val tabCollectionStorage: TabCollectionStorage,
private val topSiteStorage: TopSiteStorage,
private val onTabCounterClicked: () -> Unit,
private val onCloseTab: (Session) -> Unit
) : BrowserToolbarController {
......@@ -245,7 +243,9 @@ class DefaultBrowserToolbarController(
scope.launch {
ioScope.launch {
currentSession?.let {
topSiteStorage.addTopSite(it.title, it.url)
with(activity.components.useCases.topSitesUseCase) {
addPinnedSites(it.title, it.url)
}
}
}.join()
......
......@@ -209,7 +209,6 @@ class HomeFragment : Fragment() {
metrics = components.analytics.metrics,
sessionManager = sessionManager,
tabCollectionStorage = components.core.tabCollectionStorage,
topSiteStorage = components.core.topSiteStorage,
addTabUseCase = components.useCases.tabsUseCases.addTab,
fragmentStore = homeFragmentStore,
navController = findNavController(),
......
......@@ -22,7 +22,6 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.collections.SaveCollectionStep
import org.mozilla.fenix.components.TabCollectionStorage
import org.mozilla.fenix.components.TopSiteStorage
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.components.metrics.MetricsUtils
......@@ -160,7 +159,6 @@ class DefaultSessionControlController(
private val metrics: MetricController,
private val sessionManager: SessionManager,
private val tabCollectionStorage: TabCollectionStorage,
private val topSiteStorage: TopSiteStorage,
private val addTabUseCase: TabsUseCases.AddNewTabUseCase,
private val fragmentStore: HomeFragmentStore,
private val navController: NavController,
......@@ -290,7 +288,9 @@ class DefaultSessionControlController(
}
viewLifecycleScope.launch(Dispatchers.IO) {
topSiteStorage.removeTopSite(topSite)
with(activity.components.useCases.topSitesUseCase) {
removeTopSites(topSite)
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment