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.bumptech.glide.load.engine.DiskCacheStrategy;
import com.danding.yang800.Entity.DetailsInfo;
import com.danding.yang800.Entity.MarketInfo;
import com.danding.yang800.R;
import com.danding.yang800.Util.CacheManageUtil;
import com.danding.yang800.Util.ToastUtil;
import com.danding.yang800.View.MyDialog;
import com.zhy.autolayout.utils.AutoUtils;

public class MarketShopAdapter extends MyBaseAdapter<MarketInfo> {

    public MarketShopAdapter(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.market_normal_adapter, null);
            info = new Info();
            info.maketAdapter_normalLayout = (LinearLayout) convertView.findViewById(R.id.maketAdapter_normalLayout);
            info.maketAdapter_cancelLayout = (LinearLayout) convertView.findViewById(R.id.maketAdapter_cancelLayout);
            info.maketAdapter_editLayout = (LinearLayout) convertView.findViewById(R.id.maketAdapter_editLayout);
            info.maketAdapter_conutTv = (TextView) convertView.findViewById(R.id.maketAdapter_conutTv);
            info.maketAdapter_sendTv = (TextView) convertView.findViewById(R.id.maketAdapter_sendTv);

            convertView.setTag(info);
            AutoUtils.autoSize(convertView);

        } else {
            info = (Info) convertView.getTag();
        }
        if (getItem(position).getStatus() == 0) {
            info.maketAdapter_normalLayout.setVisibility(View.VISIBLE);
            info.maketAdapter_cancelLayout.setVisibility(View.GONE);
            info.maketAdapter_editLayout.setVisibility(View.GONE);
            info.maketAdapter_conutTv.setText("已领取并使用：1/20");
        } else if (getItem(position).getStatus() == 1) {
            info.maketAdapter_normalLayout.setVisibility(View.GONE);
            info.maketAdapter_cancelLayout.setVisibility(View.VISIBLE);
            info.maketAdapter_editLayout.setVisibility(View.GONE);
        } else if (getItem(position).getStatus() == 2) {
            info.maketAdapter_normalLayout.setVisibility(View.GONE);
            info.maketAdapter_cancelLayout.setVisibility(View.GONE);
            info.maketAdapter_editLayout.setVisibility(View.VISIBLE);
        } else if (getItem(position).getStatus() == 10) {
            info.maketAdapter_normalLayout.setVisibility(View.VISIBLE);
            info.maketAdapter_cancelLayout.setVisibility(View.GONE);
            info.maketAdapter_editLayout.setVisibility(View.GONE);
            info.maketAdapter_conutTv.setText("每一用户限领1张（共3000张）");
        }
        info.maketAdapter_sendTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final MyDialog okCancelDialog = MyDialog.createBuilder(context).setAlertTitle("发布营销活动").
                        setMsg("确定支付100元吗？").setRemark("（支付后，未被领用的券可作废）");
                okCancelDialog.setOKOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        okCancelDialog.dismiss();
                    }
                });
                okCancelDialog.setOnCancelListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        okCancelDialog.dismiss();
                    }
                });
                okCancelDialog.show();

            }
        });
        return convertView;
    }


    class Info {
        LinearLayout maketAdapter_normalLayout;
        LinearLayout maketAdapter_cancelLayout;
        LinearLayout maketAdapter_editLayout;
        TextView maketAdapter_conutTv;
        TextView maketAdapter_sendTv;
    }
}
