Update insertOrRemoveChapters method

This commit is contained in:
inorichi 2015-10-08 14:28:57 +02:00
parent 67a2e99cc1
commit 74ccd8bd24

View file

@ -62,22 +62,28 @@ public class ChapterManagerImpl extends BaseManager implements ChapterManager {
return Observable.create(subscriber -> {
List<Chapter> dbChapters = prepareGet(manga).executeAsBlocking();
Observable<List<Chapter>> newChaptersObs =
Observable<Integer> newChaptersObs =
Observable.from(chapters)
.filter(c -> !dbChapters.contains(c))
.toList();
.toList()
.flatMap(this::insertChapters)
.map(PutResults::numberOfInserts);
Observable<List<Chapter>> deletedChaptersObs =
Observable<Integer> deletedChaptersObs =
Observable.from(dbChapters)
.filter(c -> !chapters.contains(c))
.toList();
.toList()
.flatMap(this::deleteChapters)
.map(result -> result.results().size());
Observable.zip(newChaptersObs, deletedChaptersObs,
(newChapters, deletedChapters) -> {
insertChapters(newChapters).subscribe();
deleteChapters(deletedChapters).subscribe();
ArrayList<Integer> results = new ArrayList<>();
results.add(newChapters);
results.add(deletedChapters);
subscriber.onNext(results);
subscriber.onCompleted();
return null;
return results;
}).subscribe();
});
}