Skip to content

Instantly share code, notes, and snippets.

@vshkl
Created November 15, 2020 14:00
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 vshkl/0718d2735af689713e435e14d6c8453a to your computer and use it in GitHub Desktop.
Save vshkl/0718d2735af689713e435e14d6c8453a to your computer and use it in GitHub Desktop.
class MainController(
private val callbackAdapter: MainCallbackAdapter
) : EpoxyController() {
private var firstRows = emptyList<Row>()
private var secondRows = emptyList<Row>()
override fun buildModels() {
header {
id("header", "1")
titleRes(R.string.txt_header_one)
}
firstRows.map { row ->
row {
id(row.id)
rowId(row.id)
title(row.title)
onDragHandleTouchListener(this@MainController::onRowDragHandleTouched)
}
}
header {
id("header", "2")
titleRes(R.string.txt_header_two)
}
secondRows.map { row ->
row {
id(row.id)
rowId(row.id)
title(row.title)
onDragHandleTouchListener(this@MainController::onRowDragHandleTouched)
}
}
}
fun setFirstRowsData(firstRowsData: List<Row>) {
this.firstRows = firstRowsData
requestModelBuild()
}
fun setSecondRowsData(secondRowsData: List<Row>) {
this.secondRows = secondRowsData
requestModelBuild()
}
private fun onRowDragHandleTouched(view: View, event: MotionEvent): Boolean {
if (event.action == MotionEvent.ACTION_DOWN) {
callbackAdapter.onDragStart()
}
return view.performClick()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment