Skip to content

Commit 081e4eb

Browse files
authored
Update README.md
Rephrased some sentences.
1 parent f8b19da commit 081e4eb

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

README.md

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# DynamicStackAdapter
2-
This library helps to achieve a stack behaviour for RecyclerViews. It includes a Builder which handles all the
3-
creation and configuration of the Adapter. </br>
4-
![Imgur](http://i.imgur.com/oAfmXdE.gif)</br>
5-
Keep in mind that scrolling is disabled because it would interfere with the Drag&Drop mechanics.
2+
This library helps to achieve a stack behaviour for RecyclerViews. The user can move, delete and resize the items on the stack if desired. It works with the standard RecyclerView from the android support library.</br></br>
3+
![Imgur](http://i.imgur.com/oAfmXdE.gif)</br></br>
4+
Note: Keep in mind that scrolling is disabled because it would interfere with the Drag&Drop mechanics.
65

76
# Setup
87

@@ -19,13 +18,13 @@ Add jitpack.io to your repositories build.gradle file:
1918
And then add the dependency
2019
```
2120
dependencies {
21+
...
2222
compile 'com.github.TreesAreOp:dynamic-stack-adapter:v0.3-alpha'
2323
}
2424
```
2525

2626
# Usage
27-
To configure the Dynamic Stack Adapter you should use the DynamicStackBuilder class. The following example shows
28-
a minimum configuration of the RecyclerView
27+
You should use the DynamicStackBuilder class to set up the stack behaviour. This Library works without it but using the Builder makes the configuration process less complicated and configures the used RecyclerView appropiately. The following example shows a minimum configuration of the RecyclerView through the Builder:
2928
```java
3029
final MyAdapter adapter = (MyAdapter) new DynamicStackBuilder()
3130
.stackRecyclerView(stackView)
@@ -35,47 +34,56 @@ final MyAdapter adapter = (MyAdapter) new DynamicStackBuilder()
3534
.build();
3635
```
3736
You need to provide your own DynamicStackAdapter and DynamicStackViewHolder as well as a layout for the item views. Your custom Adapter
38-
needs to extend the DynamicStackAdapter and you need to specify your Item Type T and your custom DynamicStackViewHolder VH.
37+
needs to extend the DynamicStackAdapter and you need to specify your Item Type T and your custom DynamicStackViewHolder VH. The withCreateViewHolder and withBindViewHolder methods can be implemented like usual.
38+
Minimal example:
3939
```java
40-
public abstract class DynamicStackAdapter<T, VH extends DynamicStackViewHolder>
41-
```
42-
Subclass example:
43-
```java
44-
class MyAdapter extends DynamicStackAdapter<DataItem, MyViewHolder>
40+
class MyAdapter extends DynamicStackAdapter<Data, MyViewHolder> {
41+
public MyAdapter(RecyclerView container, Class holderClass) {
42+
super(container, holderClass);
43+
}
44+
45+
@Override
46+
public void withCreateViewHolder(MyViewHolder myViewHolder) {
47+
//this method is called when a ViewHolder is created
48+
}
49+
50+
@Override
51+
public void withBindViewHolder(MyViewHolder myViewHolder, int i, Data data) {
52+
//this method is called when a ViewHolder is bound to a position
53+
}
54+
}
4555
```
4656

4757
A custom DynamicStackViewHolder could be implemented like this:
4858
```java
4959
class MyViewHolder extends DynamicStackViewHolder {
5060

5161
//you can reference all your views of the item layout here
52-
TextView text;
5362

5463
protected MyViewHolder(View itemView, DynamicStackAdapter adapter) {
5564
super(itemView, adapter);
56-
df = new DecimalFormat("#");
5765
}
5866

59-
//here you get your views from the layout
6067
@Override
6168
protected void findCustomViews(View view) {
62-
text = (TextView) view.findViewById(R.id.content);
69+
//here you get your views from the layout with view.findViewByID(...)
6370
}
6471

65-
//this method is called when the user resizes the item AND when a new item is added
6672
@Override
6773
protected void updateOnResize(int i, Object o, float percentage) {
68-
text.setText("percentage: " + df.format(percentage * 100f) + "%");
74+
//this method is called when the user resizes the item AND when a new item is added
6975
}
7076

7177
}
7278
```
7379
And thats basically all you need to know.
7480
1. extend DynamicStackAdapter and DynamicStackViewHolder and implement your own versions
75-
2. run the builder
81+
2. run the builder and set up your RecyclerView, DynamicStackAdapter and DynamicStackViewHolder
7682

77-
Through the builder you can customize the Adapter, ViewHolder and RecyclerView. All of the following commands are optional.
78-
Most of them are self explanatory. You can read the documentation if anything is unclear. Default values will be used if you don't set those values yourself.
83+
A working example can be found in the app folder.
84+
</br>
85+
As mentioned before the builder allows you to customize the Adapter, ViewHolder and RecyclerView. All commands are listed below.
86+
Most of them are self explanatory but the documentation should provide more insight if anything is unclear. Default values will be used if the optional methods are not executed.
7987
```java
8088
final MyAdapter adapter = (MyAdapter) new DynamicStackBuilder() //reqired
8189
.stackRecyclerView(stackView) //reqired
@@ -94,9 +102,9 @@ final MyAdapter adapter = (MyAdapter) new DynamicStackBuilder() //reqired
94102
```
95103

96104
## Note:
97-
I highly recommend not using any margins for your item views!
98-
if you really must use margin you can look into the setPixelPadding method (which is just a workaround for now)
99-
or try to encapsulate the item view in a layout and use margin on the parent layout. Heres an example:
105+
I highly recommend not using any margins for your item views because some height calculations could become incorrect!
106+
if you really must use margins you can look into the setPixelPadding method (which is just a workaround for now)
107+
or try to encapsulate the item view in a parent layout and then add your margins to the actual (now child) item layout. Heres an example:
100108
```xml
101109
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
102110
android:layout_width="match_parent

0 commit comments

Comments
 (0)