mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-25 02:18:24 +01:00
Add an observable that notifies of every download progress
This commit is contained in:
parent
758ebfca0b
commit
03ddf6d376
@ -219,8 +219,8 @@ public class DownloadManager {
|
|||||||
.doOnNext(p -> {
|
.doOnNext(p -> {
|
||||||
page.setImagePath(imagePath.getAbsolutePath());
|
page.setImagePath(imagePath.getAbsolutePath());
|
||||||
page.setProgress(100);
|
page.setProgress(100);
|
||||||
page.setStatus(Page.READY);
|
|
||||||
download.downloadedImages++;
|
download.downloadedImages++;
|
||||||
|
page.setStatus(Page.READY);
|
||||||
})
|
})
|
||||||
// If the download fails, mark this page as error
|
// If the download fails, mark this page as error
|
||||||
.doOnError(e -> page.setStatus(Page.ERROR))
|
.doOnError(e -> page.setStatus(Page.ERROR))
|
||||||
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import eu.kanade.mangafeed.data.database.models.Chapter;
|
import eu.kanade.mangafeed.data.database.models.Chapter;
|
||||||
|
import eu.kanade.mangafeed.data.source.model.Page;
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
import rx.subjects.PublishSubject;
|
import rx.subjects.PublishSubject;
|
||||||
|
|
||||||
@ -58,4 +59,33 @@ public class DownloadQueue {
|
|||||||
return statusSubject;
|
return statusSubject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Observable<Download> getProgressObservable() {
|
||||||
|
return statusSubject
|
||||||
|
.startWith(getActiveDownloads())
|
||||||
|
.flatMap(download -> {
|
||||||
|
if (download.getStatus() == Download.DOWNLOADING) {
|
||||||
|
PublishSubject<Integer> pageStatusSubject = PublishSubject.create();
|
||||||
|
setPagesSubject(download.pages, pageStatusSubject);
|
||||||
|
return pageStatusSubject
|
||||||
|
.filter(status -> status == Page.READY)
|
||||||
|
.flatMap(status -> Observable.just(download));
|
||||||
|
|
||||||
|
} else if (download.getStatus() == Download.DOWNLOADED ||
|
||||||
|
download.getStatus() == Download.ERROR) {
|
||||||
|
|
||||||
|
setPagesSubject(download.pages, null);
|
||||||
|
}
|
||||||
|
return Observable.just(download);
|
||||||
|
})
|
||||||
|
.filter(download -> download.getStatus() == Download.DOWNLOADING);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setPagesSubject(List<Page> pages, PublishSubject<Integer> subject) {
|
||||||
|
if (pages != null) {
|
||||||
|
for (Page page : pages) {
|
||||||
|
page.setStatusSubject(subject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,6 @@ public class MangaInfoFragment extends BaseRxFragment<MangaInfoPresenter> {
|
|||||||
} else {
|
} else {
|
||||||
coverCache.loadFromNetwork(cover, manga.thumbnail_url, headers);
|
coverCache.loadFromNetwork(cover, manga.thumbnail_url, headers);
|
||||||
}
|
}
|
||||||
cover.setTag(manga.thumbnail_url);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user