Skip to content

Commit

Permalink
Merge pull request #2 from longbkiter07/develop/v1
Browse files Browse the repository at this point in the history
Develop/v1
  • Loading branch information
longbkiter07 authored Apr 24, 2017
2 parents 9d44bf7 + e8e9024 commit 00f8eed
Show file tree
Hide file tree
Showing 26 changed files with 1,320 additions and 908 deletions.
45 changes: 24 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# SnappyRecyclerAdapter

This library helps you to manage `RecyclerViewAdapter` easier.
This library helps you to manage `RecyclerViewAdapter` easier. This library is very useful for rendering a sorted data in real time (For example: chat application)

# Features

* Calling `notifyDataSetChanges`, `notifyItemInserted`, `notifyItemChanged`... and apply [DiffUtil] (https://developer.android.com/reference/android/support/v7/util/DiffUtil.html) automatically so you don't care about them anymore.
* Calling `DiffUtil` in background thread so that the ui does not lag.
* Calling `notifyDataSetChanges`, `notifyItemInserted`, `notifyItemChanged`... automatically
* Applying both `SortedList` and `DiffUtil`
* Calling `DiffUtil` in background thread so that the ui does not lag
* Queueing events to keep data is consistent.
* Observable method so that we can catch the callback to do next action.
* Supporting LinkedList, ArrayList for reasonable usage.

# Usage

Expand All @@ -25,36 +25,39 @@ compile 'com.android.support:recyclerview-v7:24.+'
```

Code example: read [here] (https://github.com/longbkiter07/SnappyRecyclerAdapter/blob/master/app/src/main/java/com/silong/snappyrecycleradapter/adapter/UserRecyclerViewAdapter.java)
Code example: please read sample app

## Create your RecyclerList:

```
List<T> recyclerList = new ArrayList<>();
```
Or
```
List<T> recyclerList = new RecyclerLinkedList<>();
```
`RecyclerLinkedList` is a list that helps you to improve performance for `get(int index)` method.
## Create your RecyclerViewAdapter:

```
public class MyAdapter<VH> extends RecyclerViewAdapter<VH> {
private final ObservableAdapterManager<User> mObservableAdapterManager;
public MyRecyclerViewAdapter(List<User> items) {
mObservableAdapterManager = new ObservableAdapterManager<User>(this, items, null);
private final RxSortedList<T> mRxSortedList;
public MyRecyclerViewAdapter() {
mRxSortedList = new RxSortedList<>(T.class, new RxRecyclerViewCallback<T>(this) {
@Override
public boolean areContentsTheSame(T oldData, T newData) {
return //return whether content of oldData and newData are the same
}
@Override
public boolean areItemsTheSame(T oldData, T newData) {
return //return whether oldData and newData are the same (checking object id is recommended)
}
@Override
public int compare(T o1, T o2) {
return //sort order.
}
});
}
@Override
public int getItemCount() {
return mObservableAdapterManager.getItemCount();
return mRxSortedList.size();
}
...
}
```

If you want to use `DiffUtil`, you would implement `DataComparable` to define differences between 2 items. Otherwise, you can pass `null` value.

## Add item:

```
Expand Down
5 changes: 4 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
}
defaultConfig {
applicationId "com.silong.snappyrecycleradapter"
minSdkVersion 15
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
Expand All @@ -28,5 +28,8 @@ dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:recyclerview-v7:24.2.0'
debugCompile "com.github.brianPlummer:tinydancer:0.1.1"
releaseCompile "com.github.brianPlummer:tinydancer-noop:0.1.1"
testCompile "com.github.brianPlummer:tinydancer-noop:0.1.1"
compile project(path: ':observablerm')
}
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
</intent-filter>
</activity>
<activity android:name=".RecyclerViewActivity" />
<activity android:name=".ListViewActivity" />
</application>

</manifest>
28 changes: 28 additions & 0 deletions app/src/main/java/com/silong/snappyrecycleradapter/App.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.silong.snappyrecycleradapter;

import com.codemonkeylabs.fpslibrary.FrameDataCallback;
import com.codemonkeylabs.fpslibrary.TinyDancer;

import android.app.Application;
import android.util.Log;

/**
* Created by SILONG on 8/29/16.
Expand All @@ -10,6 +14,30 @@ public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
// TinyDancer.create()
// .show(this);

//alternatively
// TinyDancer.create()
// .redFlagPercentage(.1f) // set red indicator for 10%....different from default
// .startingXPosition(200)
// .startingYPosition(600)
// .show(this);

//you can add a callback to get frame times and the calculated
//number of dropped frames within that window
TinyDancer.create()
.addFrameDataCallback(new FrameDataCallback() {
@Override
public void doFrame(long previousFrameNS, long currentFrameNS, int droppedFrames) {
//collect your stats here
long renderTime = (currentFrameNS - previousFrameNS) / 1000000;
if (renderTime > 35) {
Log.d("App", "rendered frame:" + renderTime);
}
}
})
.show(this);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
ListView listView = (ListView) findViewById(android.R.id.list);
listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
new String[]{
"Fast RecyclerView with ArrayList",
"Fast RecyclerView with LinkedList",
"Regular RecyclerView",
"Regular ListView"
"RxSortedList",
"SortedList",
"RegularList"
}));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
Expand All @@ -33,16 +32,13 @@ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
switch (i) {
default:
case 0:
intent = RecyclerViewActivity.newFastArrayListIntent(MainActivity.this);
intent = RecyclerViewActivity.newRxSortedList(MainActivity.this, listView.getItemAtPosition(i).toString());
break;
case 1:
intent = RecyclerViewActivity.newFastLinkedListIntent(MainActivity.this);
intent = RecyclerViewActivity.newSortedIntent(MainActivity.this, listView.getItemAtPosition(i).toString());
break;
case 2:
intent = RecyclerViewActivity.newRegularIntent(MainActivity.this);
break;
case 3:
intent = new Intent(MainActivity.this, ListViewActivity.class);
intent = RecyclerViewActivity.newRegularIntent(MainActivity.this, listView.getItemAtPosition(i).toString());
break;
}
startActivity(intent);
Expand Down
Loading

0 comments on commit 00f8eed

Please sign in to comment.