The GenericAdapter is a flexible and reusable Android RecyclerView adapter that simplifies the process of creating adapters for various data types. It offers ViewBinding integration, efficient data updates with DiffUtil, and filtering support.
- Flexibility: Create RecyclerView adapters for different data types with ease.
- ViewBinding Integration: Utilize ViewBinding for type-safe and efficient view management.
- Efficient Data Updates: Benefit from DiffUtil integration for optimized data updates and animations.
- Filtering Support: Easily add filtering functionality to your adapters.
- Customizable: Customize your adapters by defining your own data binding logic and layouts.
-
Extend the
GenericAdapter
class: Create your custom adapter by extendingGenericAdapter
. Implement the required methods, includingonBindData
andcreateViewBinding
, to specify how your data is displayed. -
Integrate ViewBinding: Utilize ViewBinding to bind your layout's views efficiently.
-
Submit Data: Use
submitFilterableList
to submit your data to the adapter. The data will be automatically filtered when needed. -
Filtering: Access the
filter
property to perform filtering operations on your data.
// Example usage:
val adapter = MyAdapter(MyDiffCallback())
adapter.submitFilterableList(dataList)
adapter.filter.filter("searchQuery")
Here's an example of how to create an adapter using the GenericAdapter
:
class MyAdapter(diffUtil: DiffUtil.ItemCallback<MyData>) :
GenericAdapter<MyData, MyItemBinding>(diffUtil) {
override val filter: Filter
get() = MyFilter()
override fun createViewBinding(
inflater: LayoutInflater,
parent: ViewGroup
): MyItemBinding {
return MyItemBinding.inflate(inflater, parent, false)
}
override fun onBindData(binding: MyItemBinding, item: MyData) {
// Bind your data to the ViewBinding here
// Example: binding.textView.text = item.name
}
}
Contributions, issues, and feature requests are welcome! Feel free to open a pull request or create an issue if you have any suggestions or improvements.
This project is licensed under the MIT License - see the LICENSE file for details.
© 2023 Bishal Adhikari. All rights reserved.
This project is licensed under the MIT License - see the LICENSE file for details.
Feel free to customize this README.md
with more specific information about your project, including installation instructions, advanced usage examples, and license details.