Last active
January 13, 2020 01:01
-
-
Save bam-e22/6810fa3890de46085126f2558d1caeda to your computer and use it in GitHub Desktop.
Retrofit + RxJava2 : Flowable Combining #RxJava
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| newsList = new ArrayList<>(); | |
| NetworkService networkService = GlobalApplication.getGlobalApplicationContext().getNetworkService(); | |
| List<Flowable<?>> newsRequests = new ArrayList<>(); | |
| List<String> selectedCategory = newsCard.getConfigNews().getCategory(); | |
| for (String cat : selectedCategory) { | |
| newsRequests.add(networkService.getNews(cat)); | |
| } | |
| Flowable.merge(newsRequests) | |
| .subscribeOn(Schedulers.io()) | |
| .observeOn(AndroidSchedulers.mainThread()) | |
| .subscribe(new FlowableSubscriber<Object>() { | |
| @Override | |
| public void onSubscribe(Subscription s) { | |
| DebugLog.logD(TAG, "[requsetNewsInfo] - onSubscribe"); | |
| s.request(1000); | |
| } | |
| @Override | |
| public void onNext(Object o) { | |
| DebugLog.logD(TAG, "[requsetNewsInfo] - onNext"); | |
| newsList.addAll((List<NewsItem>) o); | |
| } | |
| @Override | |
| public void onError(Throwable t) { | |
| DebugLog.logD(TAG, "[requsetNewsInfo] - onError", t); | |
| } | |
| @Override | |
| public void onComplete() { | |
| DebugLog.logD(TAG, "[requsetNewsInfo] - onComplete"); | |
| for (NewsItem item : newsList) { | |
| DebugLog.logD(TAG, "[NewsItem] " + item.toString()); | |
| } | |
| mainView.showNews(newsList); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment