public static void removeFrom(RecyclerView recyclerView) {
    final ItemClickSupport itemClickSupport = from(recyclerView);
    if (itemClickSupport == null) {
      // TODO: Log warning
      return;
    }

    recyclerView.removeOnItemTouchListener(itemClickSupport.mTouchListener);
    recyclerView.setTag(R.id.twowayview_item_click_support, null);
  }
  public static ItemClickSupport addTo(RecyclerView recyclerView) {
    ItemClickSupport itemClickSupport = from(recyclerView);
    if (itemClickSupport == null) {
      itemClickSupport = new ItemClickSupport(recyclerView);
      recyclerView.setTag(R.id.twowayview_item_click_support, itemClickSupport);
    } else {
      // TODO: Log warning
    }

    return itemClickSupport;
  }
  public static ItemSelectionSupport addTo(RecyclerView recyclerView) {
    ItemSelectionSupport itemSelectionSupport = from(recyclerView);
    if (itemSelectionSupport == null) {
      itemSelectionSupport = new ItemSelectionSupport(recyclerView);
      recyclerView.setTag(R.id.recyclerview_item_selection_support, itemSelectionSupport);
    } else {
      // TODO: Log warning
    }

    return itemSelectionSupport;
  }
  public static ItemClickSupport addTo(RecyclerView recyclerView) {
    ItemClickSupport itemClickSupport = from(recyclerView);
    if (itemClickSupport == null) {
      itemClickSupport = new ItemClickSupport(recyclerView);
      recyclerView.setTag(R.id.twowayview_item_click_support, itemClickSupport);
    } else {
      Log.w("ItemClickSupport", "itemClickSupport is null");
    }

    return itemClickSupport;
  }
  public static void removeFrom(RecyclerView recyclerView) {
    final ItemSelectionSupport itemSelection = from(recyclerView);
    if (itemSelection == null) {
      // TODO: Log warning
      return;
    }

    itemSelection.clearChoices();

    recyclerView.removeOnItemTouchListener(itemSelection.mTouchListener);
    recyclerView.setTag(R.id.recyclerview_item_selection_support, null);
  }
 private void resetUILoadingState() {
   Object _state = mRecyclerView.getTag();
   // prevent unnecessary traffic
   if (_state != null && (_state instanceof Utils.State)) {
     ((Utils.State) _state).setPendingLoadMore(false);
   } else {
     Utils.State state = new Utils.State();
     state.setPendingLoadMore(false);
     _state = state;
   }
   mRecyclerView.setTag(_state);
   reInitializeScrollListener(mRecyclerView);
 }
  private void callForRemotePosts(boolean isPaginating) {
    String tag = getArguments().getString(K.KEY_TAG.name());

    // construct context from preferences if any?
    Bundle iArgs = new Bundle();

    if (isPaginating) {
      Object _state = mRecyclerView.getTag();
      // prevent unnecessary traffic
      if (_state != null && (_state instanceof Utils.State)) {
        if (((Utils.State) _state).isPendingLoadMore()) {
          return;
        }
      }

      Utils.State state = new Utils.State();
      state.setPendingLoadMore(true);
      mRecyclerView.setTag(state);

      //            Utils.PreferencesManager pref = Utils.PreferencesManager.getInstance();
      //            Map<String, String> entries =
      // pref.getValueAsMap(AppConstants.API.PREF_POSTS_LIST_USER.getValue());
      //            for (Map.Entry<String, String> e : entries.entrySet()) {
      //                iArgs.putString(e.getKey(), e.getValue());
      //            }
    }

    // context
    iArgs.putString(KEY_BY.getValue(), KEY_POSTS_SEARCH.getValue());
    iArgs.putString(KEY_KEY.getValue(), tag);

    // call for intent
    Intent mServiceIntent = new Intent(mActivity, PostsPullService.class);
    mServiceIntent.putExtras(iArgs);
    mActivity.startService(mServiceIntent);
  }
 private ItemClickSupport(RecyclerView recyclerView) {
   mRecyclerView = recyclerView;
   mRecyclerView.setTag(R.id.item_click_support, this);
   mRecyclerView.addOnChildAttachStateChangeListener(mAttachListener);
 }
 private void detach(RecyclerView view) {
   view.removeOnChildAttachStateChangeListener(mAttachListener);
   view.setTag(R.id.item_click_support, null);
 }