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

Commit 82c950b

Browse files
authored
Merge pull request #8 from DevAhamed/develop
1.1.0 release
2 parents 1aee29d + a8c10a1 commit 82c950b

Some content is hidden

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

52 files changed

+1047
-448
lines changed

README.md

+3-160
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The minimum API level supported by this library is API 9.
1919
```gradle
2020
dependencies {
2121
// ... other dependencies here
22-
compile 'com.github.devahamed:multi-view-adapter:1.0.1'
22+
compile 'com.github.devahamed:multi-view-adapter:1.1.0'
2323
}
2424
```
2525

@@ -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)

images/File-Template-Cover.png

80.2 KB
Loading

images/File-Template-Menu.png

419 KB
Loading

images/contexual-action-mode.gif

740 KB
Loading

images/drag-and-drop.gif

1.11 MB
Loading

images/expandable-group.gif

1.31 MB
Loading

images/multi-list.gif

661 KB
Loading

images/swipe-to-dismiss.gif

1.01 MB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright 2017 Riyaz Ahamed
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
apply plugin: 'com.android.library'
18+
19+
def devPropertiesFile = rootProject.file("developer.properties");
20+
def devProperties = new Properties()
21+
devProperties.load(new FileInputStream(devPropertiesFile))
22+
23+
android {
24+
compileSdkVersion 25
25+
buildToolsVersion "25.0.3"
26+
27+
defaultConfig {
28+
minSdkVersion 9
29+
targetSdkVersion 25
30+
versionCode 1
31+
versionName "1.0"
32+
33+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
34+
}
35+
buildTypes {
36+
release {
37+
minifyEnabled false
38+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
39+
}
40+
}
41+
}
42+
43+
dependencies {
44+
compile project(':multi-view-adapter')
45+
provided('com.android.databinding:library:1.3.1') {
46+
transitive = false
47+
}
48+
provided('com.android.databinding:baseLibrary:2.3.2') {
49+
transitive = false
50+
}
51+
}
52+
53+
ext {
54+
55+
bintrayRepo = devProperties['repoName']
56+
bintrayName = devProperties['artifactId']
57+
58+
publishedGroupId = devProperties['groupId']
59+
libraryName = devProperties['repoName']
60+
artifact = devProperties['artifactIdDataBinding']
61+
62+
libraryDescription = 'Additional DataBinding support for MultiViewAdapter'
63+
64+
siteUrl = 'https://github.com/DevAhamed/MultiViewAdapter'
65+
gitUrl = 'https://github.com/DevAhamed/MultiViewAdapter.git'
66+
67+
libraryVersion = '1.1.0'
68+
69+
developerId = devProperties['devId']
70+
developerName = devProperties['devName']
71+
developerEmail = devProperties['devEmail']
72+
73+
licenseName = 'The Apache Software License, Version 2.0'
74+
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
75+
allLicenses = ["Apache-2.0"]
76+
}
77+
78+
apply from: '../install.gradle'
79+
apply from: '../bintray.gradle'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/Ahamed/Library/Android/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
18+
19+
# Uncomment this to preserve the line number information for
20+
# debugging stack traces.
21+
#-keepattributes SourceFile,LineNumberTable
22+
23+
# If you keep the line number information, uncomment this to
24+
# hide the original source file name.
25+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<?xml version="1.0" encoding="utf-8"?>
21
<!--
32
~ Copyright 2017 Riyaz Ahamed
43
~
@@ -15,11 +14,4 @@
1514
~ limitations under the License.
1615
-->
1716

18-
<LinearLayout
19-
xmlns:android="http://schemas.android.com/apk/res/android"
20-
android:layout_width="wrap_content"
21-
android:layout_height="wrap_content"
22-
android:orientation="horizontal"
23-
>
24-
25-
</LinearLayout>
17+
<manifest package="com.ahamed.multiviewadapter.databinding" />

multi-view-adapter/src/main/java/com/ahamed/multiviewadapter/BindingViewHolder.java renamed to multi-view-adapter-databinding/src/main/java/com/ahamed/multiviewadapter/BindingViewHolder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
* @param <M> Refers to the model class
2525
* @param <VDB> Refers to the DataBinding class of the model
2626
*/
27-
public abstract class BindingViewHolder<M, VDB extends ViewDataBinding> extends BaseViewHolder<M> {
27+
abstract class BindingViewHolder<M, VDB extends ViewDataBinding> extends BaseViewHolder<M> {
2828

2929
private final VDB binding;
3030

31-
public BindingViewHolder(VDB binding) {
31+
BindingViewHolder(VDB binding) {
3232
super(binding.getRoot());
3333
this.binding = binding;
3434
}

multi-view-adapter/src/main/java/com/ahamed/multiviewadapter/ItemDataBinder.java renamed to multi-view-adapter-databinding/src/main/java/com/ahamed/multiviewadapter/ItemDataBinder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import android.view.ViewGroup;
2222

2323
/**
24-
* {@link ItemBinder} which supports the DataBinding
24+
* ItemBinder which supports the DataBinding
2525
*
2626
* @param <M> Refers to the model class
2727
* @param <VDB> Refers to the view binding of the model class

multi-view-adapter/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ android {
3232
minSdkVersion 9
3333
targetSdkVersion 25
3434
versionCode 1
35-
versionName "1.0.1"
35+
versionName "1.1.0"
3636

3737
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
3838
}
@@ -62,7 +62,7 @@ ext {
6262
siteUrl = 'https://github.com/DevAhamed/MultiViewAdapter'
6363
gitUrl = 'https://github.com/DevAhamed/MultiViewAdapter.git'
6464

65-
libraryVersion = '1.0.1'
65+
libraryVersion = '1.1.0'
6666

6767
developerId = devProperties['devId']
6868
developerName = devProperties['devName']

multi-view-adapter/src/main/AndroidManifest.xml

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,4 @@
1414
~ limitations under the License.
1515
-->
1616

17-
<manifest
18-
package="com.ahamed.multiviewadapter"
19-
/>
17+
<manifest package="com.ahamed.multiviewadapter"/>

0 commit comments

Comments
 (0)