You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/README.md
+13-7Lines changed: 13 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,13 +37,16 @@ Now that we understand the architecture of the library, let's take a look at wha
37
37
38
38
## Level 1
39
39
40
-
Let's say we want to show the images and names of some pokemon in our `RecyclerView`. The only things we need, are a *Pokemon* class extending__ModularItem__ and a *PokemonModule* extending __AdapterModule__.
40
+
Let's say we want to show the images and names of some pokemon in our `RecyclerView`. The only things we need, are a *Pokemon* class implementing__ModularItem__ and a *PokemonModule* extending __AdapterModule__.
41
41
42
42
```
43
-
public class Pokemon extends ModularItem {
43
+
public class Pokemon implements ModularItem {
44
44
public String name;
45
45
public Drawable icon;
46
46
47
+
public boolean isHeader() {
48
+
return false;
49
+
}
47
50
}
48
51
49
52
public class PokemonModule extends AdapterModule<PokemonViewHolder, Pokemon> {
@@ -93,16 +96,19 @@ And voila, your `RecyclerView` is showing the names and images of your pokemon.
93
96
94
97
<imgsrc="art/List_pokemon.png"alt="List of pokemon"width="250">
95
98
96
-
But now it's just a long list of pokemon. A clear overview is missing. So lets fix that by adding in some headers. Again, let's create a *Header* class extending__ModularItem__ and a *HeaderModule* extending __AdapterModule__. Now just set the *isHeader* field of __ModularItem__ to true in the *Header* class to make the *adapter* recognize it as a header.
99
+
But now it's just a long list of pokemon. A clear overview is missing. So lets fix that by adding in some headers. Again, let's create a *Header* class implementing__ModularItem__ and a *HeaderModule* extending __AdapterModule__. Now just return true in the *isHeader()* method of __ModularItem__ in the *Header* class to make the *adapter* recognize it as a header.
97
100
98
101
```
99
-
public class Header extends ModularItem {
102
+
public class Header implements ModularItem {
100
103
String name;
101
104
102
105
public Header(String name) {
103
106
this.name = name;
104
-
// set isHeader = true to make ModularAdapter recognize this as a header class.
105
-
isHeader = true;
107
+
}
108
+
109
+
public boolean isHeader() {
110
+
// return true to make ModularAdapter recognize this as a header class.
111
+
return true;
106
112
}
107
113
}
108
114
@@ -152,7 +158,7 @@ We now have a list of pokemon, divided by headers.
152
158
153
159
<imgsrc="art/List_pokemon_headers.png"alt="List of pokemon, subdivided by headers"width="250">
154
160
155
-
If you want to add some more *viewtypes*, just do the same again over and over. Want to add some digimon to spice it up? Create a *Digimon* class extending__ModularItem__ and a *DigimonModule* extending __AdapterModule__ and add it to the adapter.
161
+
If you want to add some more *viewtypes*, just do the same again over and over. Want to add some digimon to spice it up? Create a *Digimon* class implementing__ModularItem__ and a *DigimonModule* extending __AdapterModule__ and add it to the adapter.
156
162
157
163
This code clearly shows that the modularity introduced at the first level makes for easy adding of new *viewtypes* and clean code.
0 commit comments