Created
November 15, 2020 14:00
-
-
Save vshkl/0718d2735af689713e435e14d6c8453a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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