4.1.0: Kotlin DSL
Added a Kotlin DSL to create AdapterDelegates through a fluend DSL. There are actually 2 DSL artifacts:
- adapterdelegates4-kotlin-dsl:
fun catAdapterDelegate(itemClickedListener : (Cat) -> Unit) = adapterDelegate<Cat, Animal>(R.layout.item_cat) {
val name : TextView = findViewById(R.id.name)
name.setClickListener { itemClickedListener(item) }
bind {
name.text = item.name
}
}
- adapterdelegates4-kotlin-dsl-layoutcontainer:
Pretty much the same asadapterDelegate
but uses kotlin android extension'sLayoutContainer
and the generated synthetic properties. Thus, you dont have to write anyfindViewById()
.
fun catAdapterDelegate(itemClickedListener : (Cat) -> Unit) = adapterDelegateLayoutContainer<Cat, Animal>(R.layout.item_cat) {
name.setClickListener { itemClickedListener(item) } // name is imported from kotlinx.android.synthetic.main.item_cat.name
bind {
name.text = item.name
}
}
Read the README for more details how to use it.