<commit_before>package com.timehop.stickyheadersrecyclerview;

import android.graphics.Canvas;
import android.graphics.Rect;
import android.support.v4.util.LongSparseArray;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;

public class StickyRecyclerHeadersDecoration extends RecyclerView.ItemDecoration {
  private final StickyRecyclerHeadersAdapter mAdapter;
  private final LongSparseArray<View> mHeaderViews = new LongSparseArray<>();
  private final SparseArray<Rect> mHeaderRects = new SparseArray<>();

  public StickyRecyclerHeadersDecoration(StickyRecyclerHeadersAdapter adapter) {
    mAdapter = adapter;
  }

  @Override
  public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    super.getItemOffsets(outRect, view, parent, state);
    int orientation = getOrientation(parent);
    int itemPosition = parent.getChildPosition(view);
    if (hasNewHeader(itemPosition)) {
      View header = getHeaderView(parent, itemPosition);
      if (orientation == LinearLayoutManager.VERTICAL) {
        outRect.top = header.getHeight();
      } else {
        outRect.left = header.getWidth();
      }
    }
  }

  @Override
  public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    super.onDrawOver(canvas, parent, state);
    int orientation = getOrientation(parent);
    mHeaderRects.clear();

    if (parent.getChildCount() > 0 && mAdapter.getItemCount() > 0) {
      // draw the first visible child's header at the top of the view
      View firstView = parent.getChildAt(0);
      int firstPosition = parent.getChildPosition(firstView);
      if (mAdapter.getHeaderId(firstPosition) > 0) {
        View firstHeader = getHeaderView(parent, firstPosition);
        View nextView = getNextView(parent);
        int translationX = Math.max(parent.getChildAt(0).getLeft() - firstHeader.getWidth(), 0);
        int translationY = Math.max(parent.getChildAt(0).getTop() - firstHeader.getHeight(), 0);
        int nextPosition = parent.getChildPosition(nextView);
        if (nextPosition > 0 && hasNewHeader(nextPosition)) {
          View secondHeader = getHeaderView(parent, nextPosition);
          //Translate the topmost header so the next header takes its place, if applicable
          if (orientation == LinearLayoutManager.VERTICAL &&
              nextView.getTop() - secondHeader.getHeight() - firstHeader.getHeight() < 0) {<commit_msg>Draw headers with header ID = 0<commit_after>package com.timehop.stickyheadersrecyclerview;

import android.graphics.Canvas;
import android.graphics.Rect;
import android.support.v4.util.LongSparseArray;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;

public class StickyRecyclerHeadersDecoration extends RecyclerView.ItemDecoration {
  private final StickyRecyclerHeadersAdapter mAdapter;
  private final LongSparseArray<View> mHeaderViews = new LongSparseArray<>();
  private final SparseArray<Rect> mHeaderRects = new SparseArray<>();

  public StickyRecyclerHeadersDecoration(StickyRecyclerHeadersAdapter adapter) {
    mAdapter = adapter;
  }

  @Override
  public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    super.getItemOffsets(outRect, view, parent, state);
    int orientation = getOrientation(parent);
    int itemPosition = parent.getChildPosition(view);
    if (hasNewHeader(itemPosition)) {
      View header = getHeaderView(parent, itemPosition);
      if (orientation == LinearLayoutManager.VERTICAL) {
        outRect.top = header.getHeight();
      } else {
        outRect.left = header.getWidth();
      }
    }
  }

  @Override
  public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    super.onDrawOver(canvas, parent, state);
    int orientation = getOrientation(parent);
    mHeaderRects.clear();

    if (parent.getChildCount() > 0 && mAdapter.getItemCount() > 0) {
      // draw the first visible child's header at the top of the view
      View firstView = parent.getChildAt(0);
      int firstPosition = parent.getChildPosition(firstView);
      if (mAdapter.getHeaderId(firstPosition) >= 0) {
        View firstHeader = getHeaderView(parent, firstPosition);
        View nextView = getNextView(parent);
        int translationX = Math.max(parent.getChildAt(0).getLeft() - firstHeader.getWidth(), 0);
        int translationY = Math.max(parent.getChildAt(0).getTop() - firstHeader.getHeight(), 0);
        int nextPosition = parent.getChildPosition(nextView);
        if (nextPosition > 0 && hasNewHeader(nextPosition)) {
          View secondHeader = getHeaderView(parent, nextPosition);
          //Translate the topmost header so the next header takes its place, if applicable
          if (orientation == LinearLayoutManager.VERTICAL &&
              nextView.getTop() - secondHeader.getHeight() - firstHeader.getHeight() < 0) {
{'fraction_non_alphanumeric': 0.09881805851579151, 'fraction_numerical': 0.0052315442743654334, 'mean_word_length': 4.126117179741807, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3528590', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1422, 'n_words': 343}