package com.jld.vod.view.widget;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
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.Datas;
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 CustomGEOAdDialog
        extends Dialog
{

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


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


    }

    @Override
    public void dismiss() {
        super.dismiss();
    }

    private void initEvent()
    {

    }

    private void initView()
    {

        this.auto_ms_text = findViewById(R.id.auto_ms_text);

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

    @Override
    public void show() {

        /** 倒计时30秒，一次1秒 */
        CountDownTimer timer = new CountDownTimer(30*1000, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                // TODO Auto-generated method stub
                auto_ms_text.setText(millisUntilFinished/1000+"");
            }

            @Override
            public void onFinish() {
                auto_ms_text.setText("0");
                dismiss();
            }
        }.start();
        super.show();
    }

    /**
     * 设置数据
     * @param positionAdvert
     */
    public void setDataList(List<Datas> 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_geo_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();

        localLayoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
        localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;

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

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


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


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