package com.danding.yang800.Adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.danding.yang800.Config.ConfigUtil;
import com.danding.yang800.Entity.MarketInfo;
import com.danding.yang800.Entity.TicketNotUseInfo;
import com.danding.yang800.R;
import com.zhy.autolayout.utils.AutoUtils;

import jp.wasabeef.glide.transformations.CropCircleTransformation;

public class TicketNotUseAdapter extends MyBaseAdapter<TicketNotUseInfo> {

    public TicketNotUseAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        Info info = null;
        if (convertView == null) {
            convertView = inflater
                    .inflate(R.layout.ticket_notuse_adapter, null);
            info = new Info();
            info.ticketNotUseAdapter_botLayout = (LinearLayout) convertView.findViewById(R.id.ticketNotUseAdapter_botLayout);
            info.ticketNotUseAdapter_wxIv = (ImageView) convertView.findViewById(R.id.ticketNotUseAdapter_wxIv);
            info.ticketNotUseAdapter_rightIv = (ImageView) convertView.findViewById(R.id.ticketNotUseAdapter_rightIv);
            info.ticketNotUseAdapter_priceTv = (TextView) convertView.findViewById(R.id.ticketNotUseAdapter_priceTv);
            info.ticketNotUseAdapter_nameTv = (TextView) convertView.findViewById(R.id.ticketNotUseAdapter_nameTv);
            info.ticketNotUseAdapter_useTv = (TextView) convertView.findViewById(R.id.ticketNotUseAdapter_useTv);
            info.ticketNotUseAdapter_timeTv = (TextView) convertView.findViewById(R.id.ticketNotUseAdapter_timeTv);
            info.ticketNotUseAdapter_wxNameTv = (TextView) convertView.findViewById(R.id.ticketNotUseAdapter_wxNameTv);
            info.ticketNotUseAdapter_getTimeTv = (TextView) convertView.findViewById(R.id.ticketNotUseAdapter_getTimeTv);
            convertView.setTag(info);
            AutoUtils.autoSize(convertView);
        } else {
            info = (Info) convertView.getTag();
        }
        if (getItem(position).getStatus() == 3) {
            info.ticketNotUseAdapter_botLayout.setVisibility(View.VISIBLE);
            Glide.with(context).load(ConfigUtil.getImageUrl(getItem(position).getUserReceiveAvatar(), 32, 32)).error(R.drawable.huisebeijing)
                    .bitmapTransform(new CropCircleTransformation(context)).crossFade(1000)
                    .into(info.ticketNotUseAdapter_wxIv);
            info.ticketNotUseAdapter_wxNameTv.setText(getItem(position).getUserReceiveName());
            info.ticketNotUseAdapter_getTimeTv.setText("领取时间：" + getItem(position).getUserReceiveTime());
        } else {
            info.ticketNotUseAdapter_botLayout.setVisibility(View.GONE);
        }
        info.ticketNotUseAdapter_priceTv.setText(getItem(position).getDiscountFee() + "");
        info.ticketNotUseAdapter_nameTv.setText(getItem(position).getName());
        info.ticketNotUseAdapter_useTv.setText(getItem(position).getCondition());
        info.ticketNotUseAdapter_timeTv.setText("使用期限：" + getItem(position).getUserTimeRange());
        if (getItem(position).getStatus() == -1) {
            info.ticketNotUseAdapter_rightIv.setImageDrawable(context.getResources().getDrawable(R.drawable.overdue));
        } else if (getItem(position).getStatus() == 2) {
            info.ticketNotUseAdapter_rightIv.setImageDrawable(context.getResources().getDrawable(R.drawable.used));
        } else {
            info.ticketNotUseAdapter_rightIv.setImageDrawable(context.getResources().getDrawable(R.drawable.overgive));
        }
        return convertView;
    }

    class Info {
        LinearLayout ticketNotUseAdapter_botLayout;
        ImageView ticketNotUseAdapter_wxIv;
        TextView ticketNotUseAdapter_priceTv;
        TextView ticketNotUseAdapter_nameTv;
        TextView ticketNotUseAdapter_useTv;
        TextView ticketNotUseAdapter_timeTv;
        ImageView ticketNotUseAdapter_rightIv;
        TextView ticketNotUseAdapter_wxNameTv;
        TextView ticketNotUseAdapter_getTimeTv;
    }
}
