fixing some long touch related issues

This commit is contained in:
tibbi 2022-09-25 16:29:14 +02:00
parent d5368b0a15
commit 07ea589c73

View file

@ -21,6 +21,7 @@ import kotlinx.android.synthetic.main.all_apps_fragment.view.*
class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment(context, attributeSet), AllAppsListener { class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment(context, attributeSet), AllAppsListener {
private var touchDownY = -1 private var touchDownY = -1
private var lastTouchCoords = Pair(0f, 0f)
var ignoreTouches = false var ignoreTouches = false
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
@ -51,15 +52,19 @@ class AllAppsFragment(context: Context, attributeSet: AttributeSet) : MyFragment
override fun onInterceptTouchEvent(event: MotionEvent): Boolean { override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
if (ignoreTouches) { if (ignoreTouches) {
touchDownY = -1 // some devices ACTION_MOVE keeps triggering for the whole long press duration, but we are interested in real moves only, when coords change
return true if (lastTouchCoords.first != event.x || lastTouchCoords.second != event.y) {
touchDownY = -1
return true
}
} }
lastTouchCoords = Pair(event.x, event.y)
var shouldIntercept = false var shouldIntercept = false
// pull the whole fragment down if it is scrolled way to the top and the users pulls it even further // pull the whole fragment down if it is scrolled way to the top and the users pulls it even further
if (touchDownY != -1) { if (touchDownY != -1) {
shouldIntercept = touchDownY - event.y < 0 && all_apps_grid.computeVerticalScrollOffset() == 0 shouldIntercept = touchDownY - event.y.toInt() < 0 && all_apps_grid.computeVerticalScrollOffset() == 0
if (shouldIntercept) { if (shouldIntercept) {
activity?.startHandlingTouches(touchDownY) activity?.startHandlingTouches(touchDownY)
touchDownY = -1 touchDownY = -1