package com.pr0gramm.app.ui;

import android.view.MotionEvent;
import android.view.View;

import rx.functions.Action0;

/**
 * Detects single taps.
 */
public class DetectTapTouchListener implements View.OnTouchListener {
    private final Action0 consumer;
    private boolean moveOccurred;

    private DetectTapTouchListener(Action0 consumer) {
        this.consumer = consumer;
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (event.getActionIndex() == 0) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                moveOccurred = false;
            }

            if (event.getAction() == MotionEvent.ACTION_MOVE) {
                moveOccurred = true;
            }

            if (event.getAction() == MotionEvent.ACTION_UP) {
                if (!moveOccurred) {
                    consumer.call();
                    return true;
                }

                moveOccurred = false;
            }
        }

        return false;
    }

    public static DetectTapTouchListener withConsumer(Action0 consumer) {
        return new DetectTapTouchListener(consumer);
    }
}

@@ -284,16 +284,68 @@
 ccurred;
+%0A    private float firstX;%0A    private float firstY;
 %0A%0A    pr
@@ -641,32 +641,110 @@
 curred = false;%0A
+                firstX = event.getX();%0A                firstY = event.getY();%0A
             %7D%0A%0A 
@@ -837,20 +837,156 @@
 urred = 
-true
+moveOccurred%0A                        %7C%7C Math.abs(event.getX() - firstX) %3E 32%0A                        %7C%7C Math.abs(event.getY() - firstY) %3E 32
 ;%0A      
@@ -1163,16 +1163,16 @@
 n true;%0A
+
         
@@ -1184,47 +1184,8 @@
    %7D
-%0A%0A                moveOccurred = false;
 %0A   

Improve tap detection