I have a fairly complex feature I want to implement reactively. Whether this feature is enabled depends on the following
- User preference for this feature has been enabled (user can toggle this feature on or off)
- Activity is started (
Activity#onStart()
). If you aren't familiar with Android, this is just means the view is visible to the user.
Here are the following observables I already have.
Observable<Boolean>
- a user preference for whether this feature is enabled.true
if enabled,false
if disabled.Observable<LifeCycleEvent>
-LifeCycleEvent
is an enum that relates to Android's activity lifecycle.Observable<Void>
andObservable<Void>
, when subscribed to, kick off a process intensive task to enable my feature.. These two observables need to be- subscribed to when #2 emits an event that
LifeCycleEvent#isStarted()
returnstrue
and #1 emitstrue
(user enabled feature) - unsubscribed to when #2 emits an event that
LifeCycleEvent#isStarted()
returnsfalse
- unsubscribed to when #2 emits an event that
LifeCycleEvent#isDestoryed()
returnstrue
. I will also need to unsubscribe from #1 and #2 here because that means this class is ready for garbage collection. - unsubscribed from when #1 emits
false
(user did not enabled this feature)
- subscribed to when #2 emits an event that
How can I best do this? I have a single class that will take the above mentioned dependencies and a single method called void startObserving()
that will kick the observation process off (and be called once for the lifetime of this instance. I think I will need to somehow maintain two subscriptions (one for #1 & #2, and another for #3).