Library to make your coding easy when create adapter
| EasyAdapter | |
|---|---|
| ViewBinding Support | ✅ |
| 100% Kotlin | ✅ |
| Compose Like Adapter | ✅ |
| Indexed Adapter | ✅ |
| Multi Easy Adapter | ✅ |
| Give Initial to Adapter | ✅ |
| Easy to use | ✅ |
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}dependencies {
implementation 'com.github.derysudrajat:EasyAdapter:2.0.0'
}you just need to put your listOfData into EasyAdapter object along with your ItemLayoutBinding that call ::inflate function 😎
binding.rvMain.adapter = EasyAdapter(listOfData, ItemDataBinding::inflate) { binding, data ->
binding.tvName.text = data.name
binding.tvId.text = data.id
// ... other awesome code
}yes finally you can use EasyAdapterIndexed if you want an index of the data when it onBind 😎
binding.rvMain.adapter = EasyAdapterIndexed(listOfData, ItemDataBinding::inflate) { binding, data, index ->
// .. your awesome code here
}Here we go to provide multiple views on EasyAdapter now you can do it with MultipleEasyAdapter 🔥
- you can use
itemfor single data likeseparatorortitle - or you can use
itemsfor multiple data like the usualEasyAdapter
multipleAdapter = MultipleEasyAdapter {
item("List with Items", ItemTextBinding::inflate) { binding, data ->
binding.root.text = data
}
items(listOne, ItemDataBinding::inflate) { binding, data ->
binding.tvName.text = data.name
binding.tvId.text = data.id
}
item("List with ItemsIndexed", ItemTextBinding::inflate) { binding, data ->
binding.root.text = data
}
itemsIndexed(listTwo, ItemDataBinding::inflate) { binding, data, index ->
binding.tvName.text = buildString {
append("This item number-${index + 1}: ${data.name}")
}
binding.tvId.text = data.id
}
}if you wondering to using the existing EasyAdapter intoMultipleEasyAdapter it's possible? yes absolutely possible 😎
- you can use
addAdapter(yourEasyDapter)intoMultipleEasyAdapter
multipleAdapter = MultipleEasyAdapter {
item("List with addAdapter", ItemTextBinding::inflate) { binding, data ->
binding.root.text = data
}
addAdapter(adapter)
item("List with addAdapter Indexed", ItemTextBinding::inflate) { binding, data ->
binding.root.text = data
}
addAdapter(adapterIndexed)
}yes if you using multiple adapter and want to using different data you can initial your adapter first just like this ✨
private var adapter = EasyAdapter.init<Data, ItemDataBinding>(ItemDataBinding::inflate)
private var adapterIndexed = EasyAdapterIndexed.init<Data, ItemDataBinding>(ItemDataBinding::inflate)finally you can attach theMultipleEasyAdapter using .assemble() like this, ya you know it means you assemble all the adapter 😎
binding.rvMain.adapter = multipleAdapter.assemble()Enjoy the library, give me star ⭐️ if you like this library, ciaao 😎✨
