Add presenter subscriptions to the subscription list when using custom subscribe methods
This commit is contained in:
@@ -8,13 +8,34 @@ open class BasePresenter<V : ViewWithPresenter<*>> : RxPresenter<V>() {
|
||||
|
||||
lateinit var context: Context
|
||||
|
||||
/**
|
||||
* Subscribes an observable with [deliverFirst] and adds it to the presenter's lifecycle
|
||||
* subscription list.
|
||||
*
|
||||
* @param onNext function to execute when the observable emits an item.
|
||||
* @param onError function to execute when the observable throws an error.
|
||||
*/
|
||||
fun <T> Observable<T>.subscribeFirst(onNext: (V, T) -> Unit, onError: ((V, Throwable) -> Unit)? = null)
|
||||
= compose(deliverFirst<T>()).subscribe(split(onNext, onError))
|
||||
= compose(deliverFirst<T>()).subscribe(split(onNext, onError)).apply { add(this) }
|
||||
|
||||
/**
|
||||
* Subscribes an observable with [deliverLatestCache] and adds it to the presenter's lifecycle
|
||||
* subscription list.
|
||||
*
|
||||
* @param onNext function to execute when the observable emits an item.
|
||||
* @param onError function to execute when the observable throws an error.
|
||||
*/
|
||||
fun <T> Observable<T>.subscribeLatestCache(onNext: (V, T) -> Unit, onError: ((V, Throwable) -> Unit)? = null)
|
||||
= compose(deliverLatestCache<T>()).subscribe(split(onNext, onError))
|
||||
= compose(deliverLatestCache<T>()).subscribe(split(onNext, onError)).apply { add(this) }
|
||||
|
||||
/**
|
||||
* Subscribes an observable with [deliverReplay] and adds it to the presenter's lifecycle
|
||||
* subscription list.
|
||||
*
|
||||
* @param onNext function to execute when the observable emits an item.
|
||||
* @param onError function to execute when the observable throws an error.
|
||||
*/
|
||||
fun <T> Observable<T>.subscribeReplay(onNext: (V, T) -> Unit, onError: ((V, Throwable) -> Unit)? = null)
|
||||
= compose(deliverReplay<T>()).subscribe(split(onNext, onError))
|
||||
= compose(deliverReplay<T>()).subscribe(split(onNext, onError)).apply { add(this) }
|
||||
|
||||
}
|
||||
|
||||
@@ -113,7 +113,16 @@ public class RxPresenter<View> extends Presenter<View> {
|
||||
* @return true if the subscription is null or unsubscribed, false otherwise.
|
||||
*/
|
||||
public boolean isUnsubscribed(int restartableId) {
|
||||
Subscription subscription = restartableSubscriptions.get(restartableId);
|
||||
return isUnsubscribed(restartableSubscriptions.get(restartableId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a subscription is unsubscribed.
|
||||
*
|
||||
* @param subscription the subscription to check.
|
||||
* @return true if the subscription is null or unsubscribed, false otherwise.
|
||||
*/
|
||||
public boolean isUnsubscribed(@Nullable Subscription subscription) {
|
||||
return subscription == null || subscription.isUnsubscribed();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user