<commit_before>package com.dev.bins.shop.fragment.Cart;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.dev.bins.shop.R;
import com.dev.bins.shop.bean.Cart;
import com.dev.bins.shop.bean.GoodsItem;
import com.dev.bins.shop.widget.CountView;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by bin on 25/02/2017.
 */

public class CartAdapter extends RecyclerView.Adapter<CartAdapter.Holder> {


    private List<GoodsItem> mCards;
    private Context mContext;
    CartFragment mCartFragment;
    public CartAdapter(List<GoodsItem> cards, CartFragment cartFragment) {
        this.mCards = cards;
        mCartFragment = cartFragment;
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        mContext = parent.getContext();
        return new Holder(LayoutInflater.from(parent.getContext()).inflate(R.layout.cart, parent, false));
    }

    @Override
    public void onBindViewHolder(Holder holder, final int position) {

        GoodsItem cart = mCards.get(position);
        holder.cb.setChecked(cart.isChecked());
        Picasso.with(mContext).load(cart.getImgUrl()).into(holder.iv);
        holder.tvName.setText(cart.getName());
        holder.tvPrice.setText(String.valueOf(cart.getPrice()));
        holder.countView.setmCount(cart.getCount());
        holder.cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mCards.get(position).setChecked(isChecked);
                mCards.get(position).save();
            }
        });
        holder.countView.setmOnCountChangeListener(new CountView.onCountChangeListener() {
            @Override
            public void onChnage(int count) {
                if (0 == count){
                    mCards.get(position).delete();
                }else {
                    mCards.get(position).setCount(count);
                    mCards.get(position).save();
                }
                mCartFragment.calcPrice();
            }
        });

    }


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

    static class Holder extends RecyclerView.ViewHolder {


        @BindView(R.id.iv)
        ImageView iv;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_price)
        TextView tvPrice;
        @BindView(R.id.count)
        CountView countView;
        @BindView(R.id.cb)
        CheckBox cb;

        public Holder(View itemView) {<commit_msg>fix delete item bug<commit_after>package com.dev.bins.shop.fragment.Cart;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.dev.bins.shop.R;
import com.dev.bins.shop.bean.Cart;
import com.dev.bins.shop.bean.GoodsItem;
import com.dev.bins.shop.widget.CountView;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by bin on 25/02/2017.
 */

public class CartAdapter extends RecyclerView.Adapter<CartAdapter.Holder> {


    private List<GoodsItem> mCards;
    private Context mContext;
    CartFragment mCartFragment;
    public CartAdapter(List<GoodsItem> cards, CartFragment cartFragment) {
        this.mCards = cards;
        mCartFragment = cartFragment;
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        mContext = parent.getContext();
        return new Holder(LayoutInflater.from(parent.getContext()).inflate(R.layout.cart, parent, false));
    }

    @Override
    public void onBindViewHolder(Holder holder, final int position) {

        GoodsItem cart = mCards.get(position);
        holder.cb.setChecked(cart.isChecked());
        Picasso.with(mContext).load(cart.getImgUrl()).into(holder.iv);
        holder.tvName.setText(cart.getName());
        holder.tvPrice.setText(String.valueOf(cart.getPrice()));
        holder.countView.setmCount(cart.getCount());
        holder.cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mCards.get(position).setChecked(isChecked);
                mCards.get(position).save();
            }
        });
        holder.countView.setmOnCountChangeListener(new CountView.onCountChangeListener() {
            @Override
            public void onChnage(int count) {
                if (0 == count){
                    mCards.get(position).delete();
                    mCards.remove(position);
                    notifyDataSetChanged();
                }else {
                    mCards.get(position).setCount(count);
                    mCards.get(position).save();
                }
                mCartFragment.calcPrice();
            }
        });

    }


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

    static class Holder extends RecyclerView.ViewHolder {


        @BindView(R.id.iv)
        ImageView iv;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_price)
        TextView tvPrice;
        @BindView(R.id.count)
        CountView countView;
        @BindView(R.id.cb)
        CheckBox cb;

        public Holder(View itemView) {
{'fraction_non_alphanumeric': 0.10600765518389083, 'fraction_numerical': 0.003328340822100183, 'mean_word_length': 2.6096096096096097, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2653252', 'n_tokens_mistral': 1798, 'n_tokens_neox': 1700, 'n_words': 305}