PrimeAdapter
PrimeAdapter makes working with RecyclerView easier by separating required code in some simple clean classes. It brings simplicity when you have multiple view types in a RecyclerView. You can use PrimeAdapter in both Kotlin and Java Android projects as the sample apps are written.
Custom Divider | Draggability | Expandability |
---|---|---|
![]() |
![]() |
![]() |
Download
Add the following lines to your build.gradle
file:
- If you write code in Java, you should also add kotlin dependency too:
How to use PrimeAdapter?
You should create both data holder and view holder classes for each type of view that you want to show in RecyclerView
.
- It's necessary to add
@DataHolder
annotation above all data holder classes which inherits fromPrimeDataHolder
:
- Each view holder class should inherit from
PrimeViewHolder
and specify related data holder as a type parameter like following:
- Your custom adapter class must inherit from
PrimeAdapter
that decides to make view holder instance based on data holder type.
Follow this pattern:
- Finally, you can instantiate your custom adapter using
PrimeAdapter
builder mechanism.
Extra Features
Handling Item Clicks
PrimeAdapter helps you handle RecyclerView
items click events,
simply by setItemClickListener()
with an OnRecyclerViewItemClickListener
argument when you're building an adapter instance or later:
Draggability
PrimeAdapter helps you make the RecyclerView
items draggable.
It would be activated/deactivated by calling setDraggable(true)
/setDraggable(false)
on a builder or an adapter instance.
Optionally, you can get notified about item movements by calling setItemDragListener()
and passing an OnRecyclerViewItemDragListener
instance to it.
It is necessary to introduce a view as handle of dragging in view holders which are going to be draggable:
Expandability
Another feature of PrimeAdapter is making the implementation of RecyclerView
items expansion easier.
Calling the setExpandable(true)
/setExpandable(false)
on a builder or on adapter instance changes its activation.
To see how to implement it, please check the [related example code][2].
Custom Skippable Divider
Showing custom divider lines is a good feature that PrimeAdapter provides.
Calling the setDivider()
on a builder or on adapter instance leads to show default divider line between items.
It's possible to pass it a custom Drawable
instance or simply a color to change the divider looking.
Also we can set inset for divider drawables in pixels.
By default dividers are shown for all items except the last one.
It's easy to skip some items divider by setting hasDivider
property to false
on their data holder instances.