From 01b5546fbb47be324afa0db7675d1d616e72cffe Mon Sep 17 00:00:00 2001 From: Lucas Lima Date: Thu, 7 Jan 2021 09:40:37 -0300 Subject: [PATCH] Cancel long press when moving screen --- .../antimine/common/level/view/AreaAdapter.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaAdapter.kt b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaAdapter.kt index d131bb81..825b93eb 100644 --- a/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaAdapter.kt +++ b/common/src/main/java/dev/lucasnlm/antimine/common/level/view/AreaAdapter.kt @@ -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 }