Reuse Observer interface.

This commit is contained in:
akwizgran
2018-11-01 17:24:22 +00:00
committed by Torsten Grote
parent fb2ab861db
commit 12a1cf8f8b
2 changed files with 5 additions and 19 deletions

View File

@@ -1,13 +0,0 @@
package org.briarproject.briar.android.util;
import android.support.annotation.Nullable;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
@NotNullByDefault
public interface Runnable<T> {
void run(@Nullable T t);
}

View File

@@ -319,18 +319,17 @@ public class UiUtils {
} }
/** /**
* Observes the given {@link LiveData<T>} until the first change. * Observes the given {@link LiveData} until the first change.
* If the LiveData's value is available, * If the LiveData's value is available, the {@link Observer} will be
* the {@link Runnable<T>} will be executed right away. * called right away.
*/ */
@MainThread @MainThread
public static <T> void observeOnce(LiveData<T> liveData, public static <T> void observeOnce(LiveData<T> liveData,
LifecycleOwner owner, LifecycleOwner owner, Observer<T> observer) {
Runnable<T> function) {
liveData.observe(owner, new Observer<T>() { liveData.observe(owner, new Observer<T>() {
@Override @Override
public void onChanged(@Nullable T t) { public void onChanged(@Nullable T t) {
function.run(t); observer.onChanged(t);
liveData.removeObserver(this); liveData.removeObserver(this);
} }
}); });