Replace onProcessRestart with the new startables.

This commit is contained in:
inorichi
2016-02-03 21:09:40 +01:00
parent 3deac86bbe
commit aada373a0c
6 changed files with 152 additions and 89 deletions
@@ -52,26 +52,22 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
protected void onCreate(Bundle savedState) {
super.onCreate(savedState);
if (savedState != null) {
onProcessRestart();
}
chaptersSubject = PublishSubject.create();
restartableLatestCache(GET_MANGA,
startableLatestCache(GET_MANGA,
() -> Observable.just(manga),
ChaptersFragment::onNextManga);
restartableLatestCache(DB_CHAPTERS,
startableLatestCache(DB_CHAPTERS,
this::getDbChaptersObs,
ChaptersFragment::onNextChapters);
restartableFirst(FETCH_CHAPTERS,
startableFirst(FETCH_CHAPTERS,
this::getOnlineChaptersObs,
(view, result) -> view.onFetchChaptersDone(),
(view, error) -> view.onFetchChaptersError());
restartableLatestCache(CHAPTER_STATUS_CHANGES,
startableLatestCache(CHAPTER_STATUS_CHANGES,
this::getChapterStatusObs,
(view, download) -> view.onChapterStatusChange(download),
(view, error) -> Timber.e(error.getCause(), error.getMessage()));
@@ -79,13 +75,6 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
registerForStickyEvents();
}
private void onProcessRestart() {
stop(GET_MANGA);
stop(DB_CHAPTERS);
stop(FETCH_CHAPTERS);
stop(CHAPTER_STATUS_CHANGES);
}
@Override
protected void onDestroy() {
unregisterForEvents();
@@ -64,22 +64,18 @@ public class MangaInfoPresenter extends BasePresenter<MangaInfoFragment> {
protected void onCreate(Bundle savedState) {
super.onCreate(savedState);
if (savedState != null) {
onProcessRestart();
}
// Update manga cache
restartableLatestCache(GET_MANGA,
// Notify the view a manga is available or has changed
startableLatestCache(GET_MANGA,
() -> Observable.just(manga),
(view, manga) -> view.onNextManga(manga, source));
// Update chapter count
restartableLatestCache(GET_CHAPTER_COUNT,
startableLatestCache(GET_CHAPTER_COUNT,
() -> Observable.just(count),
MangaInfoFragment::setChapterCount);
// Fetch manga info from source
restartableFirst(FETCH_MANGA_INFO,
startableFirst(FETCH_MANGA_INFO,
this::fetchMangaObs,
(view, manga) -> view.onFetchMangaDone(),
(view, error) -> view.onFetchMangaError());
@@ -88,15 +84,6 @@ public class MangaInfoPresenter extends BasePresenter<MangaInfoFragment> {
registerForStickyEvents();
}
/**
* Called when savedState not null
*/
private void onProcessRestart() {
stop(GET_MANGA);
stop(GET_CHAPTER_COUNT);
stop(FETCH_MANGA_INFO);
}
@Override
protected void onDestroy() {
unregisterForEvents();
@@ -44,20 +44,16 @@ public class MyAnimeListPresenter extends BasePresenter<MyAnimeListFragment> {
protected void onCreate(Bundle savedState) {
super.onCreate(savedState);
if (savedState != null) {
onProcessRestart();
}
myAnimeList = syncManager.getMyAnimeList();
restartableLatestCache(GET_MANGA_SYNC,
startableLatestCache(GET_MANGA_SYNC,
() -> db.getMangaSync(manga, myAnimeList).asRxObservable()
.doOnNext(mangaSync -> this.mangaSync = mangaSync)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()),
MyAnimeListFragment::setMangaSync);
restartableLatestCache(GET_SEARCH_RESULTS,
startableLatestCache(GET_SEARCH_RESULTS,
this::getSearchResultsObservable,
(view, results) -> {
view.setSearchResults(results);
@@ -66,7 +62,7 @@ public class MyAnimeListPresenter extends BasePresenter<MyAnimeListFragment> {
view.setSearchResultsError();
});
restartableFirst(REFRESH,
startableFirst(REFRESH,
() -> myAnimeList.getList()
.flatMap(myList -> {
for (MangaSync myManga : myList) {
@@ -86,12 +82,6 @@ public class MyAnimeListPresenter extends BasePresenter<MyAnimeListFragment> {
}
private void onProcessRestart() {
stop(GET_MANGA_SYNC);
stop(GET_SEARCH_RESULTS);
stop(REFRESH);
}
@Override
protected void onTakeView(MyAnimeListFragment view) {
super.onTakeView(view);