|
@@ -17,9 +17,9 @@ import eu.kanade.mangafeed.data.database.models.ChapterSync;
|
|
import eu.kanade.mangafeed.data.database.models.Manga;
|
|
import eu.kanade.mangafeed.data.database.models.Manga;
|
|
import eu.kanade.mangafeed.data.download.DownloadManager;
|
|
import eu.kanade.mangafeed.data.download.DownloadManager;
|
|
import eu.kanade.mangafeed.data.preference.PreferencesHelper;
|
|
import eu.kanade.mangafeed.data.preference.PreferencesHelper;
|
|
|
|
+import eu.kanade.mangafeed.data.source.SourceManager;
|
|
import eu.kanade.mangafeed.data.source.base.Source;
|
|
import eu.kanade.mangafeed.data.source.base.Source;
|
|
import eu.kanade.mangafeed.data.source.model.Page;
|
|
import eu.kanade.mangafeed.data.source.model.Page;
|
|
-import eu.kanade.mangafeed.event.RetryPageEvent;
|
|
|
|
import eu.kanade.mangafeed.event.ReaderEvent;
|
|
import eu.kanade.mangafeed.event.ReaderEvent;
|
|
import eu.kanade.mangafeed.event.UpdateChapterSyncEvent;
|
|
import eu.kanade.mangafeed.event.UpdateChapterSyncEvent;
|
|
import eu.kanade.mangafeed.ui.base.presenter.BasePresenter;
|
|
import eu.kanade.mangafeed.ui.base.presenter.BasePresenter;
|
|
@@ -38,16 +38,18 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
|
@Inject DatabaseHelper db;
|
|
@Inject DatabaseHelper db;
|
|
@Inject DownloadManager downloadManager;
|
|
@Inject DownloadManager downloadManager;
|
|
@Inject ChapterSyncManager syncManager;
|
|
@Inject ChapterSyncManager syncManager;
|
|
|
|
+ @Inject SourceManager sourceManager;
|
|
|
|
|
|
|
|
+ @State Manga manga;
|
|
|
|
+ @State Chapter chapter;
|
|
|
|
+ @State int sourceId;
|
|
|
|
+ @State boolean isDownloaded;
|
|
|
|
+ @State int currentPage;
|
|
private Source source;
|
|
private Source source;
|
|
- private Manga manga;
|
|
|
|
- private Chapter chapter;
|
|
|
|
private Chapter nextChapter;
|
|
private Chapter nextChapter;
|
|
private Chapter previousChapter;
|
|
private Chapter previousChapter;
|
|
private List<Page> pageList;
|
|
private List<Page> pageList;
|
|
private List<Page> nextChapterPageList;
|
|
private List<Page> nextChapterPageList;
|
|
- private boolean isDownloaded;
|
|
|
|
- @State int currentPage;
|
|
|
|
|
|
|
|
private PublishSubject<Page> retryPageSubject;
|
|
private PublishSubject<Page> retryPageSubject;
|
|
|
|
|
|
@@ -63,6 +65,10 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
|
protected void onCreate(Bundle savedState) {
|
|
protected void onCreate(Bundle savedState) {
|
|
super.onCreate(savedState);
|
|
super.onCreate(savedState);
|
|
|
|
|
|
|
|
+ if (savedState != null) {
|
|
|
|
+ onProcessRestart();
|
|
|
|
+ }
|
|
|
|
+
|
|
retryPageSubject = PublishSubject.create();
|
|
retryPageSubject = PublishSubject.create();
|
|
|
|
|
|
restartableLatestCache(GET_PAGE_LIST,
|
|
restartableLatestCache(GET_PAGE_LIST,
|
|
@@ -97,42 +103,35 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
|
this::getPreloadNextChapterObservable,
|
|
this::getPreloadNextChapterObservable,
|
|
(view, pages) -> {},
|
|
(view, pages) -> {},
|
|
(view, error) -> Timber.e("An error occurred while preloading a chapter"));
|
|
(view, error) -> Timber.e("An error occurred while preloading a chapter"));
|
|
- }
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
- protected void onTakeView(ReaderActivity view) {
|
|
|
|
- super.onTakeView(view);
|
|
|
|
registerForStickyEvents();
|
|
registerForStickyEvents();
|
|
}
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
|
- protected void onDropView() {
|
|
|
|
- unregisterForEvents();
|
|
|
|
- super.onDropView();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
protected void onDestroy() {
|
|
protected void onDestroy() {
|
|
|
|
+ unregisterForEvents();
|
|
onChapterLeft();
|
|
onChapterLeft();
|
|
super.onDestroy();
|
|
super.onDestroy();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void onProcessRestart() {
|
|
|
|
+ source = sourceManager.get(sourceId);
|
|
|
|
+
|
|
|
|
+ // These are started by GET_PAGE_LIST, so we don't let them restart itselves
|
|
|
|
+ stop(GET_PAGE_IMAGES);
|
|
|
|
+ stop(RETRY_IMAGES);
|
|
|
|
+ stop(PRELOAD_NEXT_CHAPTER);
|
|
|
|
+ }
|
|
|
|
+
|
|
@EventBusHook
|
|
@EventBusHook
|
|
public void onEventMainThread(ReaderEvent event) {
|
|
public void onEventMainThread(ReaderEvent event) {
|
|
EventBus.getDefault().removeStickyEvent(event);
|
|
EventBus.getDefault().removeStickyEvent(event);
|
|
- source = event.getSource();
|
|
|
|
manga = event.getManga();
|
|
manga = event.getManga();
|
|
|
|
+ source = event.getSource();
|
|
|
|
+ sourceId = source.getSourceId();
|
|
loadChapter(event.getChapter());
|
|
loadChapter(event.getChapter());
|
|
}
|
|
}
|
|
|
|
|
|
- @EventBusHook
|
|
|
|
- public void onEventMainThread(RetryPageEvent event) {
|
|
|
|
- EventBus.getDefault().removeStickyEvent(event);
|
|
|
|
- Page page = event.getPage();
|
|
|
|
- page.setStatus(Page.QUEUE);
|
|
|
|
- retryPageSubject.onNext(page);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
// Returns the page list of a chapter
|
|
// Returns the page list of a chapter
|
|
private Observable<List<Page>> getPageListObservable() {
|
|
private Observable<List<Page>> getPageListObservable() {
|
|
return isDownloaded ?
|
|
return isDownloaded ?
|
|
@@ -216,6 +215,11 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
|
return downloadManager.isChapterDownloaded(source, manga, chapter);
|
|
return downloadManager.isChapterDownloaded(source, manga, chapter);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void retryPage(Page page) {
|
|
|
|
+ page.setStatus(Page.QUEUE);
|
|
|
|
+ retryPageSubject.onNext(page);
|
|
|
|
+ }
|
|
|
|
+
|
|
// Called before loading another chapter or leaving the reader. It allows to do operations
|
|
// Called before loading another chapter or leaving the reader. It allows to do operations
|
|
// over the chapter read like saving progress
|
|
// over the chapter read like saving progress
|
|
private void onChapterLeft() {
|
|
private void onChapterLeft() {
|