<commit_before>package com.karcompany.views.adapters;

/**
 * Created by pvkarthik on 2016-12-12.
 *
 * Recycler view adapter which displays data.
 */

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.karcompany.GitExplorerApplication;
import com.karcompany.R;
import com.karcompany.models.UserMetaData;
import com.karcompany.presenters.BrowseUsersPresenter;
import com.karcompany.utils.GlideUtils;
import com.paginate.Paginate;
import com.paginate.recycler.LoadingListItemCreator;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

public class BrowseUsersAdapter extends RecyclerView.Adapter<UserListItemViewHolder> {

	private Fragment mFragment;
	private Context mContext;
	private Map<Long, UserMetaData> mDataMap;
	private List<Long> mDataList;
	private RecyclerView mRecyclerView;
	private Paginate mPaginate;

	@Inject
	BrowseUsersPresenter mBrowseUsersPresenter;

	private final View.OnClickListener mOnClickListener = new View.OnClickListener() {
		@Override
		public void onClick(View view) {
			int itemPosition = (Integer) view.getTag();
			//int itemPosition = mRecyclerView.getChildLayoutPosition(view);
			Long item = mDataList.get(itemPosition);
			//Toast.makeText(mContext, item, Toast.LENGTH_LONG).show();
			mBrowseUsersPresenter.onUserSelected(mDataMap.get(item));
		}
	};

	public BrowseUsersAdapter(Fragment fragment, RecyclerView recyclerView) {
		GitExplorerApplication.getApplicationComponent().inject(this);
		mFragment = fragment;
		mContext = fragment.getContext();
		mDataMap = new LinkedHashMap<>();
		mDataList = new ArrayList<>(4);
		mRecyclerView = recyclerView;
	}

	@Override
	public UserListItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
		View view = LayoutInflater.from(mContext).inflate(R.layout.view_user_row_item, parent, false);
		return new UserListItemViewHolder(view);
	}

	@Override
	public void onBindViewHolder(UserListItemViewHolder holder, int position) {
		if(position < mDataList.size()) {
			UserMetaData userMetaData = mDataMap.get(mDataList.get(position));
			if(userMetaData != null) {
				holder.nameTxtView.setText(userMetaData.getLogin());
			} else {
				holder.nameTxtView.setText("");
			}
			GlideUtils.loadImageWithNoCache(mFragment, userMetaData.getAvatarUrl(), holder.profileImgView);
		}
		holder.itemView.setTag(position);
		holder.itemView.setOnClickListener(mOnClickListener);
		/*if(position > mLastPosition) {
			Animation animation = AnimationUtils.loadAnimation(mContext,
					R.anim.up_bottom);
			holder.itemView.startAnimation(animation);
			mLastPosition = position;
		}*/
	}

	@Override
	public int getItemCount() {
		return mDataList.size();
	}

	public void addData(UserMetaData[] userList) {
		if(userList != null) {
			for (UserMetaData userMetaData:userList) {
				mDataMap.put(userMetaData.getId(), userMetaData);
			}
			int oldSize = mDataList.size();<commit_msg>Cleanup glide resources.<commit_after>package com.karcompany.views.adapters;

/**
 * Created by pvkarthik on 2016-12-12.
 *
 * Recycler view adapter which displays data.
 */

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;
import com.karcompany.GitExplorerApplication;
import com.karcompany.R;
import com.karcompany.models.UserMetaData;
import com.karcompany.presenters.BrowseUsersPresenter;
import com.karcompany.utils.GlideUtils;
import com.paginate.Paginate;
import com.paginate.recycler.LoadingListItemCreator;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

public class BrowseUsersAdapter extends RecyclerView.Adapter<UserListItemViewHolder> {

	private Fragment mFragment;
	private Context mContext;
	private Map<Long, UserMetaData> mDataMap;
	private List<Long> mDataList;
	private RecyclerView mRecyclerView;
	private Paginate mPaginate;

	@Inject
	BrowseUsersPresenter mBrowseUsersPresenter;

	private final View.OnClickListener mOnClickListener = new View.OnClickListener() {
		@Override
		public void onClick(View view) {
			int itemPosition = (Integer) view.getTag();
			Long item = mDataList.get(itemPosition);
			mBrowseUsersPresenter.onUserSelected(mDataMap.get(item));
		}
	};

	public BrowseUsersAdapter(Fragment fragment, RecyclerView recyclerView) {
		GitExplorerApplication.getApplicationComponent().inject(this);
		mFragment = fragment;
		mContext = fragment.getContext();
		mDataMap = new LinkedHashMap<>();
		mDataList = new ArrayList<>(4);
		mRecyclerView = recyclerView;
	}

	@Override
	public UserListItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
		View view = LayoutInflater.from(mContext).inflate(R.layout.view_user_row_item, parent, false);
		return new UserListItemViewHolder(view);
	}

	@Override
	public void onBindViewHolder(UserListItemViewHolder holder, int position) {
		if(position < mDataList.size()) {
			UserMetaData userMetaData = mDataMap.get(mDataList.get(position));
			if(userMetaData != null) {
				holder.nameTxtView.setText(userMetaData.getLogin());
			} else {
				holder.nameTxtView.setText("");
			}
			GlideUtils.loadImageWithNoCache(mFragment, userMetaData.getAvatarUrl(), holder.profileImgView);
		}
		holder.itemView.setTag(position);
		holder.itemView.setOnClickListener(mOnClickListener);
	}

	@Override
	public void onViewRecycled(UserListItemViewHolder holder) {
		Glide.clear(holder.profileImgView);
		holder.profileImgView.setImageDrawable(null);
		super.onViewRecycled(holder);
	}

	@Override
	public int getItemCount() {
		return mDataList.size();
	}

	public void addData(UserMetaData[] userList) {
		if(userList != null) {
			for (UserMetaData userMetaData:userList) {
				mDataMap.put(userMetaData.getId(), userMetaData);
			}
			int oldSize = mDataList.size();
{'fraction_non_alphanumeric': 0.10358242827038418, 'fraction_numerical': 0.003566218187712757, 'mean_word_length': 5.663066954643629, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 14, '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': '6443721', 'n_tokens_mistral': 2079, 'n_tokens_neox': 1926, 'n_words': 366}