-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
644 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,45 @@ | ||
# SuperAdapter | ||
recyclerview 万能adapter | ||
# Walle <img alt="Walle is an android library" src="https://www.cleveroad.com/public/comercial/label-android.svg" height="19"> [![minSdk for Walle](https://img.shields.io/badge/minSdk-15-green.svg)](#) | ||
|
||
## This is Walle - Recyclerview.Adapter's helper | ||
|
||
|
||
## Setup and usage | ||
### installation | ||
|
||
with gradle | ||
```GRADLE | ||
compile 'com.github.donniesky:walle:0.0.1' | ||
``` | ||
|
||
Assuming you have installed jitpack provider: | ||
```GRADLE | ||
allprojects { | ||
repositories { | ||
jcenter() | ||
maven { url "https://jitpack.io" } | ||
} | ||
} | ||
``` | ||
|
||
or just import `Walle` module to your project. | ||
|
||
## Features | ||
Proxy Pattern. | ||
|
||
* No need change anything with your target adapter; | ||
* Not destory target adapter position; | ||
* Support dynamic add & remove; | ||
* No dependencies code build order | ||
|
||
### Usage | ||
|
||
```JAVA | ||
Walle wrapper = Walle.newBuilder() | ||
.wrapperAdapter(adapter) | ||
.autoLoadMore(false) | ||
.headerViewRes(R.layout.view_header) | ||
.emptyViewRes(R.layout.view_empty) | ||
.footerViewRes(R.layout.view_footer) | ||
.loadMoreViewRes(R.layout.view_loadmore) | ||
.build(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,65 @@ | ||
package me.donnie.superadapter; | ||
|
||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.DividerItemDecoration; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.View; | ||
import android.widget.Toast; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import me.donnie.adapter.MultiItemAdapter; | ||
import me.donnie.adapter.Walle; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
private RecyclerView rv; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
rv = (RecyclerView) findViewById(R.id.rv); | ||
rv.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)); | ||
rv.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL)); | ||
|
||
TestAdapter adapter = new TestAdapter(); | ||
adapter.setOnItemClickListener(new MultiItemAdapter.OnItemClickListener() { | ||
@Override | ||
public void onItemClick(MultiItemAdapter adapter, View view, int position) { | ||
Toast.makeText(MainActivity.this, position+"", Toast.LENGTH_SHORT).show(); | ||
} | ||
}); | ||
|
||
Walle wrapper = Walle.newBuilder() | ||
.wrapperAdapter(adapter) | ||
.autoLoadMore(false) | ||
.headerViewRes(R.layout.view_header) | ||
.emptyViewRes(R.layout.view_empty) | ||
.footerViewRes(R.layout.view_footer) | ||
.loadMoreViewRes(R.layout.view_loadmore) | ||
.build(); | ||
|
||
rv.setAdapter(wrapper.getWrapperAdapter()); | ||
adapter.addNewData(getData()); | ||
|
||
} | ||
|
||
private List<Test> getData() { | ||
List<Test> tests = new ArrayList<>(); | ||
for (int i = 0; i < 20; i++) { | ||
Test test = new Test(); | ||
test.setId(i); | ||
test.setName("name "+i); | ||
test.setDesc("desc "+i); | ||
tests.add(test); | ||
} | ||
return tests; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.constraint.ConstraintLayout | ||
<android.support.v7.widget.RecyclerView | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/rv" | ||
android:scrollbars="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context="me.donnie.superadapter.MainActivity"> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Hello World!" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toTopOf="parent"/> | ||
|
||
</android.support.constraint.ConstraintLayout> | ||
tools:context="me.donnie.superadapter.MainActivity"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:padding="10dp" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal"> | ||
|
||
<ImageView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:src="@mipmap/ic_launcher"/> | ||
|
||
<LinearLayout | ||
android:layout_marginLeft="15dp" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:id="@+id/name" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="123"/> | ||
|
||
<TextView | ||
android:id="@+id/desc" | ||
android:layout_marginTop="5dp" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="aksjdfkljalksdj" | ||
android:textSize="18sp"/> | ||
|
||
</LinearLayout> | ||
|
||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:gravity="center" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:textSize="50sp" | ||
android:text="内容为空"/> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:gravity="center" | ||
android:layout_width="match_parent" | ||
android:layout_height="50dp"> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="这是尾部"/> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:gravity="center" | ||
android:layout_width="match_parent" | ||
android:layout_height="50dp"> | ||
|
||
<ImageView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:src="@mipmap/ic_launcher"/> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:gravity="center" | ||
android:layout_width="match_parent" | ||
android:layout_height="50dp"> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="加载更多..."/> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ buildscript { | |
allprojects { | ||
repositories { | ||
jcenter() | ||
maven { url "https://jitpack.io" } | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.