Cancel long press when moving screen

This commit is contained in:
Lucas Lima 2021-01-07 09:40:37 -03:00
parent c60f7f46ec
commit 01b5546fbb
No known key found for this signature in database
GPG key ID: 049CCC5A365B00D2

View file

@ -110,6 +110,13 @@ class AreaAdapter(
var longClickJob: Job? = null
view.setOnTouchListener { _, motionEvent ->
when (motionEvent.action) {
MotionEvent.ACTION_MOVE -> {
longClickJob?.let { job ->
job.cancel()
longClickJob = null
}
true
}
MotionEvent.ACTION_DOWN -> {
view.isPressed = true
longClickJob = coroutineScope.launch {
@ -164,6 +171,11 @@ class AreaAdapter(
}
}
}
} else {
longClickJob?.let { job ->
job.cancel()
longClickJob = null
}
}
handled
}