mirror of
https://git.mihon.tech/mihonapp/mihon
synced 2024-11-21 20:55:41 +03: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 -> {
|
return Observable.create(subscriber -> {
|
||||||
List<Chapter> dbChapters = prepareGet(manga).executeAsBlocking();
|
List<Chapter> dbChapters = prepareGet(manga).executeAsBlocking();
|
||||||
|
|
||||||
Observable<List<Chapter>> newChaptersObs =
|
Observable<Integer> newChaptersObs =
|
||||||
Observable.from(chapters)
|
Observable.from(chapters)
|
||||||
.filter(c -> !dbChapters.contains(c))
|
.filter(c -> !dbChapters.contains(c))
|
||||||
.toList();
|
.toList()
|
||||||
|
.flatMap(this::insertChapters)
|
||||||
|
.map(PutResults::numberOfInserts);
|
||||||
|
|
||||||
Observable<List<Chapter>> deletedChaptersObs =
|
Observable<Integer> deletedChaptersObs =
|
||||||
Observable.from(dbChapters)
|
Observable.from(dbChapters)
|
||||||
.filter(c -> !chapters.contains(c))
|
.filter(c -> !chapters.contains(c))
|
||||||
.toList();
|
.toList()
|
||||||
|
.flatMap(this::deleteChapters)
|
||||||
|
.map(result -> result.results().size());
|
||||||
|
|
||||||
Observable.zip(newChaptersObs, deletedChaptersObs,
|
Observable.zip(newChaptersObs, deletedChaptersObs,
|
||||||
(newChapters, deletedChapters) -> {
|
(newChapters, deletedChapters) -> {
|
||||||
insertChapters(newChapters).subscribe();
|
ArrayList<Integer> results = new ArrayList<>();
|
||||||
deleteChapters(deletedChapters).subscribe();
|
results.add(newChapters);
|
||||||
|
results.add(deletedChapters);
|
||||||
|
subscriber.onNext(results);
|
||||||
subscriber.onCompleted();
|
subscriber.onCompleted();
|
||||||
return null;
|
return results;
|
||||||
}).subscribe();
|
}).subscribe();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue