Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
lisawray authored Jan 2, 2018
1 parent 196dc2c commit 893132d
Showing 1 changed file with 18 additions and 31 deletions.
49 changes: 18 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ Groupie plays best with Kotlin and Kotlin Android extensions. Never write a View
You can also use Groupie with Java and your existing ViewHolders.

```gradle
compile 'com.xwray:groupie:2.0.0-alpha2'
compile 'com.xwray:groupie:2.0.0'
```

Groupie also supports Android's [data binding](https://developer.android.com/topic/libraries/data-binding/index.html) to generate view holders. [Setup here.](#data-binding)

```gradle
compile 'com.xwray:groupie-databinding:2.0.0-alpha2'
```
The last stable release ONLY supported data binding. It was:
```gradle
compile 'com.xwray:groupie:1.1.1'
compile 'com.xwray:groupie-databinding:2.0.0'
```

Which one to choose? It's up to you and what your project already uses. You can even use Kotlin and data binding together.[<sup>*</sup>](#kotlin-and-data-binding) Or all your existing hand-written Java ViewHolders, and one new Kotlin item to try it out. Go crazy!
Expand Down Expand Up @@ -60,30 +56,15 @@ section.removeHeader(); // results in a remove event for 1 item in the adapter,
```

There are a few simple implementations of Groups within the library:
- `Section`, a list of body content with an optional header group and footer group.
- `Section`, a list of body content with an optional header group and footer group. It supports diffing
- `ExpandableGroup`, a single parent group with a list of body content that can be toggled hidden or shown.
- `UpdatingGroup`, a list of items which can diff its previous and new contents and animate moves, updates and other changes

Groups are flexible and composable. They can be combined and nested to arbitrary depth. For example, you could make an UpdatingSection by adding a single UpdatingGroup to the content of a Section.

```java
public class UpdatingSection extends Section {
private final UpdatingGroup updatingGroup;

public UpdatingSection() {
setHeader(new HeaderItem("Updating section!");
updatingGroup = new UpdatingGroup();
}

public void update(List<Item> list) {
updatingGroup.update(list);
}
}
```
Groups are flexible and composable. They can be combined and nested to arbitrary depth.

Life is messy, so groups are designed so that making new ones and defining their behavior is easy. You should make many small, simple, custom groups as the need strikes you.

You can implement the `Group` interface directly if you want. However, in most cases, you should extend the base implementation, `NestedGroup`. NestedGroup provides support for arbitrary nesting of groups, registering/unregistering listeners, and fine-grained change notifications to support animations and updating the adapter.
You can implement the `Group` interface directly if you want. However, in most cases, you should extend `Section` or the base implementation, `NestedGroup`. Section supports common RV paradigms like diffing, headers, footers, and placeholders. NestedGroup provides support for arbitrary nesting of groups, registering/unregistering listeners, and fine-grained change notifications to support animations and updating the adapter.

## Items

Expand All @@ -94,15 +75,15 @@ Groupie abstracts away the complexity of multiple item view types. Each Item de
The `Item` class gives you simple callbacks to bind your model object to the generated fields. Because of Kotlin Android extensions, there's no need to write a view holder.

```kotlin
import kotlinx.android.synthetic.main.song.view.*
import kotlinx.android.synthetic.main.song.*

class SongItem constructor(private val song: Song) : Item<ViewHolder>() {

override fun getLayout() = R.layout.song

override fun bind(viewHolder: ViewHolder, position: Int) {
viewHolder.itemView.title.text = song.title
viewHolder.itemView.title.artist = song.artist
viewHolder.title.text = song.title
viewHolder.title.artist = song.artist
}
}
```
Expand Down Expand Up @@ -153,7 +134,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
buildscript {
ext.kotlin_version = '1.1.1'
ext.kotlin_version = '1.2.10'
repositories {
jcenter()
}
Expand All @@ -163,15 +144,21 @@ buildscript {
}
}
// IMPORTANT! Enables view caching in viewholders.
// See: https://github.com/Kotlin/KEEP/blob/master/proposals/android-extensions-entity-caching.md
androidExtensions {
experimental = true
}
dependencies {
compile 'com.xwray:groupie:2.0.0-alpha2'
compile 'com.xwray:groupie:2.0.0'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
```

Remember to include
```kotlin
import kotlinx.android.synthetic.main.my_item_layout.view.*
import kotlinx.android.synthetic.main.my_item_layout.*
```
in the corresponding Item class for generated view references.

Expand All @@ -187,7 +174,7 @@ android {
}
dependencies {
compile 'com.xwray:groupie-databinding:2.0.0-alpha2'
compile 'com.xwray:groupie-databinding:2.0.0'
}
```

Expand Down

0 comments on commit 893132d

Please sign in to comment.