package com.taikor.investment.adapter;

import android.app.Activity;
import android.graphics.Color;
import android.text.TextUtils;
import android.widget.TextView;

import com.taikor.investment.base.BaseAdapter;
import com.taikor.investment.bean.Customer;
import com.taikor.investment.utils.DegreeUtils;
import com.taikor.investment.R;

/**
 * 客户列表的适配器
 * Created by Any on 2017/3/30.
 */

public class CustomerAdapter extends BaseAdapter<Customer.CustomersBean> {

    public CustomerAdapter(Activity context) {
        super(context);
    }

    @Override
    protected int getItemLayoutId(int itemViewType) {
        return R.layout.item_customer;
    }

    @Override
    protected void handleItem(int itemViewType, int position, Customer.CustomersBean item, ViewHolder holder, boolean reused) {
        holder.get(R.id.tv_cus_id, TextView.class).setText(String.valueOf(position + 1));
        holder.get(R.id.tv_cus_customer_name, TextView.class).setText(item.getCustomerName());
        String portfolioName = item.getPortfolioName();
        if (TextUtils.isEmpty(portfolioName)) {
            holder.get(R.id.tv_cus_group_name, TextView.class).setText("");
        } else
            holder.get(R.id.tv_cus_group_name, TextView.class).setText(portfolioName);
        //拟合净值
        double fittingNetWorth = item.getFittingNetWorth();
        if (fittingNetWorth == 0) {
            holder.get(R.id.tv_cus_net_fit, TextView.class).setText("0.0000");
        } else {
            holder.get(R.id.tv_cus_net_fit, TextView.class).setText(DegreeUtils.setDoubleFour(fittingNetWorth));
        }
        //收益率
        double profitRate = item.getProfitRate();
        TextView textView = holder.get(R.id.tv_cus_income, TextView.class);

        if (profitRate > 0) {
            textView.setTextColor(Color.parseColor("#FD3642"));
            textView.setText(DegreeUtils.setDoubleTwo(profitRate) + "%");
        } else if (profitRate < 0) {
            textView.setTextColor(Color.parseColor("#07B60E"));
            textView.setText(DegreeUtils.setDoubleTwo(profitRate) + "%");
        } else {
            textView.setTextColor(Color.parseColor("#333333"));
            textView.setText("0.00%");
        }
    }
}
