Reduce visibility of LiveEvent inner classes.

This commit is contained in:
akwizgran
2019-05-10 10:20:49 +01:00
parent 33fdca4aa1
commit 8005cdc659

View File

@@ -18,30 +18,30 @@ public class LiveEvent<T> extends LiveData<LiveEvent.ConsumableEvent<T>> {
super.observe(owner, observer); super.observe(owner, observer);
} }
public static class ConsumableEvent<T> { static class ConsumableEvent<T> {
private final T content; private final T content;
private boolean consumed = false; private boolean consumed = false;
public ConsumableEvent(T content) { ConsumableEvent(T content) {
this.content = content; this.content = content;
} }
@Nullable @Nullable
public T getContentIfNotConsumed() { T getContentIfNotConsumed() {
if (consumed) return null; if (consumed) return null;
else { consumed = true;
consumed = true; return content;
return content;
}
} }
} }
@Immutable @Immutable
public static class LiveEventObserver<T> static class LiveEventObserver<T>
implements Observer<ConsumableEvent<T>> { implements Observer<ConsumableEvent<T>> {
private final LiveEventHandler<T> handler; private final LiveEventHandler<T> handler;
public LiveEventObserver(LiveEventHandler<T> handler) { LiveEventObserver(LiveEventHandler<T> handler) {
this.handler = handler; this.handler = handler;
} }
@@ -49,13 +49,13 @@ public class LiveEvent<T> extends LiveData<LiveEvent.ConsumableEvent<T>> {
public void onChanged(@Nullable ConsumableEvent<T> consumableEvent) { public void onChanged(@Nullable ConsumableEvent<T> consumableEvent) {
if (consumableEvent != null) { if (consumableEvent != null) {
T content = consumableEvent.getContentIfNotConsumed(); T content = consumableEvent.getContentIfNotConsumed();
if (content != null) handler.onEventUnconsumedContent(content); if (content != null) handler.onEvent(content);
} }
} }
} }
public interface LiveEventHandler<T> { public interface LiveEventHandler<T> {
void onEventUnconsumedContent(T t); void onEvent(T t);
} }
} }