From 80a59548a5a572ceb65750b5c3cd961e33993bd2 Mon Sep 17 00:00:00 2001 From: inorichi Date: Mon, 21 Dec 2015 17:58:12 +0100 Subject: [PATCH] Merge changes from Nucleus presenter --- .../ui/base/presenter/RxPresenter.java | 39 ++++++++++++------- .../ui/manga/chapter/ChaptersPresenter.java | 2 +- .../mangafeed/ui/reader/ReaderPresenter.java | 2 +- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/base/presenter/RxPresenter.java b/app/src/main/java/eu/kanade/mangafeed/ui/base/presenter/RxPresenter.java index df7fbd96d1..4d1ddde0cd 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/base/presenter/RxPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/base/presenter/RxPresenter.java @@ -100,20 +100,21 @@ public class RxPresenter extends Presenter { * @param restartableId id of a restartable. */ public void stop(int restartableId) { - requested.remove((Integer)restartableId); + requested.remove((Integer) restartableId); Subscription subscription = restartableSubscriptions.get(restartableId); if (subscription != null) subscription.unsubscribe(); } /** - * Checks if a restartable is started. + * Checks if a restartable is subscribed. * * @param restartableId id of a restartable. - * @return True if the restartable is started, false otherwise. + * @return True if the restartable is subscribed, false otherwise. */ - public boolean isStarted(int restartableId) { - return requested.contains(restartableId); + public boolean isSubscribed(int restartableId) { + Subscription s = restartableSubscriptions.get(restartableId); + return s != null && !s.isUnsubscribed(); } /** @@ -129,14 +130,14 @@ public class RxPresenter extends Presenter { * @param the type of the observable. */ public void restartableFirst(int restartableId, final Func0> observableFactory, - final Action2 onNext, @Nullable final Action2 onError) { + final Action2 onNext, @Nullable final Action2 onError) { restartable(restartableId, new Func0() { @Override public Subscription call() { return observableFactory.call() - .compose(RxPresenter.this.deliverFirst()) - .subscribe(split(onNext, onError)); + .compose(RxPresenter.this.deliverFirst()) + .subscribe(split(onNext, onError)); } }); } @@ -161,14 +162,14 @@ public class RxPresenter extends Presenter { * @param the type of the observable. */ public void restartableLatestCache(int restartableId, final Func0> observableFactory, - final Action2 onNext, @Nullable final Action2 onError) { + final Action2 onNext, @Nullable final Action2 onError) { restartable(restartableId, new Func0() { @Override public Subscription call() { return observableFactory.call() - .compose(RxPresenter.this.deliverLatestCache()) - .subscribe(split(onNext, onError)); + .compose(RxPresenter.this.deliverLatestCache()) + .subscribe(split(onNext, onError)); } }); } @@ -193,14 +194,14 @@ public class RxPresenter extends Presenter { * @param the type of the observable. */ public void restartableReplay(int restartableId, final Func0> observableFactory, - final Action2 onNext, @Nullable final Action2 onError) { + final Action2 onNext, @Nullable final Action2 onError) { restartable(restartableId, new Func0() { @Override public Subscription call() { return observableFactory.call() - .compose(RxPresenter.this.deliverReplay()) - .subscribe(split(onNext, onError)); + .compose(RxPresenter.this.deliverReplay()) + .subscribe(split(onNext, onError)); } }); } @@ -329,4 +330,14 @@ public class RxPresenter extends Presenter { protected void onDropView() { views.onNext(null); } + + /** + * Please, use restartableXX and deliverXX methods for pushing data from RxPresenter into View. + */ + @Deprecated + @Nullable + @Override + public View getView() { + return super.getView(); + } } 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 093e2144f9..069a4f3277 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 @@ -92,7 +92,7 @@ public class ChaptersPresenter extends BasePresenter { public void onEventMainThread(Manga manga) { this.manga = manga; - if (!isStarted(DB_CHAPTERS)) { + if (!isSubscribed(DB_CHAPTERS)) { source = sourceManager.get(manga.source); start(DB_CHAPTERS); diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java index a3c86b99e6..78f5fc88c6 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java @@ -319,7 +319,7 @@ public class ReaderPresenter extends BasePresenter { } private void stopPreloadingNextChapter() { - if (isStarted(PRELOAD_NEXT_CHAPTER)) { + if (isSubscribed(PRELOAD_NEXT_CHAPTER)) { stop(PRELOAD_NEXT_CHAPTER); if (nextChapterPageList != null) source.savePageList(nextChapter.url, nextChapterPageList);