Skip to content
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

Merged
merged 19 commits into from
Oct 1, 2017
Merged

Sample app! #97

merged 19 commits into from
Oct 1, 2017

Conversation

ZacSweers
Copy link
Collaborator

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.

Copy link
Contributor

@0legg 0legg left a 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) {
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Collaborator Author

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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnBind

Copy link
Collaborator Author

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 ->
Copy link
Contributor

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

Copy link
Collaborator Author

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 ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Copy link
Collaborator Author

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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Candidate for laziness

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?.

Copy link
Collaborator Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?.

Copy link
Collaborator Author

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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?.

Copy link
Collaborator Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@0legg 0legg left a 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.

@ZacSweers ZacSweers merged commit f9874af into master Oct 1, 2017
@ZacSweers ZacSweers deleted the z/sample branch October 1, 2017 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants