From 74ccd8bd24ebf57eaeb2c532552518e369388d0e Mon Sep 17 00:00:00 2001 From: inorichi Date: Thu, 8 Oct 2015 14:28:57 +0200 Subject: [PATCH] Update insertOrRemoveChapters method --- .../data/managers/ChapterManagerImpl.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/data/managers/ChapterManagerImpl.java b/app/src/main/java/eu/kanade/mangafeed/data/managers/ChapterManagerImpl.java index c595a5c560..6c270a507c 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/managers/ChapterManagerImpl.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/managers/ChapterManagerImpl.java @@ -62,22 +62,28 @@ public class ChapterManagerImpl extends BaseManager implements ChapterManager { return Observable.create(subscriber -> { List dbChapters = prepareGet(manga).executeAsBlocking(); - Observable> newChaptersObs = + Observable newChaptersObs = Observable.from(chapters) .filter(c -> !dbChapters.contains(c)) - .toList(); + .toList() + .flatMap(this::insertChapters) + .map(PutResults::numberOfInserts); - Observable> deletedChaptersObs = + Observable 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 results = new ArrayList<>(); + results.add(newChapters); + results.add(deletedChapters); + subscriber.onNext(results); subscriber.onCompleted(); - return null; + return results; }).subscribe(); }); }