[fenix] For https://github.com/mozilla-mobile/fenix/issues/11660: added prefetch for topsites and update in onCreateView() (https://github.com/mozilla-mobile/fenix/pull/11668)
* For https://github.com/mozilla-mobile/fenix/issues/11660:added prefetch for topsites TopSites will be prefetched with observerOnce (wrapper around observerForever). Also, the SessionControlView.update() is called right away instead of waiting from consumeFrom in the HomeFragment.onCreateView() which will allow the UI to render all at once on its first perform traversal * Removed the submitList(null) since it retriggered a drawing on lower end devicepull/600/head
parent
b7af130eb7
commit
17d1072e3a
@ -0,0 +1,20 @@
|
||||
/* 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)
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue