Skip to content

Instantly share code, notes, and snippets.

@bam-e22
Last active January 13, 2020 01:01
Show Gist options
  • Select an option

  • Save bam-e22/6810fa3890de46085126f2558d1caeda to your computer and use it in GitHub Desktop.

Select an option

Save bam-e22/6810fa3890de46085126f2558d1caeda to your computer and use it in GitHub Desktop.
Retrofit + RxJava2 : Flowable Combining #RxJava
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