Epoxy: Custom view model generated name

Created on 3 Feb 2018  路  7Comments  路  Source: airbnb/epoxy

Is possibile to change the generated name of an automodel custom view? I would like to remove the "Model" suffix because i use a mvvm pattern and there would be a sort of name confusion.

enhancement help wanted

Most helpful comment

I am pushing the 2.10.0 release with this change right now. I also updated the wiki to reflect this option.

Thanks everyone!

All 7 comments

Not currently possible, but it would be possible to add this customization. I can see the usefulness.

If anyone wants to work on it I can point them in the right direction :)

@elihart I can look into it. I am not that familiar with custom views implementation, but I am sure if you point me in the right direction I will be able to tackle it =)

@geralt-encore that would be great!

The general approach I am thinking of is

  • Change PackageModelViewConfig to have a setting for generated model suffix (default being "Model_`"
  • Update PackageModelViewSettings to store this data
  • Add a method to ConfigManager that takes a GeneratedModelInfo and returns the model suffix (see ConfigManager#requiresHashCode for an example)
  • Look up usages of GeneratedModelInfo#GENERATED_MODEL_SUFFIX and replace static usages with something that looks up the suffix via the config manager
  • Look at tests like ViewProcessorTest#baseModelFromPackageConfig for examples on how to test the configuration

Thanks for the heads-up!
I am digging into ConfigManager and seems like PackageModelViewSettings can be used only for ModelViewInfo configs and not for general GeneratedModelInfo. Am I missing something?

Yeah you're right, I was kind of figuring that models created in other ways would still fall back to the default suffix. I just realized though that the suffix needs to be looked up in the constructor of ModelViewInfo, so the ConfigManager method should take the val viewElement: TypeElement of the ModelViewInfo and return the package name.

We could take a similar approach with the EpoxyDataBindingLayouts annotation to change the suffix of databinding generated models

Will be included in next release. Thanks @geralt-encore !

I am pushing the 2.10.0 release with this change right now. I also updated the wiki to reflect this option.

Thanks everyone!

Was this page helpful?
0 / 5 - 0 ratings