Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ Groups are the building block of Groupie. An individual `Item` (the unit which

Kotlin
```kotlin
groupAdapter += HeaderItem()
groupAdapter += CommentItem()
groupAdapter.add(HeaderItem())
groupAdapter.add(CommentItem())

val section = Section()
section.setHeader(HeaderItem())
section.addAll(bodyItems)
groupAdapter += section
groupAdapter.add(section)
```
Comment on lines 57 to 65
Copy link
Author

@jack-webb jack-webb Sep 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT this part of the readme was wrong. groupie-kotlin-android-extensions wasn't mentioned before this point, so you wouldn't have the dependency necessary to use the overloaded functions.


Java
Expand Down Expand Up @@ -168,6 +168,33 @@ Finally, in your `Item<MyExistingViewHolder>`, override
}
```

### Add and remove items with `+=` and `-=` in Kotlin

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

```gradle
implementation "com.github.lisawray.groupie:groupie:$groupie_version"
implementation "com.github.lisawray.groupie:groupie-ktx:$groupie_version"
```

Instances of `.add()`, `.addAll()`, and `.remove()` can be replaced with `+=` and `-=`

```kotlin
// Without groupie-ktx
mySection.add(HeaderItem())
mySection.remove(CommentItem())
groupAdapter.add(mySection)
groupAdapter.remove(DescriptionItem())

// With groupie-ktx
mySection += HeaderItem()
mySection -= CommentItem()
groupAdapter += mySection
groupAdapter -= DescriptionItem()
```

Note: `groupie-ktx` is included with the deprecated `groupie-kotlin-android-extensions` module. If you depend on `groupie-kotlin-android-extensions`, you do not need to also depend on this module.

### Note:

Items can also declare their own column span and whether they are draggable or swipeable.
Expand Down
1 change: 1 addition & 0 deletions library-groupie-ktx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
111 changes: 111 additions & 0 deletions library-groupie-ktx/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'maven-publish'


archivesBaseName = 'groupie-ktx'


android {
compileSdkVersion rootProject.sdkVersion


defaultConfig {
minSdkVersion rootProject.minimumSdkVersion
targetSdkVersion rootProject.sdkVersion
versionCode 20
versionName "1.0"
}

signingConfigs {
release {
}
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled false
}
}

}

dependencies {
implementation project(':library')
implementation "androidx.recyclerview:recyclerview:1.2.1"
}

tasks.withType(Javadoc).all {
enabled = false
}


group = "com.github.lisawray.groupie"
version = "2.10.1"

task javadoc(type: Javadoc) {
configurations.implementation.canBeResolved(true)
configurations.api.canBeResolved(true)

failOnError false

source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
//destinationDir = file("../javadoc/")
classpath += configurations.api
}

task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
archiveClassifier = "sources"
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

artifacts {
archives sourcesJar
archives javadocJar
}

// Because the components are created only during the afterEvaluate phase, you must
// configure your publications using the afterEvaluate() lifecycle method.
afterEvaluate {
publishing {
publications {
// Creates a Maven publication called "release".
release(MavenPublication) {
// Applies the component for the release build variant.
from components.release
artifact(sourcesJar)

// You can then customize attributes of the publication as shown below.
groupId = 'com.github.lisawray.groupie'
artifactId = 'groupie-ktx'
version = '2.10.1'

pom.withXml {
def dependenciesNode = (asNode().get("dependencies") as groovy.util.NodeList).get(0) as groovy.util.Node
def configurationNames = ["implementation", "api"]

configurationNames.forEach { configurationName ->
configurations[configurationName].allDependencies.forEach {
if (it.group != null && it.version != "unspecified") {
def dependencyNode = dependenciesNode.appendNode("dependency")
dependencyNode.appendNode("groupId", it.group)
dependencyNode.appendNode("artifactId", it.name)
dependencyNode.appendNode("version", it.version)
// dependencyNode.appendNode("scope", configurationName)
}
}
}
}
}
}
}
}



6 changes: 6 additions & 0 deletions library-groupie-ktx/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
POM_NAME=groupie-ktx
POM_DESCRIPTION=Library to help with complex RecyclerViews
POM_BINTRAY_NAME=groupie-ktx
POM_ARTIFACT_ID=groupie-ktx
POM_PACKAGING=aar
POM_VERSION=2.10.1
2 changes: 2 additions & 0 deletions library-groupie-ktx/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xwray.groupie.groupie-ktx" />
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.xwray.groupie.Group
import com.xwray.groupie.GroupAdapter
import com.xwray.groupie.GroupieViewHolder

// TODO(zhuinden): move this into its own artifact later: `groupiex` (or rather, `groupie-ktx`)
operator fun GroupAdapter<out GroupieViewHolder>.plusAssign(element: Group) = this.add(element)
operator fun GroupAdapter<out GroupieViewHolder>.plusAssign(groups: Collection<Group>) = this.addAll(groups)
operator fun GroupAdapter<out GroupieViewHolder>.minusAssign(element: Group) = this.remove(element)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.xwray.groupie.groupiex
import com.xwray.groupie.Group
import com.xwray.groupie.Section

// TODO(zhuinden): move this into its own artifact later: `groupiex` (or rather, `groupie-ktx`)
operator fun Section.plusAssign(element: Group) = this.add(element)
operator fun Section.plusAssign(groups: Collection<Group>) = this.addAll(groups)
operator fun Section.minusAssign(element: Group) = this.remove(element)
Expand Down
1 change: 1 addition & 0 deletions library-kotlin-android-extensions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ android {

dependencies {
implementation project(':library')
implementation project(':library-groupie-ktx')
implementation "androidx.recyclerview:recyclerview:1.2.1"
}

Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':example-databinding', ':library-databinding', ':library', ':example', ':example-shared', ':library-kotlin-android-extensions', 'example-viewbinding', ':library-viewbinding'
include ':example-databinding', ':library-databinding', ':library', ':example', ':example-shared', ':library-kotlin-android-extensions', ':library-groupie-ktx', 'example-viewbinding', ':library-viewbinding'