<commit_before>package io.rover.ui;

import android.graphics.drawable.GradientDrawable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import io.rover.R;
import io.rover.model.Block;
import io.rover.model.Row;

/**
 * Created by ata_n on 2016-06-28.
 */
public class RowsAdapter extends RecyclerView.Adapter<RowsAdapter.ViewHolder> implements BlockLayoutManager.BlockProvider {

    private List<Row> mRows;
    private float screenDensity;

    public RowsAdapter(List<Row> rows, float density) {
        mRows = rows;
        screenDensity = density;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View blockView = inflater.inflate(R.layout.text_block, parent, false);
        ViewHolder viewHolder = new ViewHolder(blockView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Block block = null;

        int count = 0;
        for (int i = 0; i < mRows.size(); i++) {
            List<Block> blocks = mRows.get(i).getBlocks();
            int index = position - count;
            if (index < blocks.size()) {
                block = blocks.get(index);
                break;
            }
            count += blocks.size();
        }

        if (block == null) { return; }

        GradientDrawable borderDrawable = new GradientDrawable();
        borderDrawable.setColor(block.getBackgroundColor());
        borderDrawable.setStroke((int)(block.getBorderWidth() * screenDensity), block.getBorderColor());
        borderDrawable.setCornerRadius((float)(block.getBorderRadius() * screenDensity));
        holder.itemView.setBackground(borderDrawable);



    }

    @Override
    public int getItemCount() {
        int numBlocks = 0;
        for (Row row : mRows) {
            numBlocks += row.getBlocks().size();
        }
        return numBlocks;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        public ViewHolder(View itemView) {
            super(itemView);
        }
    }

    @Override
    public int getRowCount() {
        return mRows.size();
    }

    @Override
    public Row getRow(int index) {
        return mRows.get(index);
    }
}<commit_msg>make separate view holders for each block type<commit_after>package io.rover.ui;

import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import io.rover.R;
import io.rover.model.Block;
import io.rover.model.ImageBlock;
import io.rover.model.Row;
import io.rover.model.TextBlock;

/**
 * Created by ata_n on 2016-06-28.
 */
public class RowsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements BlockLayoutManager.BlockProvider {

    private List<Row> mRows;
    private float screenDensity;

    public RowsAdapter(List<Row> rows, float density) {
        mRows = rows;
        screenDensity = density;
    }

    @Override
    public int getItemViewType(int position) {
        Block block = getBlockAtPosition(position);
        if (block instanceof ImageBlock) {
            return 0;
        } else if (block instanceof TextBlock) {
            return 1;
        }
        return super.getItemViewType(position);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        switch (viewType) {
            case 0: return new ImageViewHolder(parent.getContext());
            case 1: return new TextViewHolder(parent.getContext());
            default: return new ViewHolder(parent.getContext());
        }
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        Block block = getBlockAtPosition(position);

        if (block == null) { return; }

        // Appearance

        GradientDrawable borderDrawable = new GradientDrawable();
        borderDrawable.setColor(block.getBackgroundColor());
        borderDrawable.setStroke((int)(block.getBorderWidth() * screenDensity), block.getBorderColor());
        borderDrawable.setCornerRadius((float)(block.getBorderRadius() * screenDensity));
        holder.itemView.setBackground(borderDrawable);
    }

    @Override
    public int getItemCount() {
        int numBlocks = 0;
        for (Row row : mRows) {
            numBlocks += row.getBlocks().size();
        }
        return numBlocks;
    }

    @Override
    public int getRowCount() {
        return mRows.size();
    }

    @Override
    public Row getRow(int index) {
        return mRows.get(index);
    }

    private Block getBlockAtPosition(int position) {
        Block block = null;

        int count = 0;
        for (int i = 0; i < mRows.size(); i++) {
            List<Block> blocks = mRows.get(i).getBlocks();
            int index = position - count;
            if (index < blocks.size()) {
                block = blocks.get(index);
                break;
            }
            count += blocks.size();
        }

        return block;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public ViewHolder(Context context) {
            super(new View(context));
        }
    }

    public static class ImageViewHolder extends RecyclerView.ViewHolder {
        public ImageViewHolder(Context context) { super(new View(context)); }
    }

    public static class TextViewHolder extends RecyclerView.ViewHolder {
        public TextViewHolder(Context context) { super(new View(context)); }
    }


}
{'fraction_non_alphanumeric': 0.10036088675030073, 'fraction_numerical': 0.004811823337343186, 'mean_word_length': 2.5859519408502774, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, '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': '4325584', 'n_tokens_mistral': 1662, 'n_tokens_neox': 1594, 'n_words': 383}