Skip to content

Library to create Recycle View without Adapter Class

License

Notifications You must be signed in to change notification settings

derysudrajat/EasyAdapter

Repository files navigation

EasyAdapter

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

Setup

1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

2. Add the dependency

dependencies {
    implementation 'com.github.derysudrajat:EasyAdapter:2.0.0'
}

How To Use

1. The new way to use EasyAdapter ⚡️

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
}

2. EasyAdapter with Indexed 🥳

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
}

3. Multi EasyAdapter

Here we go to provide multiple views on EasyAdapter now you can do it with MultipleEasyAdapter 🔥

  • you can use item for single data like separator or title
  • or you can use items for multiple data like the usual EasyAdapter
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
    }
}

4. Using Existing EasyAdapter in MultipleEasyAdapter

if you wondering to using the existing EasyAdapter intoMultipleEasyAdapter it's possible? yes absolutely possible 😎

  • you can use addAdapter(yourEasyDapter) into MultipleEasyAdapter
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)
}

5. You can initial your EasyAdapter

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)

6. Attach your MultipleEasyAdapter

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 😎✨