I'm trying to make room entity observable (extend BaseObservable) so it could be used in LiveData with bi-directional binding. So I have this data class:
@Entity
data class Model(
@PrimaryKey(autoGenerate = true)
val id: Int,
val name: String) : Serializable
and in XML I want to use it like this:
<EditText
...
android:text="@{viewModel.myLiveData.name}"
and in the ViewModel I have:
val myLiveData: MutableLiveData<Model>
I've found basically the same question here.. but for JAVA, and I'm having issues converting it into kotlin. My kotlin equivalent is:
@Entity
class Model: BaseObservable, Serializable {
constructor(id: Int, name: String) {
this.id = id
this.name = name
}
@PrimaryKey(autoGenerate = true)
var id: Int = 0
@get:Bindable
var name: String = ""
set(value) {
field = value
notifyChange()
}
}
which doesn't work and causes:
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
> java.lang.reflect.InvocationTargetException (no error message)