mirror of
https://github.com/mihonapp/mihon.git
synced 2026-01-20 19:42:41 +01:00
43 lines
1.4 KiB
Java
43 lines
1.4 KiB
Java
package nucleus.presenter.delivery;
|
|
|
|
import rx.Notification;
|
|
import rx.Observable;
|
|
import rx.functions.Func1;
|
|
import rx.functions.Func2;
|
|
|
|
public class DeliverLatestCache<View, T> implements Observable.Transformer<T, Delivery<View, T>> {
|
|
|
|
private final Observable<View> view;
|
|
|
|
public DeliverLatestCache(Observable<View> view) {
|
|
this.view = view;
|
|
}
|
|
|
|
@Override
|
|
public Observable<Delivery<View, T>> call(Observable<T> observable) {
|
|
return Observable
|
|
.combineLatest(
|
|
view,
|
|
observable
|
|
.materialize()
|
|
.filter(new Func1<Notification<T>, Boolean>() {
|
|
@Override
|
|
public Boolean call(Notification<T> notification) {
|
|
return !notification.isOnCompleted();
|
|
}
|
|
}),
|
|
new Func2<View, Notification<T>, Delivery<View, T>>() {
|
|
@Override
|
|
public Delivery<View, T> call(View view, Notification<T> notification) {
|
|
return view == null ? null : new Delivery<>(view, notification);
|
|
}
|
|
})
|
|
.filter(new Func1<Delivery<View, T>, Boolean>() {
|
|
@Override
|
|
public Boolean call(Delivery<View, T> delivery) {
|
|
return delivery != null;
|
|
}
|
|
});
|
|
}
|
|
}
|