private void initDefaultHeaderOffset(Rect headerMargins, RecyclerView recyclerView, View header, View firstView, int orientation) {
    int translationX, translationY;
    mDimensionCalculator.initMargins(mTempRect1, header);

    ViewGroup.LayoutParams layoutParams = firstView.getLayoutParams();
    int leftMargin = 0;
    int topMargin = 0;
    if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
      ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams;
      leftMargin = marginLayoutParams.leftMargin;
      topMargin = marginLayoutParams.topMargin;
    }

    if (orientation == LinearLayoutManager.VERTICAL) {
      translationX = firstView.getLeft() - leftMargin + mTempRect1.left;
      translationY = Math.max(
          firstView.getTop() - topMargin - header.getHeight() - mTempRect1.bottom,
          getListTop(recyclerView) + mTempRect1.top);
    } else {
      translationY = firstView.getTop() - topMargin + mTempRect1.top;
      translationX = Math.max(
          firstView.getLeft() - leftMargin - header.getWidth() - mTempRect1.right,
          getListLeft(recyclerView) + mTempRect1.left);
    }

    headerMargins.set(translationX, translationY, translationX + header.getWidth(),
            translationY + header.getHeight());
  }
Determines if an item in the list should have a header that is different than the item in the
list that immediately precedes it. Items with no headers will always return false.

@param position of the list item in questions
@param isReverseLayout TRUE if layout manager has flag isReverseLayout
@return true if this item has a different header than the previous item in the list
library/src/main/java/com/timehop/stickyheadersrecyclerview/HeaderPositionCalculator.java