Skip to content

Commit 1474d56

Browse files
Update github pages
Change ModularItem to interface
1 parent 940c744 commit 1474d56

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

docs/README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,16 @@ Now that we understand the architecture of the library, let's take a look at wha
3737

3838
## Level 1
3939

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__.
4141

4242
```
43-
public class Pokemon extends ModularItem {
43+
public class Pokemon implements ModularItem {
4444
public String name;
4545
public Drawable icon;
4646
47+
public boolean isHeader() {
48+
return false;
49+
}
4750
}
4851
4952
public class PokemonModule extends AdapterModule<PokemonViewHolder, Pokemon> {
@@ -93,16 +96,19 @@ And voila, your `RecyclerView` is showing the names and images of your pokemon.
9396

9497
<img src="art/List_pokemon.png" alt="List of pokemon" width="250">
9598

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.
97100

98101
```
99-
public class Header extends ModularItem {
102+
public class Header implements ModularItem {
100103
String name;
101104
102105
public Header(String name) {
103106
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;
106112
}
107113
}
108114
@@ -152,7 +158,7 @@ We now have a list of pokemon, divided by headers.
152158

153159
<img src="art/List_pokemon_headers.png" alt="List of pokemon, subdivided by headers" width="250">
154160

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.
156162

157163
This code clearly shows that the modularity introduced at the first level makes for easy adding of new *viewtypes* and clean code.
158164

0 commit comments

Comments
 (0)