Skip to content

Commit 57ccffb

Browse files
committed
Updated Readme
1 parent faddfb0 commit 57ccffb

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

README.md

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,54 @@
11
#AdapterCommands
2+
Drop in solution to animate RecyclerView's dataset changes by using the `command pattern.
3+
Read my [blog post]() for more information.
4+
5+
Keep in mind that the runtime of `DiffCommandsCalculator` is `O(n*m)` (n = number of items in old list, m = number of items in new list).
6+
So you better run this on a background thread if your data set contains many items.
27

38
##Dependencies
49

510
```groovy
6-
compile 'com.hannesdorfmann.adaptercommands:adaptercommands:1.0.0'
11+
compile 'com.hannesdorfmann.adaptercommands:adaptercommands:1.0.1'
712
```
813

9-
## Motivation
10-
1114
## How to use
15+
There are basically 2 components:
16+
- `DiffCommandsCalculator` that calculates the difference from previous data set to the new data set and returns `List<AdapterCommand>`
17+
- `AdapterCommandProcessor` takes `List<AdapterCommand>` and executes each command to trigger RecyclerView's `ItemAnimator` to run animations.
18+
19+
```java
20+
public class MainActivity extends AppCompatActivity {
21+
22+
@Bind(R.id.recyclerView) RecyclerView recyclerView;
23+
24+
List<Item> items = new ArrayList<Item>();
25+
Random random = new Random();
26+
ItemAdapter adapter; // RecyclerView adapter
27+
AdapterCommandProcessor commandProcessor;
28+
DiffCommandsCalculator<Item> commandsCalculator = new DiffCommandsCalculator<Item>();
29+
30+
@Override protected void onCreate(Bundle savedInstanceState) {
31+
super.onCreate(savedInstanceState);
32+
setContentView(R.layout.activity_main);
33+
ButterKnife.bind(this);
34+
35+
adapter = new ItemAdapter(this, items);
36+
recyclerView.setAdapter(adapter);
37+
recyclerView.setLayoutManager(new GridLayoutManager(this, 4));
38+
39+
commandProcessor = new AdapterCommandProcessor(adapter);
40+
}
41+
42+
// Called when new items should be displayed in RecyclerView
43+
public void setItems(List<Item> newItems){
44+
adapter.setItems(newItems);
45+
List<AdapterCommand> commands = commandsCalculator.diff(items);
46+
commandProcessor.execute(commands); // executes commands that triggers animations
47+
}
48+
```
49+
50+
## MVP
51+
Best practise is to use a `PresentationModel` and `Model-View-Presenter`. See my [blog post]() for a concrete example.
1252

1353
## License
1454

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
# org.gradle.parallel=true
1919

2020

21-
VERSION_NAME=1.0.0
22-
VERSION_CODE=101
21+
VERSION_NAME=1.0.2-SNAPSHOT
22+
VERSION_CODE=102
2323
GROUP=com.hannesdorfmann.adaptercommands
2424

2525

0 commit comments

Comments
 (0)