CombinedCollectionLiveData

open class CombinedCollectionLiveData<I, O>(calculateValue: (List<I>) -> O) : MutableLiveData<O>

Similar to MediatorLiveData, but with a few key differences:

  • There's a single function to update the value when any of the sources change.

  • Updating multiple sources simultaneously only results in a single value update.

Consistent with kotlinx.coroutines.flow.combine, calculateValue will only be called when all added sources have a value set (even if that value is null). Until then, the returned LiveData's value will be unset and observers will not receive callbacks.

Parameters

I

The type of the input. I.e., the source LiveData values.

O

The type of the output LiveData value.

calculateValue

A method that calculates the value for this LiveData after one or more sources are updated.

Constructors

Link copied to clipboard
fun <I, O> CombinedCollectionLiveData(calculateValue: (List<I>) -> O)

Inherited properties

Link copied to clipboard
val mActiveCount: Int
Link copied to clipboard
val mDataLock: Any
Link copied to clipboard
val mPendingData: Any

Functions

Link copied to clipboard
fun addSource(source: LiveData<out I>)

Adds a source, triggering a value update. Any future change to the added source's value will also trigger a value update.

Link copied to clipboard
fun removeSource(source: LiveData<out I>)

Removes a source, triggering a value update. Any future change to the added source's value will no longer trigger a value update.

Link copied to clipboard
fun setSources(newSources: List<LiveData<out I>>)

Replaces all sources, triggering a value update. Any future change to any of the new sources' values will also trigger a value update.

Inherited functions

Link copied to clipboard
open fun changeActiveCounter(p0: Int)
Link copied to clipboard
open fun dispatchingValue(@Nullable p0: LiveData.ObserverWrapper<O>?)
Link copied to clipboard
open fun getValue(): O?
Link copied to clipboard
open fun getVersion(): Int
Link copied to clipboard
open fun hasActiveObservers(): Boolean
Link copied to clipboard
open fun hasObservers(): Boolean
Link copied to clipboard
open fun observe(@NonNull p0: LifecycleOwner, @NonNull p1: Observer<in O>)
Link copied to clipboard
open fun observeForever(@NonNull p0: Observer<in O>)
Link copied to clipboard
open override fun postValue(p0: O)
Link copied to clipboard
open fun removeObserver(@NonNull p0: Observer<in O>)
Link copied to clipboard
open fun removeObservers(@NonNull p0: LifecycleOwner)
Link copied to clipboard
open override fun setValue(p0: O)