📜 ⬆️ ⬇️

MVC for android

I believe that the job of a programmer is not to write code, but to optimize processes. We write code so that its user can quickly and efficiently achieve world domination, for example. And it would be a bit strange to optimize the work of others and not to optimize one’s own. A shoemaker without boots is irrational.

So. I recently began to write the second version of my app for the same religious fanatics like me. APP is not important, it is important that two-way binding of widgets to data is a rather routine, fraught with copyright work. It becomes especially fun if there are dependencies: If this text has changed - update one. Already on the second screen, being inspired by the Butter Knife project, I realized that there is a huge scope for generalization (and, oddly enough, I did not find anything like it).

Meet the project Bandera *
')


(I copy the example code for myself)



That is, the routine went to the library. The logic is rendered in the ViewModel (I know, this is not quite MVC, but rather MV-C). Everyone is happy.

The project is written pragmatically to fit your needs, so only TextView, EditText, DateTimePicker, ProgressBar, ImageView, ImageButton (picture) are supported so far. For events, I use the same Butter Knife.

Well, the special charm is that the binding code is generated when compiling **, that is, there are simply no traditional android fears annotations-runtime-reflection-slow-as-hell.

* Word consonant Binding and Android
** I’m not at all pleased with the way I generate this code, but for now Everything works and we will do it nicely later

Source: https://habr.com/ru/post/190072/


All Articles