summaryrefslogtreecommitdiff
path: root/app/src/main/java/org/the_jk/cleversync/LiveDataUtils.kt
blob: 7f6ab1fd54e61cd4c599b7a8a46d3cf5f7fd4277 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
package org.the_jk.cleversync

import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer

fun <T> LiveData<T>.safeValue(): T? {
    if (this.hasActiveObservers())
        return value
    var ret: T? = null
    val observer = Observer<T> { value -> ret = value }
    this.observeForever(observer)
    this.removeObserver(observer)
    return ret
}