avast / android-butterknife-zelezny

Android Studio plug-in for generating ButterKnife injections from selected layout XML.
Apache License 2.0
3.38k stars 412 forks source link

Add options about auto-generation of inject code for Activity and Fragment #123

Open bruce3x opened 7 years ago

bruce3x commented 7 years ago

Add two options in plugin's setting screen, about auto-generation of inject code for Activity and Fragment.

bruce3x commented 7 years ago

image

bruce3x commented 7 years ago

Hi @TomasKypta ,this can solve issues: #108 #100 #91 #68

siempredelao commented 7 years ago

Hi @brucezz, if you read those issues carefully, the problem is that we have a superclass where we already bind the views and we want to avoid auto-generating that code in inherited classes.

Check those explanations:

...because I do bind my views in my parent class.

The onCreateView method is overridden by the plugin even if binding ButterKnife from a base class.

The general way I use is that do ButterKnife.bind(this); in BaseActivity...

Usually I've some BaseActivity and/or BaseFragment... ...but the plugin does not play well with Butterknife binding as superclass-made behavior.

The solution you provide here avoids auto-generating code as soon as the user checks those CheckBox's, even if it is needed.

bruce3x commented 7 years ago

Hi @siempredelao , thanks for reply.

In my application, I use ButterKnife.bind(this) in BaseActivity#onCreate(), so I no longer need to write it in the subclass in most cases. It means that the plugin shouldn't generate the inject code in my subclasses. Then I add two options into the Preferences which can turn off auto-generation of inject code.

My solution is a tricky way to avoid auto-generation of inject code in inherited classes. :)