<commit_before>package com.afollestad.photoaffix.adapters;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.afollestad.dragselectrecyclerview.DragSelectRecyclerViewAdapter;
import com.afollestad.photoaffix.R;
import com.afollestad.photoaffix.data.Photo;
import com.afollestad.photoaffix.data.PhotoHolder;
import com.afollestad.photoaffix.ui.MainActivity;
import com.bumptech.glide.Glide;

import java.util.ArrayList;

import butterknife.ButterKnife;

/**
 * @author <NAME> (afollestad)
 */
public class PhotoGridAdapter extends DragSelectRecyclerViewAdapter<PhotoGridAdapter.PhotoViewHolder> {

    public PhotoGridAdapter(MainActivity context) {
        mContext = context;
    }

    private MainActivity mContext;
    private Photo[] mPhotos;

    @Override
    public void saveInstanceState(Bundle out) {
        super.saveInstanceState(out);
        if (mPhotos != null)
            out.putSerializable("photos", new PhotoHolder(mPhotos));
    }

    @Override
    public void restoreInstanceState(Bundle in) {
        super.restoreInstanceState(in);
        if (in != null && in.containsKey("photos")) {
            PhotoHolder ph = (PhotoHolder) in.getSerializable("photos");
            if (ph != null) setPhotos(ph.photos);
        }
    }

    public void setPhotos(Photo[] photos) {
        mPhotos = photos;
        notifyDataSetChanged();
    }

    public Photo[] getSelectedPhotos() {
        Integer[] indices = getSelectedIndices();
        ArrayList<Photo> selected = new ArrayList<>();
        for (Integer index : indices) {
            if (index < 0) continue;
            selected.add(mPhotos[index]);
        }
        return selected.toArray(new Photo[selected.size()]);
    }

    @Override
    public PhotoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.griditem_photo, parent, false);
        return new PhotoViewHolder(v);
    }

    @Override
    public void onBindViewHolder(PhotoViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);

        Glide.with(mContext)
                .load(mPhotos[position].getUri())
                .into(holder.image);

        if (isIndexSelected(position)) {
            holder.check.setVisibility(View.VISIBLE);
            holder.circle.setActivated(true);
            holder.image.setActivated(true);
        } else {<commit_msg>Weird crash fix<commit_after>package com.afollestad.photoaffix.adapters;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.afollestad.dragselectrecyclerview.DragSelectRecyclerViewAdapter;
import com.afollestad.photoaffix.R;
import com.afollestad.photoaffix.data.Photo;
import com.afollestad.photoaffix.data.PhotoHolder;
import com.afollestad.photoaffix.ui.MainActivity;
import com.bumptech.glide.Glide;

import java.util.ArrayList;

import butterknife.ButterKnife;

/**
 * @author <NAME> (afollestad)
 */
public class PhotoGridAdapter extends DragSelectRecyclerViewAdapter<PhotoGridAdapter.PhotoViewHolder> {

    public PhotoGridAdapter(MainActivity context) {
        mContext = context;
    }

    private MainActivity mContext;
    private Photo[] mPhotos;

    @Override
    public void saveInstanceState(Bundle out) {
        super.saveInstanceState(out);
        if (mPhotos != null)
            out.putSerializable("photos", new PhotoHolder(mPhotos));
    }

    @Override
    public void restoreInstanceState(Bundle in) {
        super.restoreInstanceState(in);
        if (in != null && in.containsKey("photos")) {
            PhotoHolder ph = (PhotoHolder) in.getSerializable("photos");
            if (ph != null) setPhotos(ph.photos);
        }
    }

    public void setPhotos(Photo[] photos) {
        mPhotos = photos;
        notifyDataSetChanged();
    }

    public Photo[] getSelectedPhotos() {
        Integer[] indices = getSelectedIndices();
        ArrayList<Photo> selected = new ArrayList<>();
        for (Integer index : indices) {
            if (index < 0) continue;
            selected.add(mPhotos[index]);
        }
        return selected.toArray(new Photo[selected.size()]);
    }

    @Override
    public PhotoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.griditem_photo, parent, false);
        return new PhotoViewHolder(v);
    }

    @Override
    public void onBindViewHolder(PhotoViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        if (mContext == null || mContext.isFinishing()) return;

        Glide.with(mContext)
                .load(mPhotos[position].getUri())
                .into(holder.image);

        if (isIndexSelected(position)) {
            holder.check.setVisibility(View.VISIBLE);
            holder.circle.setActivated(true);
            holder.image.setActivated(true);
        } else {
{'fraction_non_alphanumeric': 0.1056632459141011, 'fraction_numerical': 0.0007601672367920942, 'mean_word_length': 3.0703789636504255, 'pattern_counts': {'":': 0, '<': 13, '<?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': '6722528', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1469, 'n_words': 291}