package com.jld.vod.view.widget;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.jld.vod.R;
import com.jld.vod.config.Config;
import com.jld.vod.model.bean.PositionAdvertBean;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;

import java.util.ArrayList;
import java.util.List;

public class CustomAdDialog
        extends Dialog
{

    private ImageView mCloseImg;
    private Banner mBanner;
    private List<String> list = new ArrayList<>();
    private Context mContext;
    public OnClickBottomListener onClickBottomListener;


    public CustomAdDialog(Context paramContext)
    {
        super(paramContext, R.style.MyDialog);
        this.mContext = paramContext;


    }

    private void initEvent()
    {
        this.mCloseImg.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View paramAnonymousView)
            {
                if (CustomAdDialog.this.onClickBottomListener != null) {
                    CustomAdDialog.this.onClickBottomListener.onBtnCloseClick();
                }
            }
        });

    }

    private void initView()
    {
        this.mCloseImg = (ImageView)findViewById(R.id.iv_close_ads);
        //轮播
        this.mBanner = (Banner)findViewById(R.id.about_banner);
        //设置图片加载器
        mBanner.setImageLoader(new GlideImageLoader());
        //设置图片集合
        mBanner.setImages(list);
        //banner设置方法全部调用完毕时最后调用
        mBanner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
        mBanner.setDelayTime(3000);
        mBanner.start();
    }

    public List<String> getTestData3() {
        list.add("https://img-blog.csdnimg.cn/20200524220705330.png");
        list.add("https://img-blog.csdnimg.cn/20200524220705336.png");
        list.add("https://img-blog.csdnimg.cn/20200524220705336.png");

        return list;
    }

    /**
     * 设置数据
     * @param positionAdvert
     */
    public void setDataList(List<PositionAdvertBean> positionAdvert)
    {
        list.clear();
        for (int i = 0;i<positionAdvert.size();i++)
        {
            list.add(Config.ApiBaseUrl + "/synchronization/previewImg?imgUrl=" + positionAdvert.get(i).getFilePath());
        }

    }

    @SuppressLint("WrongConstant")
    private void refreshView()
    {

//        if (!TextUtils.isEmpty(this.tv_ok)) {
//            this.mBtnOk.setText(this.tv_ok);
//        }
//        if (!TextUtils.isEmpty(this.tv_no)) {
//            this.mBtnNo.setText(this.tv_no);
//        }
//        Button localButton = this.mBtnNo;
//        if (this.visiable) {}
//        for (int i = 0;; i = 8)
//        {
//            localButton.setVisibility(i);
//            if (!TextUtils.isEmpty(this.tv_cus))
//            {
//                this.mBtnCus.setText(this.tv_cus);
//                this.mBtnCus.setVisibility(View.VISIBLE);
//            }
//            return;
//        }
    }

    protected void onCreate(Bundle paramBundle)
    {
        super.onCreate(paramBundle);
        setContentView(R.layout.custom_ad_dialog);
        setCanceledOnTouchOutside(false);
        Window w = getWindow();
        int width = 850;
        int height = 600;
        w.setLayout(width,height);
        w.setGravity(17);
        WindowManager.LayoutParams localLayoutParams = w.getAttributes();

        w.setWindowAnimations(R.style.AnimationDialog);
        w.setAttributes(localLayoutParams);

        initView();
        refreshView();
        initEvent();
    }


    public CustomAdDialog setOnClickBottomListener(OnClickBottomListener paramOnClickBottomListener)
    {
        this.onClickBottomListener = paramOnClickBottomListener;
        return this;
    }


    public static abstract interface OnClickBottomListener
    {
        public abstract void onBtnCloseClick();
    }
}