content: package com.aditya.filebrowser.adapters;
  
  import android.content.Context;
  import android.support.v7.widget.RecyclerView;
  import android.view.GestureDetector;
  import android.view.MotionEvent;
  import android.view.View;
  
  /**
   * Created by Aditya on 4/14/2017.
   */
  
  public class CustomAdapterItemClickListener implements RecyclerView.OnItemTouchListener {
  
      private OnItemClickListener mListener;
      private boolean mFastScrolling = false;
  
      public interface OnItemClickListener {
          void onItemClick(View view, int position);
          void onItemLongClick(View view, int position);
      }
  
      GestureDetector mGestureDetector;
  
      public CustomAdapterItemClickListener(Context context, final RecyclerView recyclerView, OnItemClickListener listener) {
          mListener = listener;
          mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
              @Override
              public boolean onSingleTapUp(MotionEvent e) {
                  return true;
              }
              @Override
              public void onLongPress(MotionEvent e){
                  View childView = recyclerView.findChildViewUnder(e.getX(), e.getY());
  
                  if(childView != null && mListener != null && !ismFastScrolling()){
                      mListener.onItemLongClick(childView, recyclerView.getChildAdapterPosition(childView));
                  }
              }
          });
      }
      @Override
      public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
          View childView = view.findChildViewUnder(e.getX(), e.getY());
          if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e) && !ismFastScrolling()) {
              mListener.onItemClick(childView, view.getChildAdapterPosition(childView));
          }
          return false;
      }
  
      @Override
      public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) {
      }
  
      @Override
      public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
  
      }
  
      public boolean ismFastScrolling() {
          return mFastScrolling;
      }
  
      public void setmFastScrolling(boolean mFastScrollFlag) {
          this.mFastScrolling = mFastScrollFlag;
      }
  }