content: package io.agora.propeller.ui;
  
  import android.content.Context;
  import android.support.v7.widget.RecyclerView;
  import android.view.GestureDetector;
  import android.view.MotionEvent;
  import android.view.View;
  
  public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener {
  
      private OnItemClickListener mListener;
  
      public interface OnItemClickListener {
          void onItemClick(View view, int position);
  
          void onItemLongClick(View view, int position);
  
          void onItemDoubleClick(View view, int position);
      }
  
      private GestureDetector mGestureDetector;
  
      private RecyclerView mRv;
  
      public RecyclerItemClickListener(Context context, OnItemClickListener listener) {
          mListener = listener;
  
          mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
              @Override
              public boolean onSingleTapConfirmed(MotionEvent e) {
                  if (mRv == null) {
                      return false;
                  }
  
                  View child = mRv.findChildViewUnder(e.getX(), e.getY());
                  if (child != null && mListener != null) {
                      mListener.onItemClick(child, mRv.getChildAdapterPosition(child));
                  }
                  return true;
              }
  
              @Override
              public void onLongPress(MotionEvent e) {
                  if (mRv == null) {
                      return;
                  }
  
                  View child = mRv.findChildViewUnder(e.getX(), e.getY());
                  if (child != null && mListener != null) {
                      mListener.onItemLongClick(child, mRv.getChildAdapterPosition(child));
                  }
              }
  
              @Override
              public boolean onDoubleTap(MotionEvent e) {
                  if (mRv == null) {
                      return false;
                  }
  
                  View child = mRv.findChildViewUnder(e.getX(), e.getY());
                  if (child != null && mListener != null) {
                      mListener.onItemDoubleClick(child, mRv.getChildAdapterPosition(child));
                  }
                  return true;
              }
          });
      }
  
      @Override
      public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
          View childView = view.findChildViewUnder(e.getX(), e.getY());
          mRv = view;
  
          if (childView != null && mListener != null) {
              mGestureDetector.onTouchEvent(e);
          }
          return false;
      }
  
      @Override
      public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) {
      }
  
      @Override
      public void onRequestDisallowInterceptTouchEvent(boolean b) {
      }
  }
  