Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #10342 - Part 3: Use the TopSitesUseCase in the BrowserToolbarCon…
Browse files Browse the repository at this point in the history
…troller and SessionControlController

Use the provided `addPinnedSites` and `removeTopSites` use cases in `BrowserToolbarController` and `SessionControlController`.
  • Loading branch information
gabrielluong authored and jonalmeida committed Aug 26, 2020
1 parent d824dd1 commit 46aa6a0
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/org/mozilla/fenix/components/Components.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/java/org/mozilla/fenix/components/UseCases.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -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.
Expand Down Expand Up @@ -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) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()

Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -290,7 +288,9 @@ class DefaultSessionControlController(
}

viewLifecycleScope.launch(Dispatchers.IO) {
topSiteStorage.removeTopSite(topSite)
with(activity.components.useCases.topSitesUseCase) {
removeTopSites(topSite)
}
}
}

Expand Down

0 comments on commit 46aa6a0

Please sign in to comment.