2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-15 18:12:54 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/10342 - Part 1: Remove top sites prefetch and observation of live data

This commit is contained in:
Gabriel Luong 2020-08-18 17:22:32 -04:00 committed by Jonathan Almeida
parent d8fbb2b4b0
commit 1f3f1f481d
3 changed files with 0 additions and 42 deletions

View File

@ -141,7 +141,6 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
}
}
prefetchForHomeFragment()
setupLeakCanary()
startMetricsIfEnabled()
setupPush()
@ -257,14 +256,6 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
// no-op, LeakCanary is disabled by default
}
// This is for issue https://github.com/mozilla-mobile/fenix/issues/11660. We prefetch our info for startup
// so that we're sure that we have all the data available as our fragment is launched.
private fun prefetchForHomeFragment() {
StrictMode.allowThreadDiskReads().resetPoliciesAfter {
components.core.topSiteStorage.prefetch()
}
}
private fun setupPush() {
// Sets the PushFeature as the singleton instance for push messages to go to.
// We need the push feature setup here to deliver messages in the case where the service

View File

@ -1,20 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.ext
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
/**
* Observe a LiveData once and unregister from it as soon as the live data returns a value
*/
fun <T> LiveData<T>.observeOnce(observer: (T) -> Unit) {
observeForever(object : Observer<T> {
override fun onChanged(value: T) {
removeObserver(this)
observer(value)
}
})
}

View File

@ -68,7 +68,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.lib.state.ext.consumeFrom
import mozilla.components.support.ktx.android.util.dpToPx
import org.mozilla.fenix.BrowserDirection
@ -511,7 +510,6 @@ class HomeFragment : Fragment() {
override fun onStart() {
super.onStart()
subscribeToTabCollections()
subscribeToTopSites()
val context = requireContext()
val components = context.components
@ -847,17 +845,6 @@ class HomeFragment : Fragment() {
}
}
private fun subscribeToTopSites(): Observer<List<TopSite>> {
return Observer<List<TopSite>> { topSites ->
requireComponents.core.topSiteStorage.cachedTopSites = topSites
context?.settings()?.preferences?.edit()
?.putInt(getString(R.string.pref_key_top_sites_size), topSites.size)?.apply()
homeFragmentStore.dispatch(HomeFragmentAction.TopSitesChange(topSites))
}.also { observer ->
requireComponents.core.topSiteStorage.getTopSites().observe(this, observer)
}
}
private fun registerCollectionStorageObserver() {
requireComponents.core.tabCollectionStorage.register(collectionStorageObserver, this)
}