All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nucleus.presenter.delivery.DeliverFirst Maven / Gradle / Ivy

Go to download

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>>() {
                @Override
                public Observable> 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