Last active
May 12, 2020 16:05
-
-
Save eboudrant/4dcd821d410dc1656b7696a0e12424b4 to your computer and use it in GitHub Desktop.
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
// New attribute | |
@Nullable | |
private List<EpoxyModel<?>> modelsPending_List = null; | |
// New method, not declared in `CarouselNoSnapModelBuilder` interface. | |
public CarouselNoSnapModelBuilder add(@NonNull EpoxyModel<?> model) { | |
if (model == null) { | |
throw new IllegalArgumentException("model cannot be null"); | |
} | |
if (modelsPending_List != null) { | |
modelsPending_List = new ArrayList<>(); | |
} | |
modelsPending_List.add(model); | |
return this; | |
} | |
// New method, called by `addTo` | |
private void addPendingModels() { | |
if (modelsPending_List != null && modelsPending_List.size() > 0) { | |
if (models_List != null && models_List.size() > 0) { | |
throw new IllegalArgumentException("Need an error message"); | |
} | |
models(modelsPending_List); | |
} | |
} | |
@Override | |
public void addTo(EpoxyController controller) { | |
super.addTo(controller); | |
addPendingModels(); // flush models added by DSL | |
addWithDebugValidation(controller); | |
if (!assignedAttributes_epoxyGeneratedModel.get(6)) { | |
throw new IllegalStateException("A value is required for setModels"); | |
} | |
} |
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
// One extenstion generated per epoxy model, ex for `CarouselItemCustomView` | |
// Extension on concrete implementation `CarouselNoSnapModel_` to prevent call to `CarouselItemCustomViewModelBuilder.add(model)` from DSL | |
// The trick is when to generate this method, how to detect carousel / nested list. What if we introduce a `NestedList` interface? | |
inline fun CarouselNoSnapModel_.carouselItemCustomView( | |
modelInitializer: | |
CarouselItemCustomViewModelBuilder.() -> Unit | |
) { | |
add( | |
CarouselItemCustomViewModel_().apply { | |
modelInitializer() | |
} | |
) | |
} |
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
carouselNoSnap { | |
val lastPage = 10 | |
for (j in 0 until lastPage) { | |
carouselItemCustomView { | |
id("carousel $i-$j") | |
title("Page $j / $lastPage") | |
} | |
} | |
} |
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
// Epoxy model to implements to activate the nested dsl | |
interface NestedList { | |
fun setModels(models: List<EpoxyModel<*>?>) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment