package com.taikor.investment.adapter;

import android.app.Activity;
import android.graphics.Color;
import android.widget.TextView;
import com.taikor.investment.base.BaseAdapter;
import com.taikor.investment.bean.Product;
import com.taikor.investment.utils.DegreeUtils;
import com.taikor.investment.R;

/**
 * 固定资产和净值波动 列表的适配器
 * <p>
 * Created by Any on 2017/4/6.
 */

public class ProductsAdapter extends BaseAdapter<Product> {

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

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

    @Override
    protected void handleItem(int itemViewType, int position, Product item, BaseAdapter.ViewHolder holder, boolean reused) {
        holder.get(R.id.tv_pro_id,TextView.class).setText(String.valueOf(position+1));
        holder.get(R.id.tv_pro_fund_name,TextView.class).setText(item.getProductName());
        holder.get(R.id.tv_pro_per_fit,TextView.class).setText(DegreeUtils.setDoubleFour(item.getUnitNet()));
        TextView textView = holder.get(R.id.tv_pro_income, TextView.class);
        double annualizedProfitRate = item.getAnnualizedProfitRate();
        if (annualizedProfitRate > 0) {
            textView.setTextColor(Color.parseColor("#FD3642"));
        } else if (annualizedProfitRate < 0) {
            textView.setTextColor(Color.parseColor("#07B60E"));
        } else
            textView.setTextColor(Color.parseColor("#333333"));
        textView.setText(DegreeUtils.setDoubleTwo(annualizedProfitRate) + "%");
    }
    
}
