Skip to content

Instantly share code, notes, and snippets.

@Judrummer
Last active February 28, 2017 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Judrummer/75cd51057f6139c7df5a79af264be058 to your computer and use it in GitHub Desktop.
Save Judrummer/75cd51057f6139c7df5a79af264be058 to your computer and use it in GitHub Desktop.
inline fun jxAdapter(builder: __JxAdapterBuilder.() -> Unit): JxAdapter {
val jxBuilder = __JxAdapterBuilder()
jxBuilder.builder()
return jxBuilder.build()
}
class __JxAdapterBuilder {
val __jxHolderList = mutableListOf<JxViewHolder<*>>()
var __jxDiffUtil: JxDiffUtil? = null
fun build(): JxAdapter = JxAdapter(__jxHolderList, __jxDiffUtil)
}
inline fun <reified T : Any> __JxAdapterBuilder.holder(itemLayoutId: Int, noinline bindHolder: RecyclerView.ViewHolder.(position: Int, item: T) -> Unit) {
__jxHolderList.add(JxViewHolder(itemLayoutId, bindHolder))
}
data class Task(val id: String)
fun test() {
jxAdapter {
holder<Task>(1) { position, item ->
}
holder<Task>(1) { position, item ->
}
holder<Task>(1) { position, item ->
}
holder<Task>(1) { position, item ->
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment