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