CombinedCollectionLiveData
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
Inherited properties
Same as LiveData.getValue, except this variant throws a IllegalStateException when the LiveData instance does not have an active observer.
Same as LiveData.getValue with the exception that the returned value is up to date even when the LiveData instance does not have an observer.
Functions
Adds a source, triggering a value update. Any future change to the added source's value will also trigger a value update.
Removes a source, triggering a value update. Any future change to the added source's value will no longer trigger a value update.
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
Adds the specified element to the end of this MutableLiveData. The observers are notified of the new value.
Adds all of the elements of the specified collection to the end of this MutableLiveData. The observers are notified of the new value if the list was changed.
Convenience method to create non-mutable LiveData fields without duplicating the type.
Removes all elements from this MutableLiveData. The observers are notified of the new value if the list was changed.
Returns the value corresponding to the given key in the LiveData's value, or defaultValue if such a key is not present in the map or the LiveData has no value.
Returns the value for the given key in the LiveData's value. If the key is not found, calls the defaultValue function, puts its result into the map under the given key and returns it. Creates a map if the LiveData has no value yet.
Executes and switchMaps to block if this
has a true
value. If this
is false
or null
, it returns LiveData with value default. This can be used instead of ifTrue when the default value should be something other than null
. Note that this requires a non-null value for T in order for Kotlin's compiler to properly spot missing null
-checks.
Maps the value of the provided key, if that key exists in this map. Otherwise, no value is set. This is useful in cases where the map may not contain the requested entry but the resulting LiveData is not nullable as the client does not care about a null
value. This removes the need for the client to have null
checks in its code wherever the resulting LiveData is used.
Removes a single instance of the specified element from a MutableLiveData, if it is present. The observers are notified of the new value if any of the specified elements was removed.
Removes all elements from this MutableLiveData that are also contained in the given elements collection. The observers are notified of the new value if the list was changed.
Removes the entry mapped by key
from the LiveData's value, notifying observers of the new value.
Adds the specified element to the end of this MutableLiveData. The observers are notified of the new value.
Adds all of the elements of the specified collection to the end of this MutableLiveData. The observers are notified of the new value if the list was changed.
Removes a single instance of the specified element from a MutableLiveData, if it is present. The observers are notified of the new value if any of the specified elements was removed.
Removes all elements from this MutableLiveData that match the given predicate. The observers are notified of the new value if the list was changed.
Removes all elements from this MutableLiveData that are also contained in the given elements collection. The observers are notified of the new value if the list was changed.
Maps key to valueToAdd in LiveData's value. Creates a map if the LiveData has no value yet.
Creates a MutableLiveData from LiveData by specifying the setter to use to the change the value.