General Adapter for single ViewType cases.
With setup of Jitpack first, than add dependency in your build.gradle
implementation 'com.github.carousell:MonoAdapter:2.0.0'
- With ViewBinding: You can easily declare the ViewBinding type and the data type, and then provide how to bind data with the binding object like below.
val adapter = MonoAdapter.create<AdapterMyDataBinding, MyData>(AdapterMyDataBinding::inflate) {
textView.text = it.text1
button.setOnClickListener {
textView.text = it.text2
}
}
- Without ViewBinding: ViewBinding is preferred but not necessary, you can pass the layout directly and then bind the View and data in the lambda like below example.
val adapter = MonoAdapter.create<MyData>(R.layout.adapter_sample) { view, data ->
val textView = view.findViewById<TextView>(R.id.text)
textView.text = data.text1
view.findViewById(R.id.button).setOnClickListener {
textView.text = data.text2
}
}
p.s. You can also pass the DiffUtil.ItemCallback
into each adapter create function to identify how to do the diff check for your data. MonoAdapter will otherwise compare the data as a whole if you didn't specified.
Go to ./app module for more information.
Thank you for being interested in contributing to this project. Check out the CONTRIBUTING document for more info.
MonoAdapter is created and maintained by Carousell. Help us improve this project! We'd love the feedback from you.
We're hiring! Find out more at http://careers.carousell.com/
MonoAdapter is released under Apache License 2.0. See LICENSE for more details.