Skip to content

Commit 9d184e8

Browse files
committed
Update readme with groupie-ktx information
1 parent f6ef344 commit 9d184e8

1 file changed

Lines changed: 30 additions & 3 deletions

File tree

README.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ Groups are the building block of Groupie. An individual `Item` (the unit which
5555

5656
Kotlin
5757
```kotlin
58-
groupAdapter += HeaderItem()
59-
groupAdapter += CommentItem()
58+
groupAdapter.add(HeaderItem())
59+
groupAdapter.add(CommentItem())
6060

6161
val section = Section()
6262
section.setHeader(HeaderItem())
6363
section.addAll(bodyItems)
64-
groupAdapter += section
64+
groupAdapter.add(section)
6565
```
6666

6767
Java
@@ -168,6 +168,33 @@ Finally, in your `Item<MyExistingViewHolder>`, override
168168
}
169169
```
170170

171+
### Add and remove items with `+=` and `-=` in Kotlin
172+
173+
`groupie-ktx` provides Kotlin Extensions overriding the `plusAssign` and `minusAssign` operations on both group adapters and sections. This enables a cleaner syntax when creating and modifying layouts.
174+
175+
```gradle
176+
implementation "com.github.lisawray.groupie:groupie:$groupie_version"
177+
implementation "com.github.lisawray.groupie:groupie-ktx:$groupie_version"
178+
```
179+
180+
Instances of `.add()`, `.addAll()`, and `.remove()` can be replaced with `+=` and `-=`
181+
182+
```kotlin
183+
// Without groupie-ktx
184+
mySection.add(HeaderItem())
185+
mySection.remove(CommentItem())
186+
groupAdapter.add(mySection)
187+
groupAdapter.remove(DescriptionItem())
188+
189+
// With groupie-ktx
190+
mySection += HeaderItem()
191+
mySection -= CommentItem()
192+
groupAdapter += mySection
193+
groupAdapter -= DescriptionItem()
194+
```
195+
196+
Note: `groupie-ktx` is included with the deprecated `groupie-kotlin-android-extensions`. If you depend on `groupie-kotlin-android-extensions`, you do not need to also depend on this module.
197+
171198
### Note:
172199

173200
Items can also declare their own column span and whether they are draggable or swipeable.

0 commit comments

Comments
 (0)