Search in sources :

Example 11 with Consumer

use of io.reactivex.functions.Consumer in project RxDownload by ssseasonnn.

the class DownloadService method startDispatch.

/**
     * start dispatch download queue.
     */
private void startDispatch() {
    disposable = Observable.create(new ObservableOnSubscribe<DownloadMission>() {

        @Override
        public void subscribe(ObservableEmitter<DownloadMission> emitter) throws Exception {
            DownloadMission mission;
            while (!emitter.isDisposed()) {
                try {
                    log(WAITING_FOR_MISSION_COME);
                    mission = downloadQueue.take();
                    log(Constant.MISSION_COMING);
                } catch (InterruptedException e) {
                    log("Interrupt blocking queue.");
                    continue;
                }
                emitter.onNext(mission);
            }
            emitter.onComplete();
        }
    }).subscribeOn(Schedulers.newThread()).subscribe(new Consumer<DownloadMission>() {

        @Override
        public void accept(DownloadMission mission) throws Exception {
            mission.start(semaphore);
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(Throwable throwable) throws Exception {
            log(throwable);
        }
    });
}
Also used : ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) Consumer(io.reactivex.functions.Consumer) DownloadMission(zlc.season.rxdownload2.entity.DownloadMission) ObservableEmitter(io.reactivex.ObservableEmitter)

Example 12 with Consumer

use of io.reactivex.functions.Consumer in project RxFacebook by YouClap.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    callbackManager = CallbackManager.Factory.create();
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View view) {
            List<String> perm = new ArrayList<>();
            perm.add("email");
            perm.add("public_profile");
            RxFacebookLogin.logInWithReadPermissions(perm).subscribe(new Consumer<LoginResult>() {

                @Override
                public void accept(@NonNull LoginResult loginResult) throws Exception {
                    Log.d(LOG_TAG, "accept " + loginResult.getAccessToken());
                }
            }, new Consumer<Throwable>() {

                @Override
                public void accept(@NonNull Throwable throwable) throws Exception {
                    Log.e(LOG_TAG, "error ", throwable);
                }
            }, new Action() {

                @Override
                public void run() throws Exception {
                    Log.e(LOG_TAG, "onCompleted");
                }
            });
        }
    });
}
Also used : Action(io.reactivex.functions.Action) Consumer(io.reactivex.functions.Consumer) NonNull(io.reactivex.annotations.NonNull) LoginResult(com.facebook.login.LoginResult) FloatingActionButton(android.support.design.widget.FloatingActionButton) ArrayList(java.util.ArrayList) List(java.util.List) View(android.view.View) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

Consumer (io.reactivex.functions.Consumer)12 Action (io.reactivex.functions.Action)3 Test (org.junit.Test)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 ViewPager (android.support.v4.view.ViewPager)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 LoginResult (com.facebook.login.LoginResult)1 RxPermissions (com.tbruyelle.rxpermissions2.RxPermissions)1 MaterialTabs (io.karim.MaterialTabs)1 Observable (io.reactivex.Observable)1 ObservableEmitter (io.reactivex.ObservableEmitter)1 ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)1 NonNull (io.reactivex.annotations.NonNull)1 Disposable (io.reactivex.disposables.Disposable)1 Function (io.reactivex.functions.Function)1 BooleanSubscription (io.reactivex.internal.subscriptions.BooleanSubscription)1