Commit 451edba4 authored by Torsten Grote's avatar Torsten Grote

Merge branch 'live-event-reduce-visibility' into 'master'

Reduce visibility of LiveEvent inner classes

See merge request !1092
parents 58804799 8005cdc6
Pipeline #3296 passed with stage
in 6 minutes and 58 seconds
......@@ -18,30 +18,30 @@ public class LiveEvent<T> extends LiveData<LiveEvent.ConsumableEvent<T>> {
super.observe(owner, observer);
}
public static class ConsumableEvent<T> {
static class ConsumableEvent<T> {
private final T content;
private boolean consumed = false;
public ConsumableEvent(T content) {
ConsumableEvent(T content) {
this.content = content;
}
@Nullable
public T getContentIfNotConsumed() {
T getContentIfNotConsumed() {
if (consumed) return null;
else {
consumed = true;
return content;
}
consumed = true;
return content;
}
}
@Immutable
public static class LiveEventObserver<T>
static class LiveEventObserver<T>
implements Observer<ConsumableEvent<T>> {
private final LiveEventHandler<T> handler;
public LiveEventObserver(LiveEventHandler<T> handler) {
LiveEventObserver(LiveEventHandler<T> handler) {
this.handler = handler;
}
......@@ -49,13 +49,13 @@ public class LiveEvent<T> extends LiveData<LiveEvent.ConsumableEvent<T>> {
public void onChanged(@Nullable ConsumableEvent<T> consumableEvent) {
if (consumableEvent != null) {
T content = consumableEvent.getContentIfNotConsumed();
if (content != null) handler.onEventUnconsumedContent(content);
if (content != null) handler.onEvent(content);
}
}
}
public interface LiveEventHandler<T> {
void onEventUnconsumedContent(T t);
void onEvent(T t);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment