Skip to content

CellAdapter simplifies working with RecyclerView. It provides an opportunity to easily support multiple view types, to separate ViewHolders from Adapter class, map data to a view in a convenient way, register and handle UI callbacks for each ViewHolder.

License

Notifications You must be signed in to change notification settings

erva/CellAdapter2

Repository files navigation

CellAdapter

License: MIT

GitHub Logo

This library simplifies RecyclerView with multiple view types. Main points:

  • Single adapter class for all project
  • Easy to use - just register Cell, Model and ClickListener (optional) in adapter
  • Listen clicks on any View of any type
  • Use view binding
  • For Java / Kotlin and androidx.recyclerview/support:recyclerview-v7 see CellAdapter 1

No more code like this:

companion object {
    const val VIEW_TYPE_ONE = 1
    const val VIEW_TYPE_TWO = 2
    }

if (viewType == VIEW_TYPE_ONE) {
    return View1ViewHolder()
} else {
    eturn View2ViewHolder(
}

Usage

Kotlin

private var cellAdapter: CellAdapter = CellAdapter().apply {
    cell(
        cell = AlphaCell::class,
        binding = ItemAlphaBinding::class.java,
        model = AlphaModel::class,
        listener = object : Listener<AlphaModel> {
            override fun onCellClicked(item: AlphaModel) { }
        }
    )
    cell(
        cell = BetaCell::class,
        binding = ItemBetaBinding::class.java,
        model = BetaModel::class
        // listener may be not provided
    )
}

where AlphaCell::class is POJO and AlphaCell::class is

class AlphaCell(private val binding: ItemAlphaBinding) :
Cell<AlphaModel, ItemAlphaBinding, Listener<AlphaModel>>(binding) {

    override fun bindView() {
        val item = item()
        binding.tvAlpha.text = item.alpha
    }
}

Check samples for details.

Samples and hints

Versions

1.0.3

Added selections

1.0.0

Initial version

Download

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

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

Add the dependency:

dependencies {
    implementation "com.github.erva:celladapter2:1.0.3"
}

Proguard

-dontwarn io.erva.celladapter2.**
-keep public class kotlin.reflect.jvm.internal.impl.builtins.* { public *; }
-keepclassmembers class * extends io.erva.celladapter2.** {
    <init>(android.view.View);
}

License

CellAdapter is licensed under the MIT License.


Icons made by Freepik from www.flaticon.com is licensed by CC 3.0 BY

About

CellAdapter simplifies working with RecyclerView. It provides an opportunity to easily support multiple view types, to separate ViewHolders from Adapter class, map data to a view in a convenient way, register and handle UI callbacks for each ViewHolder.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published