예제 #1
0
 public void filter(String query) {
   if (popularTags != null) {
     Observable.from(popularTags)
         .compose(BenihScheduler.pluck().applySchedulers(BenihScheduler.Type.NEW_THREAD))
         .filter(tag -> tag.getName().toLowerCase().contains(query.toLowerCase()))
         .map(
             tag -> {
               tag.setFollowed(DataBaseHelper.pluck().isFollowed(tag));
               return tag;
             })
         .toList()
         .subscribe(presenter::showFilteredTag, presenter::showError);
   }
 }
예제 #2
0
 public void loadPopularTags(int page) {
   presenter.showLoading();
   CodePolitanApi.pluck()
       .getApi()
       .getPopularTags(page)
       .compose(BenihScheduler.pluck().applySchedulers(BenihScheduler.Type.IO))
       .flatMap(articleListResponse -> Observable.from(articleListResponse.getResult()))
       .map(
           tag -> {
             tag.setFollowed(DataBaseHelper.pluck().isFollowed(tag));
             return tag;
           })
       .toList()
       .subscribe(
           tags -> {
             BenihWorker.pluck()
                 .doInNewThread(
                     () -> {
                       if (page == 1) {
                         popularTags = tags;
                       } else {
                         popularTags.addAll(tags);
                       }
                     })
                 .subscribe(
                     o -> {
                       if (presenter != null) {
                         presenter.showPopularTags(tags);
                       }
                     });
             if (presenter != null) {
               presenter.dismissLoading();
             }
           },
           throwable -> {
             if (presenter != null) {
               Timber.d(throwable.getMessage());
               presenter.showError(new Throwable(ErrorEvent.LOAD_POPULAR_TAGS));
               presenter.dismissLoading();
             }
           });
 }