mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-17 15:26:23 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/24114 - Refactor initial HomeFragmentState into AppState
This commit is contained in:
parent
fa71851b96
commit
269dc65be3
@ -27,8 +27,16 @@ import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.autofill.AutofillConfirmActivity
|
||||
import org.mozilla.fenix.autofill.AutofillSearchActivity
|
||||
import org.mozilla.fenix.autofill.AutofillUnlockActivity
|
||||
import org.mozilla.fenix.components.appstate.AppState
|
||||
import org.mozilla.fenix.datastore.pocketStoriesSelectedCategoriesDataStore
|
||||
import org.mozilla.fenix.ext.asRecentTabs
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.ext.filterState
|
||||
import org.mozilla.fenix.ext.settings
|
||||
import org.mozilla.fenix.ext.sort
|
||||
import org.mozilla.fenix.home.PocketUpdatesMiddleware
|
||||
import org.mozilla.fenix.home.blocklist.BlocklistHandler
|
||||
import org.mozilla.fenix.home.blocklist.BlocklistMiddleware
|
||||
import org.mozilla.fenix.perf.AppStartReasonProvider
|
||||
import org.mozilla.fenix.perf.StartupActivityLog
|
||||
import org.mozilla.fenix.perf.StartupStateProvider
|
||||
@ -36,8 +44,8 @@ import org.mozilla.fenix.perf.StrictModeManager
|
||||
import org.mozilla.fenix.perf.lazyMonitored
|
||||
import org.mozilla.fenix.utils.ClipboardHandler
|
||||
import org.mozilla.fenix.utils.Settings
|
||||
import org.mozilla.fenix.wallpapers.WallpaperFileManager
|
||||
import org.mozilla.fenix.wallpapers.WallpaperDownloader
|
||||
import org.mozilla.fenix.wallpapers.WallpaperFileManager
|
||||
import org.mozilla.fenix.wallpapers.WallpaperManager
|
||||
import org.mozilla.fenix.wifi.WifiConnectionMonitor
|
||||
import java.util.concurrent.TimeUnit
|
||||
@ -188,7 +196,36 @@ class Components(private val context: Context) {
|
||||
val appStartReasonProvider by lazyMonitored { AppStartReasonProvider() }
|
||||
val startupActivityLog by lazyMonitored { StartupActivityLog() }
|
||||
val startupStateProvider by lazyMonitored { StartupStateProvider(startupActivityLog, appStartReasonProvider) }
|
||||
val appStore by lazyMonitored { AppStore() }
|
||||
val appStore by lazyMonitored {
|
||||
val blocklistHandler = BlocklistHandler(settings)
|
||||
|
||||
AppStore(
|
||||
initialState = AppState(
|
||||
collections = core.tabCollectionStorage.cachedTabCollections,
|
||||
expandedCollections = emptySet(),
|
||||
topSites = core.topSitesStorage.cachedTopSites.sort(),
|
||||
recentBookmarks = emptyList(),
|
||||
showCollectionPlaceholder = settings.showCollectionsPlaceholderOnHome,
|
||||
showSetAsDefaultBrowserCard = settings.shouldShowSetAsDefaultBrowserCard(),
|
||||
// Provide an initial state for recent tabs to prevent re-rendering on the home screen.
|
||||
// This will otherwise cause a visual jump as the section gets rendered from no state
|
||||
// to some state.
|
||||
recentTabs = if (settings.showRecentTabsFeature) {
|
||||
core.store.state.asRecentTabs()
|
||||
} else {
|
||||
emptyList()
|
||||
},
|
||||
recentHistory = emptyList()
|
||||
).run { filterState(blocklistHandler) },
|
||||
middlewares = listOf(
|
||||
BlocklistMiddleware(blocklistHandler),
|
||||
PocketUpdatesMiddleware(
|
||||
core.pocketStoriesService,
|
||||
context.pocketStoriesSelectedCategoriesDataStore
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,7 +64,6 @@ import mozilla.components.concept.sync.AccountObserver
|
||||
import mozilla.components.concept.sync.AuthType
|
||||
import mozilla.components.concept.sync.OAuthAccount
|
||||
import mozilla.components.feature.tab.collections.TabCollection
|
||||
import mozilla.components.feature.top.sites.TopSite
|
||||
import mozilla.components.feature.top.sites.TopSitesConfig
|
||||
import mozilla.components.feature.top.sites.TopSitesFeature
|
||||
import mozilla.components.feature.top.sites.TopSitesProviderConfig
|
||||
@ -82,10 +81,8 @@ import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.browser.BrowserAnimator.Companion.getToolbarNavOptions
|
||||
import org.mozilla.fenix.browser.BrowserFragmentDirections
|
||||
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
|
||||
import org.mozilla.fenix.components.Components
|
||||
import org.mozilla.fenix.components.FenixSnackbar
|
||||
import org.mozilla.fenix.components.PrivateShortcutCreateManager
|
||||
import org.mozilla.fenix.components.StoreProvider
|
||||
import org.mozilla.fenix.components.TabCollectionStorage
|
||||
import org.mozilla.fenix.components.accounts.AccountState
|
||||
import org.mozilla.fenix.components.appstate.AppAction
|
||||
@ -93,25 +90,18 @@ import org.mozilla.fenix.components.metrics.Event
|
||||
import org.mozilla.fenix.components.toolbar.FenixTabCounterMenu
|
||||
import org.mozilla.fenix.components.toolbar.ToolbarPosition
|
||||
import org.mozilla.fenix.databinding.FragmentHomeBinding
|
||||
import org.mozilla.fenix.datastore.pocketStoriesSelectedCategoriesDataStore
|
||||
import org.mozilla.fenix.ext.asRecentTabs
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.ext.filterState
|
||||
import org.mozilla.fenix.ext.hideToolbar
|
||||
import org.mozilla.fenix.ext.metrics
|
||||
import org.mozilla.fenix.ext.nav
|
||||
import org.mozilla.fenix.ext.requireComponents
|
||||
import org.mozilla.fenix.ext.runIfFragmentIsAttached
|
||||
import org.mozilla.fenix.ext.settings
|
||||
import org.mozilla.fenix.ext.sort
|
||||
import org.mozilla.fenix.home.blocklist.BlocklistHandler
|
||||
import org.mozilla.fenix.home.blocklist.BlocklistMiddleware
|
||||
import org.mozilla.fenix.home.mozonline.showPrivacyPopWindow
|
||||
import org.mozilla.fenix.home.pocket.DefaultPocketStoriesController
|
||||
import org.mozilla.fenix.home.pocket.PocketRecommendedStoriesCategory
|
||||
import org.mozilla.fenix.home.recentbookmarks.RecentBookmarksFeature
|
||||
import org.mozilla.fenix.home.recentbookmarks.controller.DefaultRecentBookmarksController
|
||||
import org.mozilla.fenix.home.recenttabs.RecentTab
|
||||
import org.mozilla.fenix.home.recenttabs.RecentTabsListFeature
|
||||
import org.mozilla.fenix.home.recenttabs.controller.DefaultRecentTabsController
|
||||
import org.mozilla.fenix.home.recentvisits.RecentVisitsFeature
|
||||
@ -173,7 +163,6 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
private lateinit var homeFragmentStore: HomeFragmentStore
|
||||
private var _sessionControlInteractor: SessionControlInteractor? = null
|
||||
private val sessionControlInteractor: SessionControlInteractor
|
||||
get() = _sessionControlInteractor!!
|
||||
@ -236,34 +225,6 @@ class HomeFragment : Fragment() {
|
||||
::dispatchModeChanges
|
||||
)
|
||||
|
||||
val blocklistHandler = BlocklistHandler(components.settings)
|
||||
homeFragmentStore = StoreProvider.get(this) {
|
||||
HomeFragmentStore(
|
||||
initialState = HomeFragmentState(
|
||||
collections = components.core.tabCollectionStorage.cachedTabCollections,
|
||||
expandedCollections = emptySet(),
|
||||
mode = currentMode.getCurrentMode(),
|
||||
topSites = getTopSites(components),
|
||||
recentBookmarks = emptyList(),
|
||||
showCollectionPlaceholder = components.settings.showCollectionsPlaceholderOnHome,
|
||||
showSetAsDefaultBrowserCard = components.settings.shouldShowSetAsDefaultBrowserCard(),
|
||||
// Provide an initial state for recent tabs to prevent re-rendering on the home screen.
|
||||
// This will otherwise cause a visual jump as the section gets rendered from no state
|
||||
// to some state.
|
||||
recentTabs = getRecentTabs(components),
|
||||
recentHistory = emptyList()
|
||||
).run { filterState(blocklistHandler) },
|
||||
middlewares = listOf(
|
||||
BlocklistMiddleware(blocklistHandler),
|
||||
PocketUpdatesMiddleware(
|
||||
lifecycleScope,
|
||||
requireComponents.core.pocketStoriesService,
|
||||
requireContext().pocketStoriesSelectedCategoriesDataStore
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
lifecycleScope.launch(IO) {
|
||||
if (requireContext().settings().showPocketRecommendationsFeature) {
|
||||
val categories = components.core.pocketStoriesService.getStories()
|
||||
@ -684,22 +645,6 @@ class HomeFragment : Fragment() {
|
||||
subscribeToTabCollections()
|
||||
|
||||
val context = requireContext()
|
||||
val components = context.components
|
||||
|
||||
homeFragmentStore.dispatch(
|
||||
HomeFragmentAction.Change(
|
||||
collections = components.core.tabCollectionStorage.cachedTabCollections,
|
||||
mode = currentMode.getCurrentMode(),
|
||||
topSites = getTopSites(components),
|
||||
showCollectionPlaceholder = components.settings.showCollectionsPlaceholderOnHome,
|
||||
// Provide an initial state for recent tabs to prevent re-rendering on the home screen.
|
||||
// This will otherwise cause a visual jump as the section gets rendered from no state
|
||||
// to some state.
|
||||
recentTabs = getRecentTabs(components),
|
||||
recentBookmarks = emptyList(),
|
||||
recentHistory = emptyList()
|
||||
)
|
||||
)
|
||||
|
||||
requireComponents.backgroundServices.accountManagerAvailableQueue.runIfReadyOrQueue {
|
||||
// By the time this code runs, we may not be attached to a context or have a view lifecycle owner.
|
||||
@ -1194,22 +1139,6 @@ class HomeFragment : Fragment() {
|
||||
?.isVisible = tabCount > 0
|
||||
}
|
||||
|
||||
private fun getTopSites(components: Components): List<TopSite> {
|
||||
return if (components.settings.showTopSitesFeature) {
|
||||
components.core.topSitesStorage.cachedTopSites.sort()
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getRecentTabs(components: Components): List<RecentTab> {
|
||||
return if (components.settings.showRecentTabsFeature) {
|
||||
components.core.store.state.asRecentTabs()
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
private fun displayWallpaperIfEnabled() {
|
||||
if (shouldEnableWallpaper()) {
|
||||
val wallpaperManger = requireComponents.wallpaperManager
|
||||
|
Loading…
Reference in New Issue
Block a user