Kotlin Data Binding (KDB)

TL;DR
Android Data Binding is great, but it also comes with some problems mainly caused by code generation.
To try to fix those issues, I created my own library: no code generation, no code in your XML, just a few files using extension functions. If you are already using LiveData, you will be able to exchange Android Data Binding to KDB without having to change a single line of code inside your viewmodel .
Update
Updated to KDB library to AndroidX, also made several improvements in its usability, check out the new release 1.0.0
Android Data Binding library uses binding adapters to bind your XML files to your model class. This sounds like an easy way to write the application, since it decreases the amount of boilerplate code that you usually write. However, that’s not quite the case. As you can implement presentation logic in your XML file, the only way to actually test that code is to write Espresso tests and make sure your view have the state that you want.
Another problem is code generation. This comes with a high price, especially because of the way that Android deals with it: if one or more issues are detected when trying to generate the code, it stops and no code is generated. This causes havoc in your application: several included files cease to exist and suddenly you have several errors in your compilation. Believe me, it will take a while to find the single error that caused the build failure. Another problem with code generation is branch changes; this means a lot of cleans and wasted time for the full build.
Usually these are matters that you can live with if you are working on a smaller application. But, as your application grows, so does the build time, and the wasted time fixing issues becomes a serious burden.

To solve this issue I created my own Library in Kotlin that handles the binding using extension functions, generics and high orders functions. The main advantage is no code generation. This means faster builds, smaller APK and not wasting time searching for the error if you happened to use a Boolean LiveData instead of an Int one.
Adding to project
To use it just add the following to your app gradle file:
implementation 'com.psato.kdbcore:kdb:1.0.0'
Usage
There are two methods: the bind and the twoWayBind.
Bind
The bind method is an extension function for LiveData and it has one parameters:
- Block of code that receives the value
TwoWayBind
The twoWayBind method is also an extension function for LiveData and it takes one parameters:
- A TwoWayBinder of same type as the LiveData
TwoWayBinder
The TwoWayBinder is an abstract class that is necessary to perform a two way binding. It has 3 methods that should be implemented:
it has 3 methods that should be implemented:
- oneWayBind: A method that receives a parameter of the same type as the TwoWayBinder. Basically, it is the method that should be called when the values of the LiveData changes.
- observeField: This method receives a WeakReference with the MutableLiveData that will be passed on the twoWayBind method. In this method, you should observe the field that you want to bind (set/add your listener to the view and update the value inside the mutable live data).
- removeObserver: This method should remove any listener created on the ObserveField method. It avoids memory leak, and is an abstract method to make sure that the listener will be removed.
All the information for using and contributing is in the GitHub repository. You can send issues or submit a pull request at any time; I will answer back as soon as I can.