mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 11:21:49 +01:00
Merge changes from Nucleus presenter
This commit is contained in:
parent
50d6632d0e
commit
80a59548a5
@ -100,20 +100,21 @@ public class RxPresenter<View> extends Presenter<View> {
|
|||||||
* @param restartableId id of a restartable.
|
* @param restartableId id of a restartable.
|
||||||
*/
|
*/
|
||||||
public void stop(int restartableId) {
|
public void stop(int restartableId) {
|
||||||
requested.remove((Integer)restartableId);
|
requested.remove((Integer) restartableId);
|
||||||
Subscription subscription = restartableSubscriptions.get(restartableId);
|
Subscription subscription = restartableSubscriptions.get(restartableId);
|
||||||
if (subscription != null)
|
if (subscription != null)
|
||||||
subscription.unsubscribe();
|
subscription.unsubscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a restartable is started.
|
* Checks if a restartable is subscribed.
|
||||||
*
|
*
|
||||||
* @param restartableId id of a restartable.
|
* @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) {
|
public boolean isSubscribed(int restartableId) {
|
||||||
return requested.contains(restartableId);
|
Subscription s = restartableSubscriptions.get(restartableId);
|
||||||
|
return s != null && !s.isUnsubscribed();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -129,14 +130,14 @@ public class RxPresenter<View> extends Presenter<View> {
|
|||||||
* @param <T> the type of the observable.
|
* @param <T> the type of the observable.
|
||||||
*/
|
*/
|
||||||
public <T> void restartableFirst(int restartableId, final Func0<Observable<T>> observableFactory,
|
public <T> void restartableFirst(int restartableId, final Func0<Observable<T>> observableFactory,
|
||||||
final Action2<View, T> onNext, @Nullable final Action2<View, Throwable> onError) {
|
final Action2<View, T> onNext, @Nullable final Action2<View, Throwable> onError) {
|
||||||
|
|
||||||
restartable(restartableId, new Func0<Subscription>() {
|
restartable(restartableId, new Func0<Subscription>() {
|
||||||
@Override
|
@Override
|
||||||
public Subscription call() {
|
public Subscription call() {
|
||||||
return observableFactory.call()
|
return observableFactory.call()
|
||||||
.compose(RxPresenter.this.<T>deliverFirst())
|
.compose(RxPresenter.this.<T>deliverFirst())
|
||||||
.subscribe(split(onNext, onError));
|
.subscribe(split(onNext, onError));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -161,14 +162,14 @@ public class RxPresenter<View> extends Presenter<View> {
|
|||||||
* @param <T> the type of the observable.
|
* @param <T> the type of the observable.
|
||||||
*/
|
*/
|
||||||
public <T> void restartableLatestCache(int restartableId, final Func0<Observable<T>> observableFactory,
|
public <T> void restartableLatestCache(int restartableId, final Func0<Observable<T>> observableFactory,
|
||||||
final Action2<View, T> onNext, @Nullable final Action2<View, Throwable> onError) {
|
final Action2<View, T> onNext, @Nullable final Action2<View, Throwable> onError) {
|
||||||
|
|
||||||
restartable(restartableId, new Func0<Subscription>() {
|
restartable(restartableId, new Func0<Subscription>() {
|
||||||
@Override
|
@Override
|
||||||
public Subscription call() {
|
public Subscription call() {
|
||||||
return observableFactory.call()
|
return observableFactory.call()
|
||||||
.compose(RxPresenter.this.<T>deliverLatestCache())
|
.compose(RxPresenter.this.<T>deliverLatestCache())
|
||||||
.subscribe(split(onNext, onError));
|
.subscribe(split(onNext, onError));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -193,14 +194,14 @@ public class RxPresenter<View> extends Presenter<View> {
|
|||||||
* @param <T> the type of the observable.
|
* @param <T> the type of the observable.
|
||||||
*/
|
*/
|
||||||
public <T> void restartableReplay(int restartableId, final Func0<Observable<T>> observableFactory,
|
public <T> void restartableReplay(int restartableId, final Func0<Observable<T>> observableFactory,
|
||||||
final Action2<View, T> onNext, @Nullable final Action2<View, Throwable> onError) {
|
final Action2<View, T> onNext, @Nullable final Action2<View, Throwable> onError) {
|
||||||
|
|
||||||
restartable(restartableId, new Func0<Subscription>() {
|
restartable(restartableId, new Func0<Subscription>() {
|
||||||
@Override
|
@Override
|
||||||
public Subscription call() {
|
public Subscription call() {
|
||||||
return observableFactory.call()
|
return observableFactory.call()
|
||||||
.compose(RxPresenter.this.<T>deliverReplay())
|
.compose(RxPresenter.this.<T>deliverReplay())
|
||||||
.subscribe(split(onNext, onError));
|
.subscribe(split(onNext, onError));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -329,4 +330,14 @@ public class RxPresenter<View> extends Presenter<View> {
|
|||||||
protected void onDropView() {
|
protected void onDropView() {
|
||||||
views.onNext(null);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
|
|||||||
public void onEventMainThread(Manga manga) {
|
public void onEventMainThread(Manga manga) {
|
||||||
this.manga = manga;
|
this.manga = manga;
|
||||||
|
|
||||||
if (!isStarted(DB_CHAPTERS)) {
|
if (!isSubscribed(DB_CHAPTERS)) {
|
||||||
source = sourceManager.get(manga.source);
|
source = sourceManager.get(manga.source);
|
||||||
start(DB_CHAPTERS);
|
start(DB_CHAPTERS);
|
||||||
|
|
||||||
|
@ -319,7 +319,7 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void stopPreloadingNextChapter() {
|
private void stopPreloadingNextChapter() {
|
||||||
if (isStarted(PRELOAD_NEXT_CHAPTER)) {
|
if (isSubscribed(PRELOAD_NEXT_CHAPTER)) {
|
||||||
stop(PRELOAD_NEXT_CHAPTER);
|
stop(PRELOAD_NEXT_CHAPTER);
|
||||||
if (nextChapterPageList != null)
|
if (nextChapterPageList != null)
|
||||||
source.savePageList(nextChapter.url, nextChapterPageList);
|
source.savePageList(nextChapter.url, nextChapterPageList);
|
||||||
|
Loading…
Reference in New Issue
Block a user