Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
Prepare v0.2.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
belinwu committed Jan 25, 2019
1 parent 1fa8d77 commit 85813f9
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 23 deletions.
66 changes: 53 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,28 @@ Modular adapter for Android RecyclerView.
**DO NOT USE THIS LIBRARY IN PRODUCTION UNTIL V1.0.0 IS RELEASED.**

# Installation

Add the following dependency to your `build.gradle` file:

```groovy
dependencies {
implementation 'com.samelody.modapter:modapter:0.1.0'
// required, core
implementation 'com.samelody.modapter:modapter-core:0.2.0'
// optional, support android paging library
implementation 'com.samelody.modapter:modapter-paging:0.2.0'
}
```

# Usage

```java
// create a ModularAdapter object instead of creating new Subclass of RecyclerView.Adapter.
ModularAdapter adapter = new ModularAdapter();
recyclerView.setAdapter(adapter);
ModularAdapter<AdapterItem> adapter = new ModularAdapter<>();
listView.setAdapter(adapter);

// register item metadata to manager
ItemManager manager = adapter.getManager();
ItemManager<AdapterItem> manager = adapter.getManager();
manager.register(R.layout.item_gallery_image, ImageViewHolder.class)
.register(R.layout.item_gallery_date, DateViewHolder.class);

Expand All @@ -35,32 +40,67 @@ List<Item> list = new ArrayList<>();
list.add(new ImageItem());
list.add(new DateItem());

// Setup list and notify
manager.setList(list);
// submit list
manager.submitList(list);

// notify adapter if no async differs used
adapter.notifyDataSetChanged();
```

# Docs
## AsyncDiffer

The `ItemManager` not enable async diffing by default.

You can setup `AsyncDiffer` by your choice. The setting API is

`ItemManager#setDiffer()`.

The implemented async differs are following:

- `NonAsyncDiffer`: The non implementation. (default used)
- `ListAsyncDiffer`: The `AsyncListDiffer` implementation.
- `PagedAsyncDiffer`: The `AsyncPagedListDiffer` implementation.

### Using Async Differ

```java
// set differ
manager.setDiffer(new ListAsyncDiffer<>());

// submit list
manager.submitList(list);

// not need to call adapter.notify APIs
```

## ItemManager

All APIs are encapsulated in `ItemManager` interface returned by `ModularAdapter#getItemManager()`.
All APIs are encapsulated in `ItemManager` interface returned by `ModularAdapter#getManager()`.

```java
// register via layoutId and holderClass
ItemManager register(@LayoutRes int layoutId, Class<T> holderClass);
ItemManager<E> register(@LayoutRes int layoutId, Class<T> holderClass);

// register via ItemMetadata
ItemManager register(ItemMetadata metadata);
ItemManager<E> register(ItemMetadata metadata);

// unregister via layoutId
ItemManager unregister(@LayoutRes int layoutId);
ItemManager<E> unregister(@LayoutRes int layoutId);

// setup the data list
ItemManager setList(List<? extends AdapterItem> list);
ItemManager<E> submitList(List<? extends E> list);

// Gets the item with given position
T getItem(int position);
E getItem(int position);

// Gets current displayed list
List<E> getCurrentList();

// Gets item count
int getItemCount();

// setup async differ
ItemManager<E> setDiffer(AsyncDiffer<E> differ);
```

# License
Expand Down
2 changes: 1 addition & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pubspec.artifactId = 'modapter-core'
pubspec.repo = 'maven'
pubspec.name = 'Modapter'
pubspec.description = 'Modular adapter for Android RecyclerView.'
pubspec.version = "0.2.0-alpha1"
pubspec.version = "0.2.0"
pubspec.versionCode = 2
pubspec.url = 'https://github.com/samelody/modapter'
pubspec.gitUrl = 'https://github.com/samelody/modapter.git'
Expand Down
2 changes: 1 addition & 1 deletion paging/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pubspec.artifactId = 'modapter-paging'
pubspec.repo = 'maven'
pubspec.name = 'Modapter'
pubspec.description = 'Modular adapter for Android RecyclerView.'
pubspec.version = "0.2.0-alpha1"
pubspec.version = "0.2.0"
pubspec.versionCode = 2
pubspec.url = 'https://github.com/samelody/modapter'
pubspec.gitUrl = 'https://github.com/samelody/modapter.git'
Expand Down
5 changes: 3 additions & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {
minSdkVersion deps.minSdk
targetSdkVersion deps.targetSdk
versionCode 2
versionName "0.2.0-alpha1"
versionName "0.2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -22,7 +22,8 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':core')
implementation project(':paging')
// implementation "com.samelody.modapter:modapter:0.1.0"
// implementation "com.samelody.modapter:modapter-core:0.2.0"
// implementation "com.samelody.modapter:modapter-paging:0.2.0"
implementation deps.appcompat
implementation deps.recyclerview
implementation deps.constraintlayout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;

import com.samelody.modapter.AbstractItem;
import com.samelody.modapter.AdapterItem;
import com.samelody.modapter.ItemManager;
import com.samelody.modapter.ModularAdapter;

Expand All @@ -19,20 +19,20 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);

RecyclerView listView = findViewById(R.id.list);
ModularAdapter<AbstractItem> adapter = new ModularAdapter<>();
ModularAdapter<AdapterItem> adapter = new ModularAdapter<>();
listView.setAdapter(adapter);

ItemManager<AbstractItem> manager = adapter.getManager();
ItemManager<AdapterItem> manager = adapter.getManager();
manager.register(R.layout.item_gallery_image, ImageViewHolder.class)
.register(R.layout.item_gallery_date, DateViewHolder.class);

manager.unregister(R.layout.item_gallery_image);

List<ImageItem> list = new ArrayList<>();
list.add(new ImageItem());
list.add(new ImageItem());
List<AdapterItem> list = new ArrayList<>();
list.add(new ImageItem());
list.add(new DateItem());
list.add(new ImageItem());
list.add(new DateItem());
manager.submitList(list);
adapter.notifyDataSetChanged();

Expand Down

0 comments on commit 85813f9

Please sign in to comment.