Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Gaba
fenix
Commits
bd7a5375
Unverified
Commit
bd7a5375
authored
Aug 26, 2020
by
MarcLeclair
Committed by
GitHub
Aug 26, 2020
Browse files
For 11660: fixing nits for previous #11668 (#11821)
parent
92886121
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/org/mozilla/fenix/FenixApplication.kt
View file @
bd7a5375
...
...
@@ -257,8 +257,9 @@ 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.
/**
* See [TopsiteStore.prefetch] for details on pre fetching.
*/
private
fun
prefetchForHomeFragment
()
{
StrictMode
.
allowThreadDiskReads
().
resetPoliciesAfter
{
components
.
core
.
topSiteStorage
.
prefetch
()
...
...
app/src/main/java/org/mozilla/fenix/components/TopSiteStorage.kt
View file @
bd7a5375
...
...
@@ -14,7 +14,7 @@ import mozilla.components.feature.top.sites.TopSite
import
mozilla.components.feature.top.sites.TopSiteStorage
import
mozilla.components.support.locale.LocaleManager
import
org.mozilla.fenix.R
import
org.mozilla.fenix.ext.observeOnce
import
org.mozilla.fenix.ext.observeOnce
AndRemoveObserver
import
org.mozilla.fenix.ext.settings
import
org.mozilla.fenix.settings.SupportUtils
import
org.mozilla.fenix.settings.advanced.getSelectedLocale
...
...
@@ -88,8 +88,15 @@ class TopSiteStorage(private val context: Context) {
}
}
/**
* This is for issue https://github.com/mozilla-mobile/fenix/issues/11660. We prefetch the top
* sites for startup so that we're sure that we have all the data available as our fragment is
* launched to make sure that we can display everything on the home screen on the first drawing pass.
* This method doesn't negatively affect performance since the [getTopSites] runs on the a
* background thread.
*/
fun
prefetch
()
{
getTopSites
().
observeOnce
{
getTopSites
().
observeOnce
AndRemoveObserver
{
cachedTopSites
=
it
}
}
...
...
app/src/main/java/org/mozilla/fenix/ext/LiveData.kt
View file @
bd7a5375
...
...
@@ -10,11 +10,11 @@ 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
)
{
fun
<
T
>
LiveData
<
T
>.
observeOnce
AndRemoveObserver
(
callback
:
(
T
)
->
Unit
)
{
observeForever
(
object
:
Observer
<
T
>
{
override
fun
onChanged
(
value
:
T
)
{
removeObserver
(
this
)
observer
(
value
)
callback
(
value
)
}
})
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment