Package-level declarations

Types

Link copied to clipboard
class EventObserver<T>(onEventUnhandledContent: (T) -> Unit) : Observer<SingleEvent<T>>

An Observer for SingleEvents, simplifying the pattern of checking if the SingleEvent's content has already been handled.

Link copied to clipboard
class NonNullLiveData<T>(liveData: LiveData<T>) : LiveData<T>
Link copied to clipboard
open class SingleEvent<out T>(content: T)
Link copied to clipboard
class SingleLiveData<T>(liveData: LiveData<T>) : MediatorLiveData<T>
Link copied to clipboard
Link copied to clipboard

A lifecycle-aware observable that sends only new updates after subscription, used for events like navigation and Snackbar messages.

Properties

Link copied to clipboard

Emits the items that are different from all the values that have been emitted so far

Link copied to clipboard

Emits the items that are different from the last item

Link copied to clipboard

Emits at most 1 item and returns a SingleLiveData

Link copied to clipboard

Emits only the values that are not null

Link copied to clipboard

Converts a LiveData to a MutableLiveData with the initial value set by this LiveData's value

Link copied to clipboard

Converts a LiveData to a SingleLiveData

Functions

Link copied to clipboard
fun <T> T?.asLiveData(): LiveData<T>

Creates an instance of LiveData with this as its value.

Link copied to clipboard

Creates an instance of MutableLiveData with this as its value.

Link copied to clipboard
fun <T> LiveData<T>.buffer(count: Int): MutableLiveData<List<T?>>

Buffers the items emitted by the LiveData, and emits them when they reach the count as a List.

Link copied to clipboard
fun <T> concat(vararg liveData: LiveData<T>): LiveData<T>

Concats the given LiveData together and emits their values one by one in order

Link copied to clipboard
fun <T> LiveData<T>.concatWith(otherLiveData: LiveData<T>): LiveData<T>
Link copied to clipboard
fun <T> LiveData<T>.defaultIfNull(default: T): LiveData<T>

Emits the default value when a null value is emitted

Link copied to clipboard

Emits the items that are different from all the values that have been emitted so far

Link copied to clipboard

Emits the items that are different from the last item

Link copied to clipboard

emits the item that was emitted at index position Note: This only works for elements that were emitted after the elementAt is applied.

Link copied to clipboard

Creates an empty LiveData.

Link copied to clipboard
inline fun <T> LiveData<T>.filter(crossinline predicate: (T?) -> Boolean): LiveData<T>

Emits the items that pass through the predicate

Link copied to clipboard

Emits at most 1 item and returns a SingleLiveData

Link copied to clipboard
fun <T> liveDataOf(initialValue: T): MutableLiveData<T>

Creates a LiveData that emits the initialValue immediately.

fun <T> liveDataOf(callable: () -> T): LiveData<T>

Creates a LiveData that emits the value that the callable function produces, immediately.

Link copied to clipboard

Merges multiple LiveData, and emits any item that was emitted by any of them

Link copied to clipboard
fun <T> LiveData<T>.mergeWith(vararg liveDatas: LiveData<T>): LiveData<T>

Merges this LiveData with another one, and emits any item that was emitted by any of them

Link copied to clipboard

Emits only the values that are not null

Link copied to clipboard

Emits only the values that are not null

Link copied to clipboard

Notifies the observer with the same live data as it holds

Link copied to clipboard
inline fun <T, L : LiveData<T>> LifecycleOwner.observe(liveData: L, crossinline body: (T) -> Unit = {})

Shorthand function that will observe the liveData using this as the LifecycleOwner. If the emitted value is not null then body is invoked with it as an argument.

Link copied to clipboard
fun <T, L : LiveData<SingleEvent<T>>> LifecycleOwner.observeEvent(liveData: L, body: (T) -> Unit = {})

Shorthand function that will observe the liveData using this as the LifecycleOwner. It uses EventObserver to observe the emitted values.

inline fun <T> LiveData<SingleEvent<T>>.observeEvent(owner: LifecycleOwner, crossinline onEventUnhandledContent: (T) -> Unit)
Link copied to clipboard
fun <T> LiveData<T>.observeOnce(observer: Observer<T>)
Link copied to clipboard
fun <T> MutableLiveData<T>.postValueIfNew(newValue: T)
Link copied to clipboard
fun <T> MutableLiveData<T>.setValueIfNew(newValue: T)
Link copied to clipboard
fun <T> LiveData<T>.skip(count: Int): LiveData<T>

Skips the first n values

Link copied to clipboard
inline fun <T> LiveData<T>.skipUntil(crossinline predicate: (T?) -> Boolean): LiveData<T>

Skips all values until a certain predicate is met (the item that actives the predicate is also emitted)

Link copied to clipboard
fun <T> LiveData<T>.startWith(startingValue: T?): LiveData<T>

Emits the startingValue before any other value.

Link copied to clipboard
fun <T> LiveData<T>.take(count: Int): LiveData<T>

Emits the first n valueus

Link copied to clipboard
inline fun <T> LiveData<T>.takeUntil(crossinline predicate: (T?) -> Boolean): LiveData<T>

Takes until a certain predicate is met, and does not emit anything after that, whatever the value.

Link copied to clipboard
fun <T> LiveData<T>.then(otherLiveData: LiveData<T>): LiveData<T>

Converts the LiveData to SingleLiveData and concats it with the otherLiveData and emits their values one by one

Link copied to clipboard

Converts a LiveData to a MutableLiveData with the initial value set by this LiveData's value

Link copied to clipboard

Converts a LiveData to a SingleLiveData (exactly similar to LiveData.first()