-
Notifications
You must be signed in to change notification settings - Fork 729
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Model group building with Kotlin DSL (#1012)
* Add an empty constructor for `EpoxyModelGroup`, protected visibility only. * If the model implements `ModelCollector` make the build too so the DSL can be used. * Use the new model group DSL in the sample app * Add `implementsModelCollector` in memoizer * Fix memoizer implementation * Add `shouldSaveViewState` property to model group * Make `EpoxyModelGroup` a `ModelCollector` and create a `GroupModel` class with the `@EpoxyModelClass` annotation so it can be used in the DSL * Can be simnplified * force codegen on pr check * revert last change * Move ModelCollector code to GroupModel as EpoxyModelGroup can't be used directly in the DSL * Add a small doc/usage * Check class hierarchy for ModelCollector * Reset shouldSaveViewState to private Co-authored-by: Emmanuel Boudrant <eboudrant@netflix.com>
- Loading branch information
Showing
9 changed files
with
143 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
epoxy-adapter/src/main/java/com/airbnb/epoxy/GroupModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.airbnb.epoxy | ||
|
||
/** | ||
* An [EpoxyModelGroup] usable in a DSL manner via the [group] extension. | ||
* <p> | ||
* Example: | ||
* ``` | ||
* group { | ||
* id("photos") | ||
* layout(R.layout.photo_grid) | ||
* | ||
* // add your models here, example: | ||
* for (photo in photos) { | ||
* imageView { | ||
* id(photo.id) | ||
* url(photo.url) | ||
* } | ||
* } | ||
* } | ||
* ``` | ||
*/ | ||
@EpoxyModelClass | ||
abstract class GroupModel : EpoxyModelGroup(), ModelCollector { | ||
|
||
override fun add(model: EpoxyModel<*>) { | ||
super.addModel(model) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
kotlinsample/src/main/java/com/airbnb/epoxy/kotlinsample/models/ColoredSquareView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.airbnb.epoxy.kotlinsample.models | ||
|
||
import android.content.Context | ||
import android.graphics.Color | ||
import android.util.AttributeSet | ||
import android.view.View | ||
import androidx.annotation.ColorInt | ||
import com.airbnb.epoxy.ModelProp | ||
import com.airbnb.epoxy.ModelView | ||
import com.airbnb.epoxy.kotlinsample.R | ||
|
||
@ModelView(defaultLayout = R.layout.colored_square_view) | ||
class ColoredSquareView @JvmOverloads constructor( | ||
context: Context, | ||
attrs: AttributeSet? = null, | ||
defStyleAttr: Int = 0 | ||
) : View(context, attrs, defStyleAttr) { | ||
|
||
@JvmOverloads | ||
@ModelProp | ||
fun color(@ColorInt color: Int = Color.RED) { | ||
setBackgroundColor(color) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<com.airbnb.epoxy.kotlinsample.models.ColoredSquareView xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="56dp" | ||
android:layout_height="56dp" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal" /> |