From a571bb56370593486c640ab910dd1dfab7d3e141 Mon Sep 17 00:00:00 2001 From: inorichi Date: Fri, 11 Dec 2015 17:47:07 +0100 Subject: [PATCH] Recover manga activity status when the process restarts --- .../eu/kanade/mangafeed/ui/manga/MangaPresenter.java | 3 ++- .../mangafeed/ui/manga/chapter/ChaptersPresenter.java | 10 ++++++++++ .../mangafeed/ui/manga/info/MangaInfoPresenter.java | 10 ++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/manga/MangaPresenter.java b/app/src/main/java/eu/kanade/mangafeed/ui/manga/MangaPresenter.java index d2addc4d91..803b9dea9c 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/manga/MangaPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/manga/MangaPresenter.java @@ -8,6 +8,7 @@ import de.greenrobot.event.EventBus; import eu.kanade.mangafeed.data.database.DatabaseHelper; import eu.kanade.mangafeed.data.database.models.Manga; import eu.kanade.mangafeed.ui.base.presenter.BasePresenter; +import icepick.State; import rx.Observable; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; @@ -16,7 +17,7 @@ public class MangaPresenter extends BasePresenter { @Inject DatabaseHelper db; - private long mangaId; + @State long mangaId; private static final int DB_MANGA = 1; diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/manga/chapter/ChaptersPresenter.java b/app/src/main/java/eu/kanade/mangafeed/ui/manga/chapter/ChaptersPresenter.java index 2ae9c540fa..fc0831c257 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/manga/chapter/ChaptersPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/manga/chapter/ChaptersPresenter.java @@ -52,6 +52,10 @@ public class ChaptersPresenter extends BasePresenter { protected void onCreate(Bundle savedState) { super.onCreate(savedState); + if (savedState != null) { + onProcessRestart(); + } + chaptersSubject = PublishSubject.create(); restartableLatestCache(DB_CHAPTERS, @@ -71,6 +75,12 @@ public class ChaptersPresenter extends BasePresenter { registerForStickyEvents(); } + private void onProcessRestart() { + stop(DB_CHAPTERS); + stop(FETCH_CHAPTERS); + stop(CHAPTER_STATUS_CHANGES); + } + @Override protected void onDestroy() { unregisterForEvents(); diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/manga/info/MangaInfoPresenter.java b/app/src/main/java/eu/kanade/mangafeed/ui/manga/info/MangaInfoPresenter.java index 332a4bcc53..a58c54dfd0 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/manga/info/MangaInfoPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/manga/info/MangaInfoPresenter.java @@ -36,6 +36,10 @@ public class MangaInfoPresenter extends BasePresenter { protected void onCreate(Bundle savedState) { super.onCreate(savedState); + if (savedState != null) { + onProcessRestart(); + } + restartableLatestCache(GET_MANGA, () -> Observable.just(manga), MangaInfoFragment::onNextManga); @@ -52,6 +56,12 @@ public class MangaInfoPresenter extends BasePresenter { registerForStickyEvents(); } + private void onProcessRestart() { + stop(GET_MANGA); + stop(GET_CHAPTER_COUNT); + stop(FETCH_MANGA_INFO); + } + @Override protected void onDestroy() { unregisterForEvents();