package com.taikor.investment.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.taikor.investment.R;
import com.taikor.investment.bean.Repo;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuAdapter;

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

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 客户列表，持仓设置的适配器
 * Created by Any on 2017/3/30.
 */

public class RepoAdapter extends SwipeMenuAdapter<RepoAdapter.RepoHolder> {
    private List<Repo> mData=new ArrayList<>();
    
    public void setData(List<Repo> data) {
        if (mData != null)
            this.mData = data;
        notifyDataSetChanged();
    }

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

    @Override
    public View onCreateContentView(ViewGroup parent, int viewType) {
        return LayoutInflater.from(parent.getContext()).inflate(R.layout.item_customer_repo, parent, false);
    }

    @Override
    public RepoHolder onCompatCreateViewHolder(View realContentView, int viewType) {
        return new RepoHolder(realContentView);
    }

    @Override
    public void onBindViewHolder(RepoHolder holder, int position) {
        holder.tvRepoFundId.setText(mData.get(position).getFund_id());
        holder.tvRepoId.setText(String.valueOf(position + 1));
        holder.tvRepoFundName.setText(mData.get(position).getFund_name());
        holder.tvRepoMoney.setText(String.valueOf(mData.get(position).getMoney()));
        holder.tvRepoPro.setText(mData.get(position).getProportion()+"%");
    }

    public class RepoHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_repo_id)
        TextView tvRepoId;
        @BindView(R.id.tv_repo_fund_id)
        public TextView tvRepoFundId;
        @BindView(R.id.tv_repo_fund_name)
        TextView tvRepoFundName;
        @BindView(R.id.tv_repo_pro)
        TextView tvRepoPro;
        @BindView(R.id.tv_repo_money)
        TextView tvRepoMoney;

        private RepoHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
