From e7f8d4d2c2eb0f94a97e2834d6c850a4d0e47e0f Mon Sep 17 00:00:00 2001 From: inorichi Date: Fri, 11 Dec 2015 14:14:04 +0100 Subject: [PATCH] Fix library update service --- .../mangafeed/data/sync/LibraryUpdateService.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/data/sync/LibraryUpdateService.java b/app/src/main/java/eu/kanade/mangafeed/data/sync/LibraryUpdateService.java index b705467c8..7bfd893da 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/sync/LibraryUpdateService.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/sync/LibraryUpdateService.java @@ -24,6 +24,7 @@ import eu.kanade.mangafeed.util.NotificationUtil; import eu.kanade.mangafeed.util.PostResult; import rx.Observable; import rx.Subscription; +import rx.schedulers.Schedulers; import timber.log.Timber; public class LibraryUpdateService extends Service { @@ -68,6 +69,7 @@ public class LibraryUpdateService extends Service { } Observable.fromCallable(() -> db.getFavoriteMangas().executeAsBlocking()) + .subscribeOn(Schedulers.io()) .subscribe(mangas -> { startUpdating(mangas, startId); }); @@ -76,9 +78,6 @@ public class LibraryUpdateService extends Service { } private void startUpdating(final List mangas, final int startId) { - if (updateSubscription != null && !updateSubscription.isUnsubscribed()) - updateSubscription.unsubscribe(); - final AtomicInteger count = new AtomicInteger(0); List updates = new ArrayList<>(); @@ -86,15 +85,14 @@ public class LibraryUpdateService extends Service { updateSubscription = Observable.from(mangas) .doOnNext(manga -> { NotificationUtil.create(this, UPDATE_NOTIFICATION_ID, - getString(R.string.notification_progress, count.incrementAndGet(), mangas.size()), - manga.title); + getString(R.string.notification_progress, + count.incrementAndGet(), mangas.size()), manga.title); }) .concatMap(manga -> sourceManager.get(manga.source) .pullChaptersFromNetwork(manga.url) .flatMap(chapters -> db.insertOrRemoveChapters(manga, chapters)) .filter(result -> result.getNumberOfRowsInserted() > 0) - .flatMap(result -> Observable.just(new MangaUpdate(manga, result))) - ) + .flatMap(result -> Observable.just(new MangaUpdate(manga, result)))) .subscribe(update -> { updates.add(update); }, error -> {