Skip to content

This is a play ground project of implementing adapter delegate in Android.

License

Notifications You must be signed in to change notification settings

sampingantech/adapter-delegate-playground

Repository files navigation


Adapter Delegate Playground

This is a play ground project of implementing adapter delegate in Android.

Table of Contents

About The Project

Playground Playstore
Playground Playstore

This project is a playground for anyone who want to try implementing adapter delegate. Adapter delegate is a technique that help us to create a heterogeneous RecyclerView. Instead of using viewType and if else technique in the adapter and ended creating a God Class, we can try implementing delegate technique in order to provide multiple views in a RecyclerView.

Favor composition over inheritance

Now look at this code:

class MainAdapter : ListDelegationAdapter<List<DisplayableItem>>(  
    bannerAdapterDelegate(),  
    campaignAdapterDelegate(),  
    featuredAdapterDelegate(),  
    promotionAdapterDelegate()  
)

This is an example when we implementing delegate technique in an adapter. As You can see, we can just add and remove the delegate adapter to add or remove the view as the requirements of our apps. It will make our adapter more clean and maintainable.

code of adapter delegate:

fun bannerAdapterDelegate() = adapterDelegateViewBinding<Banner, DisplayableItem, ItemBannerBinding>(  
    { layoutInflater, root -> ItemBannerBinding.inflate(layoutInflater, root, false) }  
) {  
  bind {  
       // bind your view with your data  
  }  
}

using Adapter Delegate library and ViewBinding we can create something like that. very clean easy to read.

For now this project implementing Adapter Delegate library. But not close the possibility to use code from scratch.

Built With

Contributing

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Anang Kurniawan - @anang_kur - anang@sampingan.co.id

Acknowledgements

About

This is a play ground project of implementing adapter delegate in Android.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages