mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Update insertOrRemoveChapters method
This commit is contained in:
parent
67a2e99cc1
commit
74ccd8bd24
1 changed files with 13 additions and 7 deletions
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue