<commit_before>package com.tippingcanoe.dewey;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

class DeweyLayoutManager extends LinearLayoutManager {
	int uniformCellWidth = 0;
	int forcedCellWidth = 0;

	public DeweyLayoutManager(Context context, int uniformCellWidth) {
		super(context);
		this.uniformCellWidth = uniformCellWidth;
	}

	public DeweyLayoutManager(Context context, int orientation, boolean reverseLayout, int uniformCellWidth) {
		super(context, orientation, reverseLayout);
		this.uniformCellWidth = uniformCellWidth;
	}

	public DeweyLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes, int uniformCellWidth) {
		super(context, attrs, defStyleAttr, defStyleRes);
		this.uniformCellWidth = uniformCellWidth;
	}

	@Override
	public void onMeasure ( RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec ) {
		if ( View.MeasureSpec.getMode(heightSpec) != View.MeasureSpec.EXACTLY ) {
			int height = measureFirstChildHeight(recycler);
			heightSpec = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY);
		}

		super.onMeasure(recycler, state, widthSpec, heightSpec);
	}

	protected int measureFirstChildHeight(RecyclerView.Recycler recycler) {
		View view = getItemCount() == 0 ? null : recycler.getViewForPosition(0);

		if (view != null) {
			RecyclerView.LayoutParams p = (RecyclerView.LayoutParams) view.getLayoutParams();

			int childHeightSpec = ViewGroup.getChildMeasureSpec(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), getPaddingTop() + getPaddingBottom(), p.height);
			view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), childHeightSpec);

			int height = view.getMeasuredHeight() + p.bottomMargin + p.topMargin;

			detachView(view);

			return height;
		}

		return 0;
	}

	@Override
	public RecyclerView.LayoutParams generateDefaultLayoutParams() {
		return updateLayoutParamsForUniformWidthIfNeeded(super.generateDefaultLayoutParams());
	}

	@Override
	public RecyclerView.LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp) {
		return updateLayoutParamsForUniformWidthIfNeeded(super.generateLayoutParams(lp));
	}


	@Override
	public RecyclerView.LayoutParams generateLayoutParams(Context c, AttributeSet attrs) {
		return updateLayoutParamsForUniformWidthIfNeeded(super.generateLayoutParams(c, attrs));
	}

	@Override
	public boolean checkLayoutParams(RecyclerView.LayoutParams lp) {
		return super.checkLayoutParams(lp) && (forcedCellWidth == 0 || lp.width == forcedCellWidth);
	}

	protected RecyclerView.LayoutParams updateLayoutParamsForUniformWidthIfNeeded ( RecyclerView.LayoutParams layoutParams ) {
		if ( forcedCellWidth != 0 ) {
			layoutParams.width = forcedCellWidth;
		}

		return layoutParams;
	}

	public boolean areCellsUniform() {
		return uniformCellWidth > 0;
	}

	public int getUniformCellWidth() {
		return uniformCellWidth;
	}

	protected void updateUniformCellWidth() {
		if ( areCellsUniform() && (uniformCellWidth * getItemCount()) < getWidth() ) {
			forcedCellWidth = (int) ((float) getWidth() / (float) getItemCount());
		}
	}

	public void setUniformCellWidth(int uniformCellWidth) {
		this.uniformCellWidth = uniformCellWidth;
	}
}<commit_msg>Getting rid of some measuring hell. Do it yourself :p<commit_after>package com.tippingcanoe.dewey;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

class DeweyLayoutManager extends LinearLayoutManager {
	int uniformCellWidth = 0;
	int forcedCellWidth = 0;

	public DeweyLayoutManager(Context context, int uniformCellWidth) {
		super(context);
		this.uniformCellWidth = uniformCellWidth;
		updateUniformCellWidth();
	}

	public DeweyLayoutManager(Context context, int orientation, boolean reverseLayout, int uniformCellWidth) {
		super(context, orientation, reverseLayout);
		this.uniformCellWidth = uniformCellWidth;
		updateUniformCellWidth();
	}

	public DeweyLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes, int uniformCellWidth) {
		super(context, attrs, defStyleAttr, defStyleRes);
		this.uniformCellWidth = uniformCellWidth;
		updateUniformCellWidth();
	}

	@Override
	public void onMeasure ( RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec ) {
		if ( View.MeasureSpec.getMode(heightSpec) != View.MeasureSpec.EXACTLY ) {
			int height = measureFirstChildHeight(recycler);
			heightSpec = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY);
		}

		super.onMeasure(recycler, state, widthSpec, heightSpec);

		updateUniformCellWidth();
	}

	protected int measureFirstChildHeight(RecyclerView.Recycler recycler) {
		View view = getItemCount() == 0 ? null : recycler.getViewForPosition(0);

		if (view != null) {
			RecyclerView.LayoutParams p = (RecyclerView.LayoutParams) view.getLayoutParams();

			int childHeightSpec = ViewGroup.getChildMeasureSpec(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), getPaddingTop() + getPaddingBottom(), p.height);
			view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), childHeightSpec);

			int height = view.getMeasuredHeight() + p.bottomMargin + p.topMargin;

			detachView(view);

			return height;
		}

		return 0;
	}

	@Override
	public RecyclerView.LayoutParams generateDefaultLayoutParams() {
		return updateLayoutParamsForUniformWidthIfNeeded(super.generateDefaultLayoutParams());
	}

	@Override
	public RecyclerView.LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp) {
		return updateLayoutParamsForUniformWidthIfNeeded(super.generateLayoutParams(lp));
	}


	@Override
	public RecyclerView.LayoutParams generateLayoutParams(Context c, AttributeSet attrs) {
		return updateLayoutParamsForUniformWidthIfNeeded(super.generateLayoutParams(c, attrs));
	}

	@Override
	public boolean checkLayoutParams(RecyclerView.LayoutParams lp) {
		return super.checkLayoutParams(lp) && (forcedCellWidth == 0 || lp.width == forcedCellWidth);
	}

	protected RecyclerView.LayoutParams updateLayoutParamsForUniformWidthIfNeeded ( RecyclerView.LayoutParams layoutParams ) {
		if ( forcedCellWidth != 0 ) {
			layoutParams.width = forcedCellWidth;
		}

		return layoutParams;
	}

	public boolean areCellsUniform() {
		return uniformCellWidth > 0;
	}

	public int getUniformCellWidth() {
		return uniformCellWidth;
	}

	protected void updateUniformCellWidth() {
		if ( areCellsUniform() && (uniformCellWidth * getItemCount()) < getWidth() ) {
			forcedCellWidth = (int) ((float) getWidth() / (float) getItemCount());
		}
	}

	public void setUniformCellWidth(int uniformCellWidth) {
		this.uniformCellWidth = uniformCellWidth;
		updateUniformCellWidth();
	}
}
{'fraction_non_alphanumeric': 0.09483861794397838, 'fraction_numerical': 0.0034124840039812315, 'mean_word_length': 6.026973026973027, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7660903', 'n_tokens_mistral': 2226, 'n_tokens_neox': 2025, 'n_words': 418}