Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// blueprint
open class EpoxyModel {
fun bind() {}
}
class Factory(
val key: Int,
val createModel: (Any) -> EpoxyModel
)
class StrategyExpoxyController { // extend from Type2Controller<List<Any>,Boolean>
private val factories: SparseArray<Factory> = SparseArray();
fun registerFactory(factory: Factory) {
factories.append(factory.key, factory)
}
fun buildModels(list: List<*>) {
for (data in list) {
data?.run {
factories[this::class.java.hashCode()]?.createModel?.invoke(this) // add bind this
}
}
}
//usage
class Data1 {}
class Data1Model : EpoxyModel() {}
// declare factory
val modelCreation: (Data1) -> EpoxyModel = { Data1Model() }
val factory1 = Factory(key = Data1::class.java.hashCode(), createModel = modelCreation as (Any) -> EpoxyModel)
// in fragment
val controller = StrategyExpoxyController().apply {
registerFactory(factory1)
// more registration here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.