nucleus.presenter.delivery.DeliverFirst Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nucleus Show documentation
Show all versions of nucleus Show documentation
Nucleus is an Android library, which helps to use the Model-View-Presenter pattern
The newest version!
package nucleus.presenter.delivery;
import rx.Notification;
import rx.Observable;
import rx.functions.Func1;
public class DeliverFirst implements Observable.Transformer> {
private final Observable view;
public DeliverFirst(Observable view) {
this.view = view;
}
@Override
public Observable> call(Observable observable) {
return observable.materialize()
.take(1)
.switchMap(new Func1, Observable extends Delivery>>() {
@Override
public Observable extends Delivery> call(final Notification notification) {
return view.map(new Func1>() {
@Override
public Delivery call(View view) {
return view == null ? null : new Delivery<>(view, notification);
}
});
}
})
.filter(new Func1, Boolean>() {
@Override
public Boolean call(Delivery delivery) {
return delivery != null;
}
})
.take(1);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy