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

Allow default layout res to be specified in class annotation #109

Merged
merged 3 commits into from
Feb 6, 2017

Conversation

elihart
Copy link
Contributor

@elihart elihart commented Feb 5, 2017

This lets us get rid of even more boilerplate by not writing the getDefaultLayout method in models.

@elihart
Copy link
Contributor Author

elihart commented Feb 5, 2017

@elihart elihart force-pushed the eli/generate_default_layout branch from d1afdf5 to 3396066 Compare February 5, 2017 23:57
", addedToAdapter=" + addedToAdapter +
'}';
return getClass().getSimpleName() + "{"
+ "id=" + id
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this the correct Airbnb java open source formatting? I can start using this in Lottie if that's the case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is the formatting I got from Felipe. Although I think I may have changed a few things to my preference. In general we should follow the google java style guide.

* A layout resource that should be used as the default layout for the model. If you set this you
* don't have to implement `getDefaultLayout`; it will be generated for you.
*/
@LayoutRes int value() default 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to have this be a named annotation property but also be the default?
So, you could do:
@EpoxyModelClass(R.layout.hello_world)
or
@EpoxyModelClass(layoutRes=R.layout.hello_world, futureProperty=true)
?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No unfortunately :( If you want to omit the parameter name it has to be called value http://stackoverflow.com/questions/11786354/how-i-can-do-java-annotation-like-nameluke-with-no-attribute-inside-parenth

Copy link
Collaborator

Choose a reason for hiding this comment

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

@elihart what would it look like in the future if you want to add more parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, the easy option would be @EpoxyModelClass(value=R.layout.hello_world, futureProperty=true) which isn't great.

The other option is to rename the param from value to layoutRes in the future if we other params. That'd be a breaking change we'd have to force on people. Not too bad to upgrade if we provide a structural replace pattern, but also not great.

Another option is to create a whole new annotation. That could work depending on what the goal of the feature is.

Or we just do @EpoxyModelClass(layoutRes=R.layout.hello_world) now in the anticipation of adding future params.

That last option is the safest. It's not terrible to require the param name, but it would be a bit annoying. I supposed the param name would make the purpose clearer.

Thanks for bringing this up, hadn't considered it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@elihart Personally I'm a fan because it's the most explicit and is future proof. Luckily IntelliJ should be able to autocomplete the name as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think you're right. I'll change it. Thanks!

@elihart elihart force-pushed the eli/generate_default_layout branch from 3396066 to f4e387b Compare February 6, 2017 05:44
Copy link
Contributor

@geralt-encore geralt-encore left a comment

Choose a reason for hiding this comment

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

Good stuff!
Btw, code looks much cleaner with ProcessorUtils

@elihart elihart merged commit 30111df into master Feb 6, 2017
@elihart elihart deleted the eli/generate_default_layout branch February 6, 2017 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants