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