-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sample app! #97
Sample app! #97
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, it's fine but needs some polish and few comments explaining what's up
private static Function<ActivityEvent, ActivityEvent> CORRESPONDING_EVENTS = | ||
new Function<ActivityEvent, ActivityEvent>() { | ||
@Override public ActivityEvent apply(ActivityEvent activityEvent) throws Exception { | ||
switch (activityEvent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd split these events into two separate sequences, so it'll be easier to understand, why startup methods have symmetric shutdown ones as a counterpart, while shutdown methods are having sequential shutdown ones.
implements LifecycleScopeProvider<AutoDisposeFragment.FragmentEvent> { | ||
|
||
public enum FragmentEvent { | ||
ATTACH, CREATE, CREATE_VIEW, START, RESUME, PAUSE, STOP, DESTROY_VIEW, DESTROY, DETACH |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same issue stays here — for fragments it's even harder to well-understand this small FSM mechanism.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does FSM mechanism mean? 👀
unbindNotifier = null; | ||
} | ||
|
||
private void emitUnBindIfPresent() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UnBind
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
companion object { | ||
|
||
private val CORRESPONDING_EVENTS = Function<ActivityEvent, ActivityEvent> { activityEvent -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can omit Function<ActivityEvent, ActivityEvent>
part without decrease in readability
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talked - can't do this because the compiler won't allow it
|
||
companion object { | ||
|
||
private val CORRESPONDING_EVENTS = Function<FragmentEvent, FragmentEvent> { event -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talked - can't do this because the compiler won't allow it
|
||
private var unbindNotifier: MaybeSubject<Any>? = null | ||
|
||
private val notifier: MaybeSubject<Any> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Candidate for laziness
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oop actually no I just removed this entirely
override fun onAttachedToWindow() { | ||
super.onAttachedToWindow() | ||
if (lifecycleEvents != null) { | ||
lifecycleEvents!!.onNext(ViewEvent.ATTACH) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
override fun onDetachedFromWindow() { | ||
super.onDetachedFromWindow() | ||
if (lifecycleEvents != null) { | ||
lifecycleEvents!!.onNext(ViewEvent.DETACH) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
|
||
override fun lifecycle(): Observable<ViewEvent> { | ||
return lifecycleEvents!!.hide() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
|
||
override fun peekLifecycle(): ViewEvent? { | ||
return lifecycleEvents!!.value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic behind corresponding events still can be unclear at a first sight. In general — LGTM.
This has come up a few times, so I think it's time to have a proper sample rather than just relying on tests to demonstrate usage.
Gist of it is that I added a demo app (doesn't do much but is borrowed heavily from RxLifecycle/Conductor's) + recipes for common cases.