mirror of
https://github.com/mihonapp/mihon.git
synced 2026-01-22 04:22:43 +01:00
Temporarily include nucleus in the project
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user