cleaning up some explicit signatures and fixing nullability lifecycle peeking

This commit is contained in:
tys
2023-03-27 11:06:30 -07:00
parent 73ae40ab32
commit 93dd6e8d8b
5 changed files with 13 additions and 8 deletions
@@ -37,6 +37,7 @@ import com.uber.rib.core.lifecycle.ActivityLifecycleEvent
import com.uber.rib.core.lifecycle.ActivityLifecycleEvent.Companion.create
import com.uber.rib.core.lifecycle.ActivityLifecycleEvent.Companion.createOnCreateEvent
import io.reactivex.CompletableSource
import io.reactivex.Observable
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.rx2.asObservable
@@ -50,17 +51,17 @@ abstract class RibActivity : CoreAppCompatActivity(), ActivityStarter, Lifecycle
private val callbacksObservable = callbacksFlow.asObservable()
/** @return an observable of this activity's lifecycle events. */
override fun lifecycle() = lifecycleObservable
override fun lifecycle(): Observable<ActivityLifecycleEvent> = lifecycleObservable
/** @return an observable of this activity's lifecycle events. */
override fun callbacks() = callbacksObservable
override fun callbacks(): Observable<ActivityCallbackEvent> = callbacksObservable
override fun correspondingEvents(): CorrespondingEventsFunction<ActivityLifecycleEvent> {
return ACTIVITY_LIFECYCLE
}
override fun peekLifecycle(): ActivityLifecycleEvent {
return lifecycleFlow.replayCache.last()
override fun peekLifecycle(): ActivityLifecycleEvent? {
return lifecycleFlow.replayCache.lastOrNull()
}
override fun requestScope(): CompletableSource {
@@ -23,6 +23,7 @@ import com.uber.autodispose.lifecycle.LifecycleScopeProvider
import com.uber.autodispose.lifecycle.LifecycleScopes
import com.uber.rib.core.lifecycle.InteractorEvent
import io.reactivex.CompletableSource
import io.reactivex.Observable
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.rx2.asObservable
@@ -55,7 +56,7 @@ abstract class Interactor<P : Any, R : Router<*>> : LifecycleScopeProvider<Inter
}
/** @return an observable of this controller's lifecycle events. */
override fun lifecycle() = lifecycleObservable
override fun lifecycle(): Observable<InteractorEvent> = lifecycleObservable
/** @return true if the controller is attached, false if not. */
override fun isAttached() = lifecycleFlow.replayCache.last() == InteractorEvent.ACTIVE
@@ -139,7 +140,7 @@ abstract class Interactor<P : Any, R : Router<*>> : LifecycleScopeProvider<Inter
}
override fun peekLifecycle(): InteractorEvent? {
return lifecycleFlow.replayCache.last()
return lifecycleFlow.replayCache.lastOrNull()
}
final override fun requestScope(): CompletableSource {
@@ -19,6 +19,7 @@ import androidx.annotation.CallSuper
import com.uber.autodispose.ScopeProvider
import com.uber.rib.core.lifecycle.PresenterEvent
import io.reactivex.CompletableSource
import io.reactivex.Observable
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow
@@ -70,7 +71,7 @@ abstract class Presenter : ScopeProvider {
}
/** @return an observable of this controller's lifecycle events. */
open fun lifecycle() = lifecycleObservable
open fun lifecycle(): Observable<PresenterEvent> = lifecycleObservable
override fun requestScope(): CompletableSource {
return rxCompletable(Dispatchers.Unconfined) { lifecycleFlow.take(2).collect() }
@@ -102,6 +102,7 @@ class InteractorAndRouterTest {
}
val router = TestRouterA(parentInteractor, component)
val parentObserver = RecordingObserver<InteractorEvent>()
parentInteractor.lifecycle()
parentInteractor.lifecycle().subscribe(parentObserver)
router.dispatchAttach(null)
Truth.assertThat(parentObserver.takeNext()).isEqualTo(InteractorEvent.ACTIVE)
@@ -15,6 +15,7 @@
*/
package com.uber.rib.core
import io.reactivex.Observable
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.rx2.asObservable
@@ -25,7 +26,7 @@ class RouterNavigatorEvents private constructor() {
private val _events = MutableSharedFlow<RouterNavigatorEvent>(0, 1, BufferOverflow.DROP_OLDEST)
/** @return the stream which can be subcribed to listen for [RouterNavigatorEvent] */
val events = _events.asObservable()
val events: Observable<RouterNavigatorEvent> = _events.asObservable()
/**
* Emits a new [RouterNavigatorEvent] on the stream.