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

Custom view model generated name #398

Closed
FunnyDevs opened this issue Feb 3, 2018 · 7 comments
Closed

Custom view model generated name #398

FunnyDevs opened this issue Feb 3, 2018 · 7 comments

Comments

@FunnyDevs
Copy link

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.

@elihart
Copy link
Contributor

elihart commented Feb 3, 2018

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 :)

@geralt-encore
Copy link
Contributor

@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 =)

@elihart
Copy link
Contributor

elihart commented Feb 12, 2018

@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

@geralt-encore
Copy link
Contributor

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?

@elihart
Copy link
Contributor

elihart commented Feb 13, 2018

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

@elihart
Copy link
Contributor

elihart commented Feb 15, 2018

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

@elihart
Copy link
Contributor

elihart commented Feb 25, 2018

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

Thanks everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants