mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +01:00
Reuse Observer interface.
This commit is contained in:
@@ -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);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user