diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2024-07-11 23:28:01 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2024-07-11 23:28:01 +0200 |
| commit | 5ac1ae8525181ba86ac6c17ef2192a5f7b17a86c (patch) | |
| tree | de8250a7f4a76cbf789f380a8a3a4ca9b2d16f37 /app/src/main/java/org/the_jk/cleversync/LiveDataUtils.kt | |
Initial commit
Local (Path based) implementation of Tree, Directory, File and Link.
Diffstat (limited to 'app/src/main/java/org/the_jk/cleversync/LiveDataUtils.kt')
| -rw-r--r-- | app/src/main/java/org/the_jk/cleversync/LiveDataUtils.kt | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/app/src/main/java/org/the_jk/cleversync/LiveDataUtils.kt b/app/src/main/java/org/the_jk/cleversync/LiveDataUtils.kt new file mode 100644 index 0000000..7f6ab1f --- /dev/null +++ b/app/src/main/java/org/the_jk/cleversync/LiveDataUtils.kt @@ -0,0 +1,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 +} |
