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.Group;
import com.taikor.investment.utils.DegreeUtils;
import com.taikor.investment.utils.TimeUtils;
import com.taikor.investment.R;

/**
 * 我的组合列表适配器
 * Created by Any on 2017/3/30.
 */

public class GroupAdapter extends BaseAdapter<Group> {

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

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

    @Override
    protected void handleItem(int itemViewType, int position, Group item, ViewHolder holder, boolean reused) {
        holder.get(R.id.tv_group_group_name, TextView.class).setText(item.getPortfolioName());
       
        long createTime = item.getCreateTime();
        if(createTime==0){
            holder.get(R.id.tv_create_time, TextView.class).setText("创建于 ——");
        }else{
            holder.get(R.id.tv_create_time, TextView.class).setText("创建于 "+TimeUtils.getStringDate(createTime));
        }
      
        holder.get(R.id.tv_group_net_worth, TextView.class).setText(DegreeUtils.setDoubleFour(item.getNetWorth()));
        TextView annualView = holder.get(R.id.tv_group_year_income, TextView.class);
        TextView monthView = holder.get(R.id.tv_group_month_income, TextView.class);
        //年化收益
        double annualizedProfit = item.getAnnualizedProfit();
        if (annualizedProfit > 0) {
            annualView.setTextColor(Color.parseColor("#FD3642"));
        } else if (annualizedProfit < 0) {
            annualView.setTextColor(Color.parseColor("#07B60E"));
        } else {
            annualView.setTextColor(Color.parseColor("#333333"));
        }
       annualView.setText(DegreeUtils.setDoubleTwo(item.getAnnualizedProfit())+"%");
        //近一月收益
        double monthlyProfit = item.getMonthlyProfit();
        if (monthlyProfit > 0) {
            monthView.setTextColor(Color.parseColor("#FD3642"));
        } else if (monthlyProfit < 0) {
            monthView.setTextColor(Color.parseColor("#07B60E"));
        } else {
            monthView.setTextColor(Color.parseColor("#333333"));
        }
        monthView.setText(DegreeUtils.setDoubleTwo(item.getMonthlyProfit())+"%");
    }
}
