Fix NPE when the process restarts in the reader for downloaded chapters and save page list before killing the process.
This commit is contained in:
parent
3c87b4cba9
commit
9a117f0969
1 changed files with 25 additions and 16 deletions
|
@ -1,6 +1,7 @@
|
|||
package eu.kanade.mangafeed.ui.reader;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
@ -65,6 +66,22 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
|||
|
||||
retryPageSubject = PublishSubject.create();
|
||||
|
||||
restartableLatestCache(PRELOAD_NEXT_CHAPTER,
|
||||
this::getPreloadNextChapterObservable,
|
||||
(view, pages) -> {},
|
||||
(view, error) -> Timber.e("An error occurred while preloading a chapter"));
|
||||
|
||||
restartableReplay(GET_PAGE_IMAGES,
|
||||
() -> getPageImagesObservable()
|
||||
.doOnCompleted(this::preloadNextChapter),
|
||||
(view, page) -> {},
|
||||
(view, error) -> Timber.e("An error occurred while downloading an image"));
|
||||
|
||||
restartableLatestCache(RETRY_IMAGES,
|
||||
this::getRetryPageObservable,
|
||||
(view, page) -> {},
|
||||
(view, error) -> Timber.e("An error occurred while downloading an image"));
|
||||
|
||||
restartableLatestCache(GET_PAGE_LIST,
|
||||
() -> getPageListObservable()
|
||||
.doOnNext(pages -> pageList = pages)
|
||||
|
@ -80,22 +97,6 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
|||
},
|
||||
(view, error) -> view.onChapterError());
|
||||
|
||||
restartableReplay(GET_PAGE_IMAGES,
|
||||
() -> getPageImagesObservable()
|
||||
.doOnCompleted(this::preloadNextChapter),
|
||||
(view, page) -> {},
|
||||
(view, error) -> Timber.e("An error occurred while downloading an image"));
|
||||
|
||||
restartableLatestCache(RETRY_IMAGES,
|
||||
this::getRetryPageObservable,
|
||||
(view, page) -> {},
|
||||
(view, error) -> Timber.e("An error occurred while downloading an image"));
|
||||
|
||||
restartableLatestCache(PRELOAD_NEXT_CHAPTER,
|
||||
this::getPreloadNextChapterObservable,
|
||||
(view, pages) -> {},
|
||||
(view, error) -> Timber.e("An error occurred while preloading a chapter"));
|
||||
|
||||
registerForStickyEvents();
|
||||
}
|
||||
|
||||
|
@ -107,6 +108,14 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
|||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSave(@NonNull Bundle state) {
|
||||
if (pageList != null && !isDownloaded)
|
||||
source.savePageList(chapter.url, pageList);
|
||||
|
||||
super.onSave(state);
|
||||
}
|
||||
|
||||
private void onProcessRestart() {
|
||||
source = sourceManager.get(sourceId);
|
||||
|
||||
|
|
Reference in a new issue