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

Commit 5387bf3

Browse files
committed
Merge branch 'release/v1.0.0'
2 parents a4e449f + 21c06e7 commit 5387bf3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+925
-198
lines changed

README.md

+32-19
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ Helper library for recyclerviews to create composable view holders without boile
99

1010
## Gradle Dependency
1111

12-
The Gradle dependency is available via [jCenter](https://bintray.com/devahamed/MultiViewADapter/multi-view-adapter/view).
13-
jCenter is the default Maven repository used by Android Studio.
12+
The Gradle dependency is available via [JCenter](https://bintray.com/devahamed/MultiViewAdapter/multi-view-adapter/view).
13+
JCenter is the default maven repository used by Android Studio.
1414

15-
The minimum API level supported by this library is API 14.
15+
The minimum API level supported by this library is API 9.
1616

1717
```gradle
1818
dependencies {
1919
// ... other dependencies here
20-
compile 'com.github.devahamed:multi-view-adapter:0.9.1'
20+
compile 'com.github.devahamed:multi-view-adapter:1.0.0'
2121
}
2222
```
2323

@@ -26,7 +26,7 @@ dependencies {
2626

2727
Most of the android apps out there uses recyclerview to display content.
2828
As with any other system-level api, recyclerview api is also designed in a generic way.
29-
So it needs lot of boilerplate code to be written for displaying a simple list. And it doubles, if you need to display multiple view types.
29+
So it needs lot of code to be written for displaying a simple list. And it doubles, if you need to display multiple view types.
3030
MultiViewAdapter library helps you in removing this boilerplate code while allowing you to truly re-use the viewholder code across various adapters.
3131

3232
There are many other libraries, which provides the same feature. But they do enforce the either or all of the following constraints :
@@ -77,7 +77,7 @@ class CarBinder extends ItemBinder<CarModel, CarBinder.CarViewHolder> {
7777
// Bind the data here
7878
}
7979

80-
static class CarViewHolder extends BaseViewHolder<ItemModel> {
80+
static class CarViewHolder extends BaseViewHolder<CarModel> {
8181
// Normal ViewHolder code
8282
}
8383
}
@@ -159,8 +159,8 @@ MyItemDecorator will be used with the ItemBinder as follows.
159159

160160
public class CustomItemBinder implements ItemBinder {
161161

162-
public CustomItemBinder(CustomItemBinder customItemBinder) {
163-
super(customItemBinder);
162+
public CustomItemBinder(MyItemDecorator myItemDecorator) {
163+
super(myItemDecorator);
164164
}
165165
}
166166

@@ -175,32 +175,45 @@ You can also call `itemSelectionToggled()` to make it selected by yourself. Kind
175175
Finally, you can call `DataListManager`'s `getSelectedItems()` and `setSelectedItems(List<E> selectedItems)` to get and set selected items respectively.
176176

177177
### Using DiffUtil and Payload
178-
DataListManager and DataItemManager will take care of diffutil. There is no special code needed. But to enable the payloads, you have to create custom DataManager and override `areContensSame(Object, Object)` and `getChangePayload(Object, Object)`.
178+
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.
179179

180180

181181
```java
182-
public class CustomDataManager extends DataListManager<GridItem> {
182+
class CarAdapter extends RecyclerAdapter {
183183

184-
public CustomDataManager(RecyclerAdapter recyclerAdapter) {
185-
super(recyclerAdapter);
186-
}
184+
private DataListManager<CarModel> dataManager;
185+
private PayloadProvider<M> payloadProvider = new PayloadProvider<CarModel>() {
186+
@Override public boolean areContentsTheSame(CarModel oldItem, CarModel newItem) {
187+
// Your logic here
188+
return oldItem.equals(newItem);
189+
}
190+
191+
@Override public Object getChangePayload(CarModel oldItem, CarModel newItem) {
192+
// Your logic here
193+
return null;
194+
}
195+
};
196+
197+
public CarAdapter() {
198+
this.dataManager = new DataListManager<>(this, payloadProvider);
199+
addDataManager(dataManager);
187200

188-
@Override public boolean areContentsTheSame(GridItem oldItem, GridItem newItem) {
189-
// own impl
201+
registerBinder(new CarBinder());
190202
}
191203

192-
@Override public Object getChangePayload(GridItem oldItem, GridItem newItem) {
193-
return super.getChangePayload(oldItem, newItem); // Own impl
204+
public void addData(List<CarModel> dataList) {
205+
dataManager.addAll(dataList);
194206
}
195207
}
196208
```
197209

198210
## Roadmap
199-
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.
211+
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.
200212
1. Add support for StaggeredGrid layout manager
201213
2. Move diffutil calculation to background thread
202214
3. Adding support for swipe listeners with composability as priority
203215
4. Improve the sample app code and api documentation
216+
5. Expandable item / group
204217

205218

206219
## Changelog
@@ -219,7 +232,7 @@ Kindly make sure your code is formatted with this codestyle - [Square Java code
219232

220233
## Alternatives
221234
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.
222-
1. [MultipleViewTypesAdapter](https://github.com/yqritc/RecyclerView-MultipleViewTypesAdapter) - Original inspiration for this library. By inspiration, we mean that parts of code were "re-used"<br/>
235+
1. [MultipleViewTypesAdapter](https://github.com/yqritc/RecyclerView-MultipleViewTypesAdapter) - Original inspiration for this library.<br/>
223236
2. [AdapterDelegates](https://github.com/sockeqwe/AdapterDelegates)
224237
3. [Groupie](https://github.com/lisawray/groupie)
225238
4. [Epoxy](https://github.com/airbnb/epoxy)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0"?>
2+
<globals>
3+
<global id="srcOut" value="${srcDir}/${slashedPackageName(packageName)}" />
4+
</globals>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<recipe>
3+
4+
<instantiate from="src/app_package/Adapter.java.ftl"
5+
to="${escapeXmlAttribute(srcOut)}/${adapterName}.java" />
6+
<instantiate from="src/app_package/Binder.java.ftl"
7+
to="${escapeXmlAttribute(srcOut)}/${binderName}.java" />
8+
<instantiate from="res/layout/item_view.xml"
9+
to="${escapeXmlAttribute(resOut)}/layout/${item_layout}.xml" />
10+
11+
<open file="${srcOut}/${modelName}Adapter.java"/>
12+
</recipe>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:layout_width="wrap_content"
5+
android:layout_height="wrap_content"
6+
android:orientation="horizontal">
7+
8+
</LinearLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package ${packageName};
2+
3+
import com.ahamed.multiviewadapter.DataListManager;
4+
import com.ahamed.multiviewadapter.RecyclerAdapter;
5+
import java.util.List;
6+
import ${packageNameOfModel}.${modelName};
7+
8+
public class ${adapterName} extends RecyclerAdapter {
9+
10+
private DataListManager<${modelName}> ${extractLetters(modelName?lower_case)}ListManager;
11+
12+
public ${adapterName}() {
13+
this.${extractLetters(modelName?lower_case)}ListManager = new DataListManager<>(this);
14+
addDataManager(${extractLetters(modelName?lower_case)}ListManager);
15+
16+
registerBinder(new ${binderName}());
17+
}
18+
19+
public void set${modelName}List(List<${modelName}> dataList) {
20+
${extractLetters(modelName?lower_case)}ListManager.set(dataList);
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package ${packageName};
2+
3+
import android.view.LayoutInflater;
4+
import android.view.View;
5+
import android.view.ViewGroup;
6+
import com.ahamed.multiviewadapter.BaseViewHolder;
7+
import com.ahamed.multiviewadapter.ItemBinder;
8+
import ${packageNameOfModel}.${modelName};
9+
<#if applicationPackage??>
10+
import ${applicationPackage}.R;
11+
</#if>
12+
13+
public class ${binderName} extends ItemBinder<${modelName}, ${binderName}.ViewHolder> {
14+
15+
@Override public ViewHolder create(LayoutInflater layoutInflater, ViewGroup parent) {
16+
return new ViewHolder(layoutInflater.inflate(R.layout.${item_layout}, parent, false));
17+
}
18+
19+
@Override public boolean canBindData(Object item) {
20+
return item instanceof ${modelName};
21+
}
22+
23+
@Override public void bind(ViewHolder holder, ${modelName} item) {
24+
// TODO bind data here
25+
}
26+
27+
static class ViewHolder extends BaseViewHolder<${modelName}> {
28+
29+
ViewHolder(View itemView) {
30+
super(itemView);
31+
}
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<template description="Creates a new adapter for given model class"
2+
format="4"
3+
name="MultiViewAdapter"
4+
revision="1">
5+
6+
<!--
7+
For latest revision and usage
8+
visit - https://github.com/DevAhamed/MultiViewAdapter
9+
-->
10+
11+
<category value="Other"/>
12+
13+
<parameter constraints="class|nonempty"
14+
help="The model class that requires recycler adapter"
15+
id="modelName"
16+
name="Model class name"
17+
type="string"/>
18+
19+
<parameter constraints="package|exists|nonempty"
20+
default="${packageName}"
21+
help="The package where the model class is present"
22+
id="packageNameOfModel"
23+
name="Package of model class"
24+
type="string"/>
25+
26+
<parameter constraints="class|nonempty"
27+
help="Adapter name"
28+
id="adapterName"
29+
name="Adapter name"
30+
suggest="${extractLetters(modelName)}Adapter"
31+
type="string"/>
32+
33+
<parameter constraints="class|nonempty"
34+
help="Binder name"
35+
id="binderName"
36+
name="Binder name"
37+
suggest="${extractLetters(modelName)}Binder"
38+
type="string"/>
39+
40+
<parameter
41+
constraints="layout|nonempty|unique"
42+
default="item_view"
43+
id="item_layout"
44+
name="Viewholder"
45+
suggest="item_${extractLetters(modelName?lower_case)}"
46+
type="string"/>
47+
48+
<globals file="globals.xml.ftl"/>
49+
<execute file="recipe.xml.ftl"/>
50+
51+
</template>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0"?>
2+
<globals>
3+
<global id="srcOut" value="${srcDir}/${slashedPackageName(packageName)}" />
4+
</globals>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<recipe>
3+
4+
<instantiate from="src/app_package/Binder.java.ftl"
5+
to="${escapeXmlAttribute(srcOut)}/${binderName}.java" />
6+
<instantiate from="res/layout/item_view.xml"
7+
to="${escapeXmlAttribute(resOut)}/layout/${item_layout}.xml" />
8+
9+
<open file="${srcOut}/${modelName}Adapter.java"/>
10+
</recipe>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:layout_width="wrap_content"
5+
android:layout_height="wrap_content"
6+
android:orientation="horizontal">
7+
8+
</LinearLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package ${packageName};
2+
3+
import android.view.LayoutInflater;
4+
import android.view.View;
5+
import android.view.ViewGroup;
6+
import com.ahamed.multiviewadapter.BaseViewHolder;
7+
import com.ahamed.multiviewadapter.ItemBinder;
8+
import ${packageNameOfModel}.${modelName};
9+
<#if applicationPackage??>
10+
import ${applicationPackage}.R;
11+
</#if>
12+
13+
public class ${binderName} extends ItemBinder<${modelName}, ${binderName}.ViewHolder> {
14+
15+
@Override public ViewHolder create(LayoutInflater layoutInflater, ViewGroup parent) {
16+
return new ViewHolder(layoutInflater.inflate(R.layout.${item_layout}, parent, false));
17+
}
18+
19+
@Override public boolean canBindData(Object item) {
20+
return item instanceof ${modelName};
21+
}
22+
23+
@Override public void bind(ViewHolder holder, ${modelName} item) {
24+
// TODO bind data here
25+
}
26+
27+
static class ViewHolder extends BaseViewHolder<${modelName}> {
28+
29+
ViewHolder(View itemView) {
30+
super(itemView);
31+
}
32+
}
33+
}
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<template description="Creates a new adapter for given model class"
2+
format="4"
3+
name="MultiViewAdapter"
4+
revision="1">
5+
6+
<!--
7+
For latest revision and usage
8+
visit - https://github.com/DevAhamed/MultiViewAdapter
9+
-->
10+
11+
<category value="Other"/>
12+
13+
<parameter constraints="class|nonempty"
14+
help="The model class that requires recycler adapter"
15+
id="modelName"
16+
name="Model class name"
17+
type="string"/>
18+
19+
<parameter constraints="package|exists|nonempty"
20+
default="${packageName}"
21+
help="The package where the model class is present"
22+
id="packageNameOfModel"
23+
name="Package of model class"
24+
type="string"/>
25+
26+
<parameter constraints="class|nonempty"
27+
help="Binder name"
28+
id="binderName"
29+
name="Binder name"
30+
suggest="${extractLetters(modelName)}Binder"
31+
type="string"/>
32+
33+
<parameter
34+
constraints="layout|nonempty|unique"
35+
default="item_view"
36+
id="item_layout"
37+
name="Viewholder"
38+
suggest="item_${extractLetters(modelName?lower_case)}"
39+
type="string"/>
40+
41+
<globals file="globals.xml.ftl"/>
42+
<execute file="recipe.xml.ftl"/>
43+
44+
</template>

multi-view-adapter/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ devProperties.load(new FileInputStream(devPropertiesFile))
66

77
android {
88
compileSdkVersion 25
9-
buildToolsVersion "25.0.2"
9+
buildToolsVersion "25.0.3"
1010

1111
defaultConfig {
1212
minSdkVersion 9
1313
targetSdkVersion 25
1414
versionCode 1
15-
versionName "0.9.0"
15+
versionName "1.0.0"
1616

1717
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1818
}
@@ -43,7 +43,7 @@ ext {
4343
siteUrl = 'https://github.com/DevAhamed/MultiViewAdapter'
4444
gitUrl = 'https://github.com/DevAhamed/MultiViewAdapter.git'
4545

46-
libraryVersion = '0.9.1'
46+
libraryVersion = '1.0.0'
4747

4848
developerId = devProperties['devId']
4949
developerName = devProperties['devName']

0 commit comments

Comments
 (0)