package com.desfate.chart.ui.old.OTC.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.desfate.chart.R;
import com.desfate.chart.ui.old.adapter.HistoryTik;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Locale;

public class TikAdapter extends BaseAdapter {

    private ArrayList<HistoryTik> historyTiks;
    private HolderView mHolderView;
    private Context context;// 这个必须是TimeChartFragment

    public TikAdapter(Context context) {
        this.context = context;
    }

    @SuppressWarnings("unchecked")
    public void setDatas(ArrayList<HistoryTik> datas
//            , GoodsInfoAndQuotes goodsInfoAndQuotes
    ) {
        this.historyTiks = (ArrayList<HistoryTik>) datas.clone();
        this.context = context;
//        this.goodsInfoAndQuotes = goodsInfoAndQuotes;
    }

    @Override
    public int getCount() {
        return historyTiks.size();
    }

    @Override
    public HistoryTik getItem(int arg0) {
        return historyTiks.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup arg2) {
        if (view == null) {
            mHolderView = new HolderView();
            view = LayoutInflater.from(context).inflate(R.layout.tick_item_time, null);
            mHolderView.time = view.findViewById(R.id.time);
            mHolderView.type = view.findViewById(R.id.type);
            mHolderView.price = view.findViewById(R.id.price);
            mHolderView.qty = view.findViewById(R.id.qty);
            view.setTag(mHolderView);
        } else {
            mHolderView = (HolderView) view.getTag();
        }
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss", Locale.CHINA);
        mHolderView.time.setText(sdf.format(getItem(i).getAtTime()));
        mHolderView.type.setText(getItem(i).getPublicTradeType());
//        if (goodsInfoAndQuotes != null &&
//                goodsInfoAndQuotes.getQuoteDay() != null) {
//            mHolderView.price.setText(Utils.roundNum(getItem(i).getLast(), goodsInfoAndQuotes.getGoodsInfo().getDecimalPlace()));
//            if (getItem(i).getLast() > Double.parseDouble(goodsInfoAndQuotes.getQuoteDay().getPreClose())) {
//                // 红涨
//                mHolderView.price.setTextColor(context.getResources().getColor(R.color.p_up_color));
//            } else if (getItem(i).getLast() < Double.parseDouble(goodsInfoAndQuotes.getQuoteDay().getPreClose())) {
//                // 绿跌
//                mHolderView.price.setTextColor(context.getResources().getColor(R.color.p_down_color));
//            } else {
//                mHolderView.price.setTextColor(context.getResources().getColor(R.color.manager_normal_color));
//            }
//        } else {
//            mHolderView.price.setText(Utils.roundNum(getItem(i).getLast(), 3));
//            mHolderView.price.setTextColor(context.getResources().getColor(R.color.manager_normal_color));
//        }
//        String num = PolApplication.shortNum(getItem(i).getVolume());
//        mHolderView.qty.setText(Utils.roundNum(num, 0));
        return view;
        }

    class HolderView {
        TextView time;
        TextView type;
        TextView price;
        TextView qty;
    }

}
