Skip to content Skip to sidebar Skip to footer

Filter A Response Using Rx And Retrofit

I have a call in Rx like so: rxHelper.manageSubscription(HavocService.getInstance().getHavocAPI().getAllTasks(userId) .subscribeOn(Schedulers.io())

Solution 1:

This is what I ended up doing

rxHelper.manageSubscription(HavocService.getInstance().getHavocAPI().getAllTasks(USER)
                .flatMap(response -> Observable.from(response.getTasks()))
                //filter out Tasks that are ARCHIVED or DONE
                .filter(task -> task.getStatus() == TaskStatusEnum.INCOMPLETE)
                .toList()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(RxTiPresenterUtils.deliverLatestToView(this))
                .subscribe(list -> {
                    mListOfTasks = list;
                    getView().setTaskList(mListOfTasks);
                    getView().setLoading(false);
                }, throwable -> {
                    getView().setLoading(false);
                    throwable.printStackTrace();
                })
        );

Post a Comment for "Filter A Response Using Rx And Retrofit"