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(
}
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.
Added selections
Initial version
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"
}
-dontwarn io.erva.celladapter2.**
-keep public class kotlin.reflect.jvm.internal.impl.builtins.* { public *; }
-keepclassmembers class * extends io.erva.celladapter2.** {
<init>(android.view.View);
}
CellAdapter is licensed under the MIT License.