Read downloaded chapters
This commit is contained in:
parent
b0a8740e8d
commit
fa28ccc19a
@ -140,7 +140,6 @@ public class MangaChaptersPresenter extends BasePresenter<MangaChaptersFragment>
|
||||
remove(downloadSubscription);
|
||||
|
||||
add(downloadSubscription = selectedChapters
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe(chapter -> {
|
||||
EventBus.getDefault().post(
|
||||
new DownloadChapterEvent(manga, chapter));
|
||||
|
@ -38,7 +38,6 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
||||
|
||||
private static final int GET_PAGE_LIST = 1;
|
||||
private static final int GET_PAGE_IMAGES = 2;
|
||||
private static final int GET_LOCAL_IMAGES = 3;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedState) {
|
||||
@ -47,7 +46,7 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
||||
restartableLatestCache(GET_PAGE_LIST,
|
||||
() -> getPageListObservable()
|
||||
.doOnNext(pages -> pageList = pages)
|
||||
.doOnCompleted(this::prepareChapter),
|
||||
.doOnCompleted( () -> start(GET_PAGE_IMAGES) ),
|
||||
(view, pages) -> {
|
||||
view.onPageListReady(pages);
|
||||
if (currentPage != 0)
|
||||
@ -62,9 +61,6 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
||||
},
|
||||
(view, error) -> Timber.e("An error occurred while downloading an image"));
|
||||
|
||||
restartableReplay(GET_LOCAL_IMAGES,
|
||||
this::getLocalImagesObservable,
|
||||
(view, page) -> {});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -100,26 +96,31 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
||||
}
|
||||
|
||||
private Observable<List<Page>> getPageListObservable() {
|
||||
if (chapter.downloaded != Chapter.DOWNLOADED)
|
||||
return source.pullPageListFromNetwork(chapter.url)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
else
|
||||
return Observable.just(downloadManager.getSavedPageList(source, manga, chapter));
|
||||
}
|
||||
|
||||
private Observable<Page> getPageImagesObservable() {
|
||||
return Observable.merge(
|
||||
Observable.from(pageList).filter(page -> page.getImageUrl() != null),
|
||||
source.getRemainingImageUrlsFromPageList(pageList)
|
||||
)
|
||||
.flatMap(source::getCachedImage)
|
||||
Observable<Page> pages;
|
||||
|
||||
if (chapter.downloaded != Chapter.DOWNLOADED) {
|
||||
pages = Observable
|
||||
.merge(Observable.from(pageList).filter(page -> page.getImageUrl() != null),
|
||||
source.getRemainingImageUrlsFromPageList(pageList))
|
||||
.flatMap(source::getCachedImage);
|
||||
} else {
|
||||
File chapterDir = downloadManager.getAbsoluteChapterDirectory(source, manga, chapter);
|
||||
|
||||
pages = Observable.from(pageList)
|
||||
.flatMap(page -> downloadManager.getDownloadedImage(page, source, chapterDir))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
private Observable<Page> getLocalImagesObservable() {
|
||||
File chapterDir = downloadManager.getAbsoluteChapterDirectory(source, manga, chapter);
|
||||
|
||||
return Observable.from(pageList)
|
||||
.flatMap(page -> downloadManager.getDownloadedImage(page, source, chapterDir))
|
||||
return pages
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
@ -128,13 +129,6 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
||||
this.currentPage = currentPage;
|
||||
}
|
||||
|
||||
private void prepareChapter() {
|
||||
if (chapter.downloaded != Chapter.DOWNLOADED)
|
||||
start(GET_PAGE_IMAGES);
|
||||
else
|
||||
start(GET_LOCAL_IMAGES);
|
||||
}
|
||||
|
||||
private void saveChapter() {
|
||||
chapter.last_page_read = currentPage;
|
||||
if (currentPage == pageList.size() - 1) {
|
||||
|
@ -142,6 +142,7 @@ public class MangaChaptersFragment extends BaseRxFragment<MangaChaptersPresenter
|
||||
return true;
|
||||
case R.id.action_download:
|
||||
getPresenter().downloadChapters(getSelectedChapters());
|
||||
closeActionMode();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -7,6 +7,7 @@
|
||||
android:entries="@array/download_threads"
|
||||
android:entryValues="@array/download_threads"
|
||||
android:defaultValue="1"
|
||||
android:order="1"
|
||||
android:summary="%s"/>
|
||||
|
||||
</PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user