From de8b7b27e1f828546c2a6f0b29900552884b7b78 Mon Sep 17 00:00:00 2001 From: inorichi Date: Wed, 4 Nov 2015 22:50:05 +0100 Subject: [PATCH] Minor changes --- .../mangafeed/data/helpers/DownloadManager.java | 4 ++-- .../eu/kanade/mangafeed/data/models/Page.java | 15 +++++---------- .../mangafeed/ui/fragment/ReaderPageFragment.java | 5 +++-- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/data/helpers/DownloadManager.java b/app/src/main/java/eu/kanade/mangafeed/data/helpers/DownloadManager.java index bb0e2d33d..3d378c8e2 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/helpers/DownloadManager.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/helpers/DownloadManager.java @@ -67,7 +67,7 @@ public class DownloadManager { downloadSubscription = downloadsSubject .subscribeOn(Schedulers.io()) .filter(event -> !isChapterDownloaded(event)) - .flatMap(this::createDownload) + .flatMap(this::prepareDownload) .flatMap(this::downloadChapter, preferences.getDownloadThreads()) .onBackpressureBuffer() .subscribe(); @@ -100,7 +100,7 @@ public class DownloadManager { } // Create a download object and add it to the downloads queue - private Observable createDownload(DownloadChapterEvent event) { + private Observable prepareDownload(DownloadChapterEvent event) { Download download = new Download( sourceManager.get(event.getManga().source), event.getManga(), diff --git a/app/src/main/java/eu/kanade/mangafeed/data/models/Page.java b/app/src/main/java/eu/kanade/mangafeed/data/models/Page.java index 1856ac922..e7cf497d4 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/models/Page.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/models/Page.java @@ -1,7 +1,7 @@ package eu.kanade.mangafeed.data.models; import eu.kanade.mangafeed.data.helpers.NetworkHelper; -import rx.subjects.BehaviorSubject; +import rx.subjects.PublishSubject; public class Page implements NetworkHelper.ProgressListener { @@ -12,7 +12,7 @@ public class Page implements NetworkHelper.ProgressListener { private transient volatile int status; private transient volatile int progress; - private transient BehaviorSubject statusSubject; + private transient PublishSubject statusSubject; public static final int QUEUE = 0; public static final int LOAD_PAGE = 1; @@ -61,7 +61,8 @@ public class Page implements NetworkHelper.ProgressListener { public void setStatus(int status) { this.status = status; - notifyStatus(); + if (statusSubject != null) + statusSubject.onNext(status); } public int getProgress() { @@ -73,14 +74,8 @@ public class Page implements NetworkHelper.ProgressListener { progress = (int) ((100 * bytesRead) / contentLength); } - public void setStatusSubject(BehaviorSubject subject) { + public void setStatusSubject(PublishSubject subject) { this.statusSubject = subject; - notifyStatus(); - } - - private void notifyStatus() { - if (statusSubject != null) - statusSubject.onNext(status); } } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/ReaderPageFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/ReaderPageFragment.java index 9360a4ba1..b13d92a61 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/ReaderPageFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/ReaderPageFragment.java @@ -25,7 +25,7 @@ import rx.Observable; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; -import rx.subjects.BehaviorSubject; +import rx.subjects.PublishSubject; public class ReaderPageFragment extends Fragment { @@ -128,10 +128,11 @@ public class ReaderPageFragment extends Fragment { if (page == null || statusSubscription != null) return; - BehaviorSubject statusSubject = BehaviorSubject.create(); + PublishSubject statusSubject = PublishSubject.create(); page.setStatusSubject(statusSubject); statusSubscription = statusSubject + .startWith(page.getStatus()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(this::processStatus); }