Skip to content

Instantly share code, notes, and snippets.

@GeorgCantor
Created March 14, 2021 18:10
Show Gist options
  • Save GeorgCantor/871678b654700815cd8c95a61b58abd9 to your computer and use it in GitHub Desktop.
Save GeorgCantor/871678b654700815cd8c95a61b58abd9 to your computer and use it in GitHub Desktop.
view.setOnTouchListener { _, event ->
val x = event.x.toInt() + 200
val y = event.y.toInt()
if (pickMode != 5 && event.action == ACTION_DOWN) {
viewModel.products.observeOnce(viewLifecycleOwner) { products ->
products.forEach {
if (it.rectName?.contains(x, y) == true && it.isVisible) {
findNavController().navigate(
R.id.action_pickFragment_to_productFragment,
bundleOf(PRODUCT_ID to it.id.toString())
)
}
if (it.rectButton?.contains(x, y) == true && it.isVisible) {
if (pickMode != 0) {
when (it.clickStatus) {
0 -> {
beginDelayedTransition(scan, btn_complete.getTransform(pick_window))
btn_complete.gone()
pick_window.visible()
lastProduct = it
}
1 -> {
val list = mutableListOf<PickProduct>()
dProducts.forEach { product ->
if (product.id != it.id) list.add(product)
}
dProducts = list
}
}
}
when (pickMode) {
1 -> {
pick_note.text = getString(R.string.enter_number_accepted_units)
pick_quantity.inputType = TYPE_CLASS_NUMBER
}
2 -> pick_note.text = getString(R.string.enter_product_length)
3 -> pick_note.text = getString(R.string.enter_product_weight)
4 -> pick_note.text = getString(R.string.enter_product_volume)
}
viewModel.setClickStatus(
Product(it.id, it.name, it.rectName, it.rectButton, if (it.clickStatus == 0) 1 else 0)
)
}
}
}
}
true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment