Skip to content
This repository was archived by the owner on Jan 2, 2021. It is now read-only.

Commit a8c10a1

Browse files
committed
Update readme with link for wiki
1 parent aba2178 commit a8c10a1

1 file changed

Lines changed: 2 additions & 159 deletions

File tree

README.md

Lines changed: 2 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -61,164 +61,7 @@ You can read more about this library here in this [Medium article](https://mediu
6161

6262
## Usage
6363
To get some idea about the MultiViewAdapter features kindly look at sample app code.
64-
65-
### Simple adapters
66-
Let us display list of cars. No fuss. Here is the entire code.
67-
68-
<b>CarBinder</b>
69-
70-
```java
71-
class CarBinder extends ItemBinder<CarModel, CarBinder.CarViewHolder> {
72-
73-
@Override public CarViewHolder create(LayoutInflater inflater, ViewGroup parent) {
74-
return new CarViewHolder(inflater.inflate(R.layout.item_car, parent, false));
75-
}
76-
77-
@Override public boolean canBindData(Object item) {
78-
return item instanceof CarModel;
79-
}
80-
81-
@Override public void bind(CarViewHolder holder, CarModel item) {
82-
// Bind the data here
83-
}
84-
85-
static class CarViewHolder extends BaseViewHolder<CarModel> {
86-
// Normal ViewHolder code
87-
}
88-
}
89-
```
90-
91-
<b>CarAdapter</b>
92-
93-
```java
94-
class CarAdapter extends RecyclerAdapter {
95-
96-
private DataListManager<CarModel> dataManager;
97-
98-
public SimpleAdapter() {
99-
this.dataManager = new DataListManager<>(this);
100-
addDataManager(dataManager);
101-
102-
registerBinder(new CarBinder());
103-
}
104-
105-
public void addData(List<CarModel> dataList) {
106-
dataManager.addAll(dataList);
107-
}
108-
}
109-
```
110-
111-
Now you are good to go. Just create the CarAdapter object and set it to your recyclerview. When addData() method is called it will show the items in recyclerview.
112-
<br/>
113-
If you want to show multiple viewtypes just create multiple ItemBinders and register inside the adapter.
114-
115-
### For different span count in GridLayoutManager
116-
If the GridLayoutManager has different span count for different view types, then override the getSpanSize() method inside ItemBinder.
117-
118-
```
119-
120-
@Override public int getSpanSize(int maxSpanCount) {
121-
return 1; // Return any number which is less than maxSpanCount
122-
}
123-
124-
```
125-
126-
Also don't forget to set span size lookup in GridLayoutManager. Adapter has default span size lookup object. Use that object.
127-
128-
```
129-
layoutManager.setSpanSizeLookup(adapter.getSpanSizeLookup());
130-
```
131-
132-
### ItemDecoration support
133-
Create your own item decoration class implementing ItemDecorator. It goes like this,
134-
135-
136-
```java
137-
138-
public class MyItemDecorator implements ItemDecorator {
139-
140-
public MyItemDecorator() {
141-
// Any initialization code
142-
}
143-
144-
@Override public void getItemOffsets(Rect outRect, int position, int positionType) {
145-
// Set item offset for each item
146-
// outRect.set(0, 0, 0, 0);
147-
}
148-
149-
@Override public void onDraw(Canvas canvas, RecyclerView parent, View child, int position,
150-
int positionType) {
151-
// Canvas drawing code implementation
152-
// Unlike default ItemDecoration, this method will be called for individual items. Do not create objects here.
153-
}
154-
}
155-
156-
```
157-
158-
The methods, getItemOffsets and onDraw will be called for each item. So avoid creating objects there.
159-
<br/>
160-
MyItemDecorator will be used with the ItemBinder as follows.
161-
162-
163-
```java
164-
165-
public class CustomItemBinder implements ItemBinder {
166-
167-
public CustomItemBinder(MyItemDecorator myItemDecorator) {
168-
super(myItemDecorator);
169-
}
170-
}
171-
172-
```
173-
174-
### Making RecyclerView selectable
175-
Just extend your adapter from SelectableAdapter instead of RecyclerAdapter. Now the adapter is selectable.
176-
To make an ItemBinder as selectable, extend it from SelectableBinder and also extend ViewHolder from SelectableViewHolder.
177-
By default, on long press ViewHolder will be selectable if it extends from SelectableViewHolder.
178-
You can also call `itemSelectionToggled()` to make it selected by yourself. Kindly go through the sample repo implementation.
179-
<br/>
180-
Finally, you can call `DataListManager`'s `getSelectedItems()` and `setSelectedItems(List<E> selectedItems)` to get and set selected items respectively.
181-
182-
### Using DiffUtil and Payload
183-
DataListManager and DataItemManager will take care of diffutil. There is no special code needed. But to enable the payloads, you have to pass PayloadProvider to DataListManager's constructor.
184-
185-
186-
```java
187-
class CarAdapter extends RecyclerAdapter {
188-
189-
private DataListManager<CarModel> dataManager;
190-
private PayloadProvider<M> payloadProvider = new PayloadProvider<CarModel>() {
191-
@Override public boolean areContentsTheSame(CarModel oldItem, CarModel newItem) {
192-
// Your logic here
193-
return oldItem.equals(newItem);
194-
}
195-
196-
@Override public Object getChangePayload(CarModel oldItem, CarModel newItem) {
197-
// Your logic here
198-
return null;
199-
}
200-
};
201-
202-
public CarAdapter() {
203-
this.dataManager = new DataListManager<>(this, payloadProvider);
204-
addDataManager(dataManager);
205-
206-
registerBinder(new CarBinder());
207-
}
208-
209-
public void addData(List<CarModel> dataList) {
210-
dataManager.addAll(dataList);
211-
}
212-
}
213-
```
214-
215-
## Roadmap
216-
I am actively working on expanding the feature set of this library. While i don't have a exact timeline, but here are the future plans. All these will be taken up once 1.0 is released.
217-
1. Add support for StaggeredGrid layout manager
218-
2. Move diffutil calculation to background thread
219-
3. Adding support for swipe listeners with composability as priority
220-
4. Improve the sample app code and api documentation
221-
5. Expandable item / group
64+
Also we have comprehensive wiki pages as well. Take a look at [JCenter](https://github.com/DevAhamed/MultiViewAdapter/wiki).
22265

22366

22467
## Changelog
@@ -236,7 +79,7 @@ Kindly make sure your code is formatted with this codestyle - [Square Java code
23679

23780

23881
## Alternatives
239-
This library may not suit your needs or imposes too many restrictions. In that case create an issue/feature request. In the mean time check these awesome alternatives as well.
82+
This library may not suit your needs or imposes too many restrictions. In that case create an issue/feature request. Mean time check these awesome alternatives as well.
24083
1. [MultipleViewTypesAdapter](https://github.com/yqritc/RecyclerView-MultipleViewTypesAdapter) - Original inspiration for this library.<br/>
24184
2. [AdapterDelegates](https://github.com/sockeqwe/AdapterDelegates)
24285
3. [Groupie](https://github.com/lisawray/groupie)

0 commit comments

Comments
 (0)