package com.sheep.gamegroup.view.adapter;

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

import com.sheep.gamegroup.model.entity.WithdrawalEty;
import com.sheep.gamegroup.util.CommonUtil;
import com.sheep.gamegroup.util.TimeUtil;
import com.sheep.jiuyan.samllsheep.R;

import java.util.List;
import java.util.Locale;

/**
 * Created by ljy on 2018/3/21.
 */

public class WithdrawalListAdp extends BaseAdapter {
    private Context context;
    private List<WithdrawalEty> etyList;

    public WithdrawalListAdp(Context context, List<WithdrawalEty> etyList) {
        this.context = context;
        this.etyList = etyList;
    }

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

    @Override
    public Object getItem(int position) {
        return etyList.get(position);
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Object tag = convertView == null ? null : convertView.getTag();
        ViewHolder holder;
        if(tag instanceof ViewHolder){
            holder = (ViewHolder) tag;
        }else {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.withdrawal_item, null);
            holder.name_tv = convertView.findViewById(R.id.name_tv);
            holder.date_tv = convertView.findViewById(R.id.date_tv);
            holder.price_tv = convertView.findViewById(R.id.price_tv);
            holder.state_tv = convertView.findViewById(R.id.state_tv);
            convertView.setTag(holder);
        }

        WithdrawalEty ety = (WithdrawalEty) getItem(position);
        holder.name_tv.setText(TextUtils.isEmpty(ety.getDesc())?"提现":ety.getDesc());
        try {
            holder.date_tv.setText(TimeUtil.getDate(TimeUtil.FORMAT, ety.getUpdate_time()));
        }catch (Exception e){
            e.printStackTrace();
        }
        holder.price_tv.setText(String.format(Locale.CHINA,"-%.2f元", ety.getAmount()));
        holder.state_tv.setText(CommonUtil.getInstance().returnAuditResult(ety));

        return convertView;
    }

    class ViewHolder{
        TextView name_tv, date_tv, price_tv, state_tv;
    }
}
