package com.danding.yang800.Adapter;


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

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.danding.yang800.Config.ConfigUtil;
import com.danding.yang800.Entity.SeeShopInfo;
import com.danding.yang800.General.Yang800App;
import com.danding.yang800.R;
import com.danding.yang800.SeeActivity;
import com.zhy.autolayout.utils.AutoUtils;

public class SeeShopAdapter extends MyBaseAdapter<SeeShopInfo> {
    SeeActivity context;

    public SeeShopAdapter(SeeActivity context) {
        super(context);
        this.context = context;
        sp = context.getSharedPreferences("variable", Context.MODE_PRIVATE);
    }

    SharedPreferences sp;

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Info info = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.see_shop_item, null);
            info = new Info();
            info.seeshop_goodsIv = (ImageView) convertView.findViewById(R.id.seeshop_goodsIv);
            info.seeshop_noneIv = (ImageView) convertView.findViewById(R.id.seeshop_noneIv);
            info.seeshop_goodsNameTv = (TextView) convertView.findViewById(R.id.seeshop_goodsNameTv);
            info.seeshop_goodsPriceTv = (TextView) convertView.findViewById(R.id.seeshop_goodsPriceTv);
            info.seeshop_expFreeTv = (TextView) convertView.findViewById(R.id.seeshop_expFreeTv);
            info.seeshop_taxFreeTv = (TextView) convertView.findViewById(R.id.seeshop_taxFreeTv);
            convertView.setTag(info);
            AutoUtils.autoSize(convertView);
        } else {
            info = (Info) convertView.getTag();
        }
        Glide.with(context).load(ConfigUtil.getImageUrl(getItem(position).getGoodsImgUrl(), 210, 210)).error(R.drawable.huisebeijing).diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .into(info.seeshop_goodsIv);
        info.seeshop_goodsNameTv.setText(getItem(position).getGoodsName());
        info.seeshop_goodsPriceTv.setText("￥" + getItem(position).getPrice());
        if (getItem(position).isExpFree()) {
            info.seeshop_expFreeTv.setVisibility(View.VISIBLE);
        } else {
            info.seeshop_expFreeTv.setVisibility(View.GONE);
        }
        if (getItem(position).isTaxFree()) {
            info.seeshop_taxFreeTv.setVisibility(View.VISIBLE);
        } else {
            info.seeshop_taxFreeTv.setVisibility(View.GONE);
        }
        if (getItem(position).getStats().equals("3")) {
            info.seeshop_noneIv.setVisibility(View.VISIBLE);
        } else {
            info.seeshop_noneIv.setVisibility(View.GONE);
        }
        return convertView;
    }

    class Info {
        ImageView seeshop_goodsIv;
        ImageView seeshop_noneIv;
        TextView seeshop_goodsNameTv;
        TextView seeshop_goodsPriceTv;
        TextView seeshop_expFreeTv;
        TextView seeshop_taxFreeTv;
    }

}
