Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Vlayout | 10,795 | 107 | 3 | 2 years ago | 56 | January 30, 2018 | 195 | mit | Java | |
Project vlayout is a powerfull LayoutManager extension for RecyclerView, it provides a group of layouts for RecyclerView. Make it able to handle a complicate situation when grid, list and other layouts in the same recyclerview. | ||||||||||
Multitype | 5,503 | 156 | 5 | 7 months ago | 53 | March 16, 2019 | 11 | apache-2.0 | Kotlin | |
Flexible multiple types for Android RecyclerView. | ||||||||||
Rendererrecyclerviewadapter | 1,153 | 8 | a year ago | 24 | April 17, 2021 | 1 | apache-2.0 | Java | ||
A single adapter with multiple view types for the whole project | ||||||||||
Multiviewadapter | 791 | 2 years ago | 30 | apache-2.0 | Java | |||||
Easily create complex recyclerview adapters in android | ||||||||||
Baserecyclerviewadapter | 114 | 2 years ago | 1 | February 05, 2021 | 3 | apache-2.0 | Kotlin | |||
⚡ Fast way to bind RecyclerView adapter and ViewHolder for implementing clean sections. | ||||||||||
Recyclerview_helper | 107 | 6 years ago | 2 | Java | ||||||
对RecyclerView的封装,使用简单,功能丰富 | ||||||||||
Kidadapter | 56 | 4 months ago | 18 | November 26, 2021 | apache-2.0 | Kotlin | ||||
kotlin dsl for kids to simplify RecyclerView.Adapter logic | ||||||||||
Lxadapter | 47 | 3 years ago | apache-2.0 | Java | ||||||
RecyclerView Adapter Library | ||||||||||
Mystique | 46 | 6 years ago | apache-2.0 | Kotlin | ||||||
💡🚀⭐️ A generalized adapter for RecyclerView on Android which makes it easy to add heterogeneous items to a list | ||||||||||
Nested Expandable Recyclerview | 31 | a year ago | 1 | Kotlin | ||||||
Nested Expandable RecyclerView for Android |
😔 Due to the nature of my job and growing popularity of Jetpack Compose, I lack the motivation to keep this project alive.
Recyclerview is one of the powerful widgets inside android framework. But creating adapters with multiple view types is always exhausting. Not anymore. MultiViewAdapter makes it easy for you to create adapter with multiple view types easily. Using the library you will be able to build composable view holders, which can be re-used across your app. Apart from this, MultiViewAdapter adds many other useful features into the library as add-ons.
🎉🎉 MultiViewAdapter v3.0 supports AndroidX. v3.0 is identical to v2.0 except for package name changes and androidx support.
Have you ever displayed multiple view types inside a single adapter? Have you ever added selection mode to an adapter? Have you ever set different span size to different items inside a single adapter? Have you ever added swipe-to-dismiss / drag & drop / infinite scrolling features to your adapter?
If you answered yes, then you must know how hard it is to do any one of these. What if you had to add all of these inside a single adapter. Phew.
To solve the above problems, you can also use a different library or libraries. But such libraries have a common restrictions - Your data model will be polluted with the view logic.
MultiViewAdapter solves all of these requirements. The library was specifically designed in a way to not interfere with your object modeling and hierarchy.
Here are the few features which are possible with this library.
Multiple Viewtypes | Multiple Spans | Other Features |
---|---|---|
![]() |
![]() |
![]() |
Selection | Item Expansion | Section Expansion |
---|---|---|
![]() |
![]() |
![]() |
The library is available via JCenter. JCenter is the default maven repository used by Android Studio. The minimum API level supported by this library is API 14.
dependencies {
implementation 'dev.ahamed.mva2:adapter:2.0.0'
}
dependencies {
implementation 'dev.ahamed.mva2:ext-databinding:2.0.0' // DataBinding
implementation 'dev.ahamed.mva2:ext-decorator:2.0.0' // Decorators
implementation 'dev.ahamed.mva2:ext-diffutil-rx:2.0.0' // RxDiffUtil
}
Just add '-SNAPSHOT' to the version name
dependencies {
implementation 'dev.ahamed.mva2:adapter:2.0.0-SNAPSHOT' // Library
}
To use the above snapshot version add the following to your project's gradle file
allprojects {
repositories {
maven {
url 'https://oss.jfrog.org/artifactory/oss-snapshot-local'
}
}
}
Core mantra of MultiViewAdapter - Separation of view logic from data management logic. You get two different components which are :
Section is the building block for MultiViewAdapter. Section will hold your data which needs to be displayed inside the recyclerview - data can be a single item or list of items. When the underlying data is changed the section will calculate the diff and call the correct notify method inside the adapter. You can add as many as Section to an adapter.
There are different types of sections.
Name | Description |
---|---|
ItemSection | Section to display single item |
ListSection | Section to display list of items |
HeaderSection | Section to display list of items along with a header |
NestedSection | Section which can host other section |
TreeSection | Section which can display items in tree fashion. Ex: Comment list |
ItemBinder is the class where all view related code should be written. ItemBinder is responsible for creating and binding view holders. The method signatures are kept close to the default RecyclerView.Adapter
method signatures. For each viewtype inside the recyclerview, you need to create an ItemBinder.
ItemBinder allows you to have different decoration for different view types. Apart from this, with ItemBinder you will be able to add Swipe-to-dismiss, drag and drop features.
Lets create an adapter which displays a list of cars. Follow these steps.
public class CarBinder extends ItemBinder<CarModel, CarBinder.CarViewHolder> {
@Override public CarViewHolder createViewHolder(ViewGroup parent) {
return new CarViewHolder(inflate(R.layout.item_car, parent));
}
@Override public boolean canBindData(Object item) {
return item instanceof CarModel;
}
@Override public void bindViewHolder(CarViewHolder holder, CarModel item) {
holder.tvCarName.setText(item.getName());
}
static class CarViewHolder extends ItemViewHolder<CarModel> {
TextView tvCarName;
public CarViewHolder(View itemView) {
super(itemView);
tvCarName = findViewById(R.id.tv_car_name);
}
}
}
class CarListActivity extends Activity {
private RecyclerView recyclerView;
private List<CarModel> cars;
public void initViews() {
// Create Adapter
MultiViewAdapter adapter = new MultiViewAdapter();
recyclerView.setAdapter(adapter);
// Register Binder
adapter.registerBinders(new CarItemBinder());
// Create Section and add items
ListSection<YourModel> listSection = new ListSection<>();
listSection.addAll(cars);
// Add Section to the adapter
adapter.addSection(listSection);
}
}
Yay!! We are done.
The USP of MultiViewAdapter is adding multiple viewtypes to a single adapter easily. For each view type you need to create an ItemBinder
and register it with the adapter. You don't need to manage the viewtypes yourself or write crazy if-else-if conditions.
adapter.registerBinders(new Binder1(), new Binder2(), ...);
Sections are building blocks of MultiViewAdapter. You can add as many as sections to the adapter and you can nest the sections within another section as well. Each section represents a data set. If you want to display multiple data set inside a single adapter you can do so by adding any number of sections.
adapter.addSection(new ItemSection());
adapter.addSection(new ListSection());
adapter.addSection(new NestedSection());
// And so on...
MultiViewAdapter provides easy way to add selection/choice mode for the recyclerview. There are four types of mode available
Set selection mode to your adapter or section.
adapter.setSelectionMode(Mode.SINGLE);
// You can set selection mode for section as well
section1.setSelectionMode(Mode.MULTIPLE); // Different mode than adapter
section2.setSelectionMode(Mode.NONE); // Disables selection for this section
To select an item, inside the viewholder call ItemViewHolder.toggleItemSelection()
method. For example,
static class ViewHolder extends BaseViewHolder<SelectableItem> {
ViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
toggleItemSelection();
}
});
}
}
MultiViewAdapter allows you to expand/collapse a single item or an entire section. There are four types of expansion mode available.
Set expansion mode to the adapter.
// Expanding single item
adapter.setExpansionMode(Mode.SINGLE);
section1.setExpansionMode(Mode.MULTIPLE); // Different mode than adapter
section2.setExpansionMode(Mode.NONE); // Disables expansion for this section
// Expanding Sections
adapter.setSectionExpansionMode(Mode.SINGLE);
To expand/collapse an item, inside the viewholder call ItemViewHolder.toggleItemExpansion()
method. Similarly to expand/collapse a section, call ItemViewHolder.toggleSectionExpansion()
method. For example,
static class ViewHolder extends BaseViewHolder<SelectableItem> {
ViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
toggleItemExpansion();
// or
toggleSectionExpansion();
}
});
}
}
You can display items inside the adapter with different span count. You can customise the span count either by ItemBinder
or Section
.
Each ItemBinder
can customise the span count by overriding a method like this. maxSpanCount
is the span count of parent.
public class SampleBinder extends ItemBinder<SampleModel, SampleViewHolder> {
@Override public int getSpanSize(int maxSpanCount) {
return YOUR_SPAN_COUNT;
}
}
You can also set span count for individual sections. Call section.setSpanCount(int)
to set the span count for sections.
Swipe to dismiss gesture can be added in two simple steps.
Attach your RecyclerView to the adapter's ItemTouchHelper
.
adapter.getItemTouchHelper().attachToRecyclerView(recyclerView);
Override getSwipeDirections()
inside your viewholder class.
@Override public int getSwipeDirections() {
return ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
}
You can drag and drop the items inside or across sections. An item can be moved to any place of another item - only constraint is view type should be same for both items. Drag and drop gesture can be added by two simple steps,
Attach your RecyclerView to the adapter's ItemTouchHelper
.
adapter.getItemTouchHelper().attachToRecyclerView(recyclerView);
Override getDragDirections()
inside your viewholder class.
@Override public int getDragDirections() {
return ItemTouchHelper.LEFT
| ItemTouchHelper.UP
| ItemTouchHelper.RIGHT
| ItemTouchHelper.DOWN;
}
Infinite loading is a add-on feature available in MultiViewAdapter ie., you don't need to create a separate adapter. You can use it with existing MultiViewAdapter, by creating an InfiniteLoadingHelper
object and setting it to adapter.
protected void setUpAdapter() {
// Only 10 pages will be loaded
infiniteLoadingHelper = new InfiniteLoadingHelper(recyclerView, R.layout.item_loading_footer, 10) {
@Override public void onLoadNextPage(int page) {
// Load next page
}
};
adapter.setInfiniteLoadingHelper(infiniteLoadingHelper);
}
The library allows you to draw decoration for individual items or sections. You can create a decoration by extending Decorator
which can be added to any ItemBinder or Section.
MultiViewAdapter adapter = new MultiViewAdapter();
recyclerView.addItemDecoration(adapter.getItemDecoration());
// Add to itembinder
itemBinder.addDecorator(new SampleDecoration());
// or you can add it to a Section
section.addDecorator(new SampleDecoration());
Decoration and its api's are powerful feature of this library. Kindly read the full documentation to understand the complete feature. Decoration Documentation
Type | Stability | Date |
---|---|---|
Major | Stable | 29-October-2019 |
After being in development for more than a year and being in beta for more than three months, the library is moved to stable release.
Type | Stability | Date |
---|---|---|
Major | Beta | 3-July-2019 |
All public API's are finalized for v2.0.0 release, only bug fixes will be added in further beta's.
OnItemClickListener
method inside the ItemSection class.Type | Stability | Date |
---|---|---|
Major | Alpha | 31-May-2019 |
onDrawOver
method inside the decoration apiclearAllSelections()
method - Issue
Type | Stability | Date |
---|---|---|
Major | Alpha | 20-April-2019 |
Alternatively, you can visit the project's releases page for complete changelog. (View Releases) Also if you watch this repository, GitHub will send you a notification every time there is an update.
We welcome any contribution to the library. This project has a good infrastructure which should make you comfortable to push any changes. When you make a pull request CI builds the project, runs the test cases and reports the test coverage changes, so you will know whether your pull request is breaking build.
You can contribute to any of the following modules:
We are looking for project maintainers, who have made prior contributions to this project can get in touch if interested. You can contact the project owner here.
This project stands on the shoulders of open source community. It is a must to credit where it is due.
Also this library uses following open source gradle plugins
If this library does not suit your needs create an issue/feature request. Meanwhile check these awesome alternatives as well.
If you are using MultiViewAdapter in your app and you are happy with it, you can create a pull request to include your app information here. We will display it here.
Copyright 2017 Riyaz Ahamed
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.