More crash fixes

This commit is contained in:
len
2016-04-06 02:18:04 +02:00
parent d8ac35d259
commit a598ebf72f
13 changed files with 147 additions and 164 deletions
@@ -12,7 +12,7 @@ import nucleus.view.PresenterLifecycleDelegate;
import nucleus.view.ViewWithPresenter;
/**
* This class is an example of how an activity could controls it's presenter.
* This view is an example of how a view should control it's presenter.
* You can inherit from this class or copy/paste this class's code to
* create your own view implementation.
*
@@ -87,12 +87,11 @@ public abstract class BaseRxFragment<P extends Presenter> extends BaseFragment i
@Override
public void onPause() {
super.onPause();
presenterDelegate.onPause(getActivity().isFinishing() || shouldDestroyPresenter(this));
presenterDelegate.onPause(getActivity().isFinishing() || isRemoving(this));
}
private boolean shouldDestroyPresenter(Fragment fragment) {
if (fragment == null) return false;
else return fragment.isRemoving() || shouldDestroyPresenter(fragment.getParentFragment());
private static boolean isRemoving(Fragment fragment) {
Fragment parent = fragment.getParentFragment();
return fragment.isRemoving() || (parent != null && isRemoving(parent));
}
}
}
@@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.base.presenter
import android.content.Context
import nucleus.view.ViewWithPresenter
import org.greenrobot.eventbus.EventBus
import rx.Observable
open class BasePresenter<V : ViewWithPresenter<*>> : RxPresenter<V>() {
@@ -16,4 +17,13 @@ open class BasePresenter<V : ViewWithPresenter<*>> : RxPresenter<V>() {
EventBus.getDefault().unregister(this)
}
fun <T> Observable<T>.subscribeFirst(onNext: (V, T) -> Unit, onError: ((V, Throwable) -> Unit)? = null)
= compose(deliverFirst<T>()).subscribe(split(onNext, onError))
fun <T> Observable<T>.subscribeLatestCache(onNext: (V, T) -> Unit, onError: ((V, Throwable) -> Unit)? = null)
= compose(deliverLatestCache<T>()).subscribe(split(onNext, onError))
fun <T> Observable<T>.subscribeReplay(onNext: (V, T) -> Unit, onError: ((V, Throwable) -> Unit)? = null)
= compose(deliverReplay<T>()).subscribe(split(onNext, onError))
}