Fix library update service

This commit is contained in:
inorichi 2015-12-11 14:14:04 +01:00
parent ed5486975d
commit e7f8d4d2c2

View File

@ -24,6 +24,7 @@ import eu.kanade.mangafeed.util.NotificationUtil;
import eu.kanade.mangafeed.util.PostResult; import eu.kanade.mangafeed.util.PostResult;
import rx.Observable; import rx.Observable;
import rx.Subscription; import rx.Subscription;
import rx.schedulers.Schedulers;
import timber.log.Timber; import timber.log.Timber;
public class LibraryUpdateService extends Service { public class LibraryUpdateService extends Service {
@ -68,6 +69,7 @@ public class LibraryUpdateService extends Service {
} }
Observable.fromCallable(() -> db.getFavoriteMangas().executeAsBlocking()) Observable.fromCallable(() -> db.getFavoriteMangas().executeAsBlocking())
.subscribeOn(Schedulers.io())
.subscribe(mangas -> { .subscribe(mangas -> {
startUpdating(mangas, startId); startUpdating(mangas, startId);
}); });
@ -76,9 +78,6 @@ public class LibraryUpdateService extends Service {
} }
private void startUpdating(final List<Manga> mangas, final int startId) { private void startUpdating(final List<Manga> mangas, final int startId) {
if (updateSubscription != null && !updateSubscription.isUnsubscribed())
updateSubscription.unsubscribe();
final AtomicInteger count = new AtomicInteger(0); final AtomicInteger count = new AtomicInteger(0);
List<MangaUpdate> updates = new ArrayList<>(); List<MangaUpdate> updates = new ArrayList<>();
@ -86,15 +85,14 @@ public class LibraryUpdateService extends Service {
updateSubscription = Observable.from(mangas) updateSubscription = Observable.from(mangas)
.doOnNext(manga -> { .doOnNext(manga -> {
NotificationUtil.create(this, UPDATE_NOTIFICATION_ID, NotificationUtil.create(this, UPDATE_NOTIFICATION_ID,
getString(R.string.notification_progress, count.incrementAndGet(), mangas.size()), getString(R.string.notification_progress,
manga.title); count.incrementAndGet(), mangas.size()), manga.title);
}) })
.concatMap(manga -> sourceManager.get(manga.source) .concatMap(manga -> sourceManager.get(manga.source)
.pullChaptersFromNetwork(manga.url) .pullChaptersFromNetwork(manga.url)
.flatMap(chapters -> db.insertOrRemoveChapters(manga, chapters)) .flatMap(chapters -> db.insertOrRemoveChapters(manga, chapters))
.filter(result -> result.getNumberOfRowsInserted() > 0) .filter(result -> result.getNumberOfRowsInserted() > 0)
.flatMap(result -> Observable.just(new MangaUpdate(manga, result))) .flatMap(result -> Observable.just(new MangaUpdate(manga, result))))
)
.subscribe(update -> { .subscribe(update -> {
updates.add(update); updates.add(update);
}, error -> { }, error -> {