#10 ~ Universal Adapter for Android

Universal Adapter Android

The most boilerplate piece in developing application in Android is create a List UI Component.

To implement List UI Component we have few ceremonies such as:
1. Create a List widget (in this case RecycleView)
2. Create a Adapter
3. Create a ViewHolder
4. Create a List Item widget for ViewHolder

Doing a repetitive code is not DRY at all. We wasting time to create such things. In that time, i was thinking how to reduce amount of class in doing create List UI Component. No more jump around and create N-adapters.

Thanks to kotlin that had great features. I can create base adapter by using a kotlin high order function. Kotlin had a great features to implements good code, like extension function, lambda with receivers, variance, DSL, couroutine, high order function, and etc.

Above is snippet of UniversalAdapter.

In first argument we provide high order function that take ViewGroup and Int parameters which return Generic ViewHolder (VH). ViewGroup is a parent of view, and Int is a viewType.

In second argument we provide VH from first argument, Int is a position, and T are the object of item adapter.

In Third argument we provide implementation of ViewType which take position and return a viewType. This Third argument is optional, you can left this argument by not implementing {}.

Use Case

Universal Adapter has six functions that can modified listof<T>().

This library also available through maven and jcenter. Thanks!


repositories {

implementation 'com.radityalabs.universaladapter:universal-adapter:1.0.0'


repositories {
maven {
url 'https://dl.bintray.com/radityagumay/android/'
implementation 'com.radityalabs.universaladapter:universal-adapter:1.0.0@aar'

Also check readme in my github https://github.com/radityagumay/universal-adapter/blob/master/README.md