Update number of downloaded images in the queue, and improve the way the view refreshes the data

This commit is contained in:
inorichi
2015-11-09 03:31:50 +01:00
parent 7c37262a9f
commit ceb56e2c8a
6 changed files with 88 additions and 27 deletions

View File

@@ -77,7 +77,6 @@ public class DownloadManager {
.subscribe(threadsNumber::onNext);
downloadsSubscription = downloadsQueueSubject
.observeOn(Schedulers.newThread())
.lift(new DynamicConcurrentMergeOperator<>(this::downloadChapter, threadsNumber))
.onBackpressureBuffer()
.observeOn(AndroidSchedulers.mainThread())
@@ -167,6 +166,8 @@ public class DownloadManager {
Observable.just(download.pages);
return pageListObservable
.subscribeOn(Schedulers.io())
.doOnNext(pages -> download.downloadedImages = 0)
.doOnNext(pages -> download.setStatus(Download.DOWNLOADING))
// Get all the URLs to the source images, fetch pages if necessary
.flatMap(pageList -> Observable.merge(
@@ -174,6 +175,7 @@ public class DownloadManager {
download.source.getRemainingImageUrlsFromPageList(pageList)))
// Start downloading images, consider we can have downloaded images already
.concatMap(page -> getDownloadedImage(page, download.source, download.directory))
.doOnNext(p -> download.downloadedImages++)
// Do after download completes
.doOnCompleted(() -> onDownloadCompleted(download))
.toList()
@@ -363,6 +365,11 @@ public class DownloadManager {
public void stopDownloads() {
destroySubscriptions();
for (Download download : queue.get()) {
if (download.getStatus() == Download.DOWNLOADING) {
download.setStatus(Download.ERROR);
}
}
}
public boolean isRunning() {

View File

@@ -14,6 +14,7 @@ public class Download {
public File directory;
public transient volatile int totalProgress;
public transient volatile int downloadedImages;
private transient volatile int status;
private transient PublishSubject<Download> statusSubject;