package com.ym.library.utils

import android.annotation.SuppressLint
import android.app.Activity
import android.app.Dialog
import android.content.DialogInterface
import android.os.Build
import android.os.CountDownTimer
import android.text.TextUtils
import android.util.Log
import android.view.Gravity
import android.view.View
import android.webkit.WebView
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.annotation.RequiresApi
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.request.RequestOptions
import com.ym.library.MyConstant
import com.ym.library.R
import com.ym.library.base.BaseDialog
import com.ym.library.listener.AdCallback
import com.ym.library.listener.H5Listener
import com.ym.modulecommon.AppliContext
import com.ym.modulecommon.base.NoDoubleClickListener
import com.ym.modulecommon.utils.LogUtils

/**
 * Created by gaoleichao on 2018/8/17.
 */
object CenterDialog : BaseDialog() {


    fun showDialogUpdateVersion(
        activity: Activity?,
        title: String,
        desc: String,
        isCancel: Boolean,
        isShowLoginDialog: Boolean,
        listener: View.OnClickListener,
        adCallback: AdCallback<Int>?
    ) {
        if (activity == null) {
            return
        }
        val mDialog = Dialog(activity, R.style.UpdateVersionCompatDialogTheme)
        val mDialogView = showBottomDialog(
            R.layout.dialog_update_viersion,
            activity,
            mDialog,
            0,
            Gravity.CENTER
        )
        if (isCancel) {
            mDialog.setCanceledOnTouchOutside(true)
            mDialog.setOnDismissListener {
                SettingPreference.setCancelUpdateDate(activity, Utils.getNowDate())
                MyConstant.Switch.isShowUpdateDialoging = false
                if (isShowLoginDialog) {
                    adCallback?.onResult(0, 0)
                }
            }
        } else {
            mDialog.setCanceledOnTouchOutside(true)
        }
        mDialog.findViewById<ImageView>(R.id.id_close_update_dailog)
            .setOnClickListener(View.OnClickListener {
                mDialog?.dismiss()
            })
        mDialogView.findViewById<TextView>(R.id.tv_check_version_desc).text = desc
        mDialogView.findViewById<TextView>(R.id.btn_update_start).setOnClickListener {
            listener.onClick(it)
        }
        mDialog?.show()
    }

    /**
     * 获得微信红包
     */
    fun showGuideGetMoney(activity: Activity?,title:String, cashStr: String, webView: WebView?) {
        if (activity == null) {
            return
        }
        val mDialog = Dialog(activity, R.style.UpdateVersionCompatDialogTheme75)
        val mDialogView =
            showBottomDialog(
                R.layout.dialog_lib_get_money,
                activity,
                mDialog,
                0,
                Gravity.CENTER
            )
        val tv_money = mDialogView?.findViewById<TextView>(R.id.id_tv_cash_content)
        val tvTitle = mDialogView?.findViewById<TextView>(R.id.id_tv_title)
        tv_money.text = "恭喜您成功兑换${cashStr}元红包，您可以前往微信钱包查看到账情况"
        tvTitle.text = title

        mDialogView.findViewById<TextView>(R.id.id_tv_go_on_make_money).setOnClickListener {
             webView?.loadUrl("javascript:onResume()")
            mDialog.dismiss()
        }
        mDialogView.findViewById<ImageView>(R.id.id_img_dialog_close).setOnClickListener {
            webView?.loadUrl("javascript:onResume()")
            mDialog.dismiss()
        }

        mDialog.setCanceledOnTouchOutside(false)
        mDialog.setCancelable(false)
        mDialog.show()
    }

//    /**
//     * 领取红包奖励
//     */
//    fun getRewardDialog(
//        activity: Activity,
//        reward: DialogRewardEntity,
//        btnStr: String,
//        withdrawClick: View.OnClickListener,
//        comePage: String
//    ) {
//        val mDialog = Dialog(activity, R.style.UpdateVersionCompatDialogTheme)
//        val mDialogView =
//            CenterDialog.showBottomDialog(
//                R.layout.dialog_datecoins,
//                activity,
//                mDialog,
//                0,
//                Gravity.CENTER
//            )
//        val tv_time = mDialogView.findViewById<TextView>(R.id.id_tv_dialog_datecoins_time)
//        val img_close = mDialogView.findViewById<ImageView>(R.id.id_dialog_datecoins_close)
//        val idAdLayout = mDialogView.findViewById<FrameLayout>(R.id.id_dialog_result_ad_layout)
//        tv_time.visibility = View.VISIBLE
//        img_close.visibility = View.GONE
//
//        ToponManager.loadNative(activity,idAdLayout,object :ToponNativeListener {
//            override fun onAdImpressed(atAdInf: ATAdInfo) {
//                EventUtils.onEvent(
//                    "ad_show",
//                    Utils.obj2Str(AdEntity(atAdInf.adNetworkType, AdID.mPlacementId_open_rp_bigimage, "打开红包大图"))
//                )
//            }
//
//            override fun onAdClicked(atAdInf: ATAdInfo, view: ATNativeAdView) {
//                EventUtils.onEvent(
//                    "ad_click",
//                    Utils.obj2Str(AdEntity(atAdInf.adNetworkType, AdID.mPlacementId_open_rp_bigimage, "打开红包大图"))
//                )
//            }
//
//            override fun onAdVideoStart() {
//            }
//
//            override fun onAdVideoEnd() {
//            }
//
//        },AdID.mPlacementId_open_rp_bigimage)
//
//        img_close.setOnClickListener {
//            mDialog.dismiss()
//        }
//        mDialogView.findViewById<TextView>(R.id.id_dialog_datecoins_coin).text =
//            "+" + reward.double?.rewardCent + "金币"
//
//        if (btnStr.isEmpty()) {
//            mDialogView.findViewById<RelativeLayout>(R.id.id_rel_dialog_btn).visibility = View.GONE
//        } else {
//            mDialogView.findViewById<TextView>(R.id.id_tv_dialog_btn_desc).text = btnStr
//        }
//
//        mDialogView.findViewById<RelativeLayout>(R.id.id_rel_dialog_btn).setOnClickListener {
//            withdrawClick.onClick(it)
//            mDialog.dismiss()
//        }
//        mDialog?.setCanceledOnTouchOutside(false)
//        mDialog?.setCancelable(false)
//        mDialog.show()
//        countDown(3000, tv_time, img_close)
//    }
//
//    /**
//     * 任务领取红包奖励
//     */
//    fun getTaskRewardDialog(
//        activity: Activity,
//        reward: String,
//        btnStr: String,
//        withdrawClick: View.OnClickListener,
//        taskType: String
//    ) {
//        val mDialog = Dialog(activity, R.style.UpdateVersionCompatDialogTheme)
//        val mDialogView =
//            CenterDialog.showBottomDialog(
//                R.layout.dialog_datecoins2,
//                activity,
//                mDialog,
//                0,
//                Gravity.CENTER
//            )
//        val tv_time = mDialogView.findViewById<TextView>(R.id.id_tv_dialog_datecoins_time)
//        val img_close = mDialogView.findViewById<ImageView>(R.id.id_dialog_datecoins_close)
//        val layouAd = mDialogView.findViewById<FrameLayout>(R.id.id_dialog_result_ad_layout)
//
//        var adIdImg = ""
//        var adNameImg = ""
//        when (taskType) {
//            //闯关
//            "guessTask" -> {
//                adIdImg = AdID.mPlacementId_pass_complete2
//                adNameImg = "闯关任务完成大图"
//            }
//            //每日任务
//            "DailyTask" -> {
//                adIdImg = AdID.mPlacementId_daily_task_finish_bigimage
//                adNameImg = "每日任务完成大图"
//            }
//            //签到
//            "SignTask" -> {
//                adIdImg = AdID.mPlacementId_daily_task_time_period_signin_bigimag
//                adNameImg = "每日任务时段签到大图"
//            }
//        }
//
//        ToponManager.loadNative(
//            activity, layouAd,
//            object : ToponNativeListener {
//                override fun onAdImpressed(atAdInf: ATAdInfo) {
//                    EventUtils.onEvent(
//                        "ad_show",
//                        Utils.obj2Str(
//                            AdEntity(
//                                atAdInf.networkFirmId.toString(),
//                                adIdImg,
//                                adNameImg
//                            )
//                        )
//                    )
//                }
//
//                override fun onAdClicked(atAdInf: ATAdInfo, view: ATNativeAdView) {
//                    EventUtils.onEvent(
//                        "ad_click",
//                        Utils.obj2Str(
//                            AdEntity(
//                                atAdInf.networkFirmId.toString(),
//                                adIdImg,
//                                adNameImg
//                            )
//                        )
//                    )
//
//                }
//
//                override fun onAdVideoStart() {
//                }
//
//                override fun onAdVideoEnd() {
//                }
//
//            }
//            , adIdImg
//        )
//
//
//
//        tv_time?.visibility = View.VISIBLE
//        img_close?.visibility = View.GONE
//        img_close?.setOnClickListener {
//            when (taskType) {
//                "guessTask" -> {
//                    EventUtils?.onEvent("task_success_close_click", "完成任务直接领奖")
//                }
//                "DailyTask" -> {
//                    EventUtils?.onEvent("task_success_close_click", "完成任务直接领奖")
//                }
//                "SignTask" -> {
//
//                }
//            }
//            mDialog?.dismiss()
//        }
//        if (btnStr == "") {
//            mDialogView.findViewById<RelativeLayout>(R.id.id_rel_dialog_btn)?.visibility = View.GONE
//        } else {
//            mDialogView.findViewById<TextView>(R.id.id_tv_dialog_btn_desc)?.text = btnStr
//        }
//
//        mDialogView.findViewById<TextView>(R.id.id_dialog_datecoins_coin)?.text = reward
//
//        mDialogView.findViewById<RelativeLayout>(R.id.id_rel_dialog_btn)?.setOnClickListener {
//            if (Utils.isFastClick()) {
//                var adId = ""
//                var adName = ""
//                when (taskType) {
//                    //闯关
//                    "guessTask" -> {
//                        adId = AdID.mPlacementId_pass_complete
//                        adName = "闯关任务完成激励视频"
//                    }
//                    //每日任务
//                    "DailyTask" -> {
//                        adId = AdID.mPlacementId_daily_task_video
//                        adName = "每日任务激励视频"
//                    }
//                    //签到
//                    "SignTask" -> {
//                        adId = AdID.mPlacementId_daily_task_time_period_signin_video
//                        adName = "每日任务时段签到激励视频"
//                    }
//                }
//
//                ToponManager.loadReward(activity, object : ToponRewardListener {
//                    override fun onRewardedVideoAdPlayClicked(entity: ATAdInfo) {
//                        EventUtils.onEvent(
//                            "ad_click",
//                            Utils.obj2Str(
//                                AdEntity(
//                                    entity.networkFirmId.toString(),
//                                    adId,
//                                    adName
//                                )
//                            )
//                        )
//
//                    }
//
//                    override fun onRewardedVideoAdClosed(entity: ATAdInfo) {
//                        withdrawClick.onClick(mDialogView)
//                        mDialog?.dismiss()
//                    }
//
//                    override fun onRewardedVideoAdFailed(errorCode: AdError) {
//                        withdrawClick.onClick(mDialogView)
//                        mDialog?.dismiss()
//                    }
//
//                    override fun onRewardedVideoAdPlayEnd(entity: ATAdInfo) {
//                        EventUtils.onEvent("ad_ended", Utils.obj2Str(AdEntity("ad_ended", "ad_ended", adName)))
//                    }
//
//                    override fun onRewardedVideoAdPlayStart(entity: ATAdInfo) {
//                        EventUtils.onEvent(
//                            "ad_show",
//                            Utils.obj2Str(
//                                AdEntity(
//                                    entity.networkFirmId.toString(),
//                                    adId,
//                                    adName
//                                )
//                            )
//                        )
//                    }
//                }, adId)
//            }
//
//
//        }
//        mDialog?.setCanceledOnTouchOutside(false)
//        mDialog?.setCancelable(false)
//        mDialog?.show()
//        countDown(3000, tv_time, img_close)
//    }
    /**
     * 水滴发放
     * type:   1水滴   2金币
     * waterDropCount:   奖励数量
     * adType: 广告的类型
     */
    fun showgetWaterDrop(
        context: Activity?,
        type: Int,
        rewardCount: Int,
        actionName:String,
        listener: DialogInterface.OnCancelListener,
        mWebView: WebView?
    ) {
        if (context == null) {
            return
        }
        val mDialog = Dialog(context, R.style.UpdateVersionCompatDialogTheme)
        val mDialogView =
            showBottomDialog(
                R.layout.dialog_get_diamand,
                context,
                mDialog,
                0,
                Gravity.CENTER
            )
        val imgbg = mDialogView?.findViewById<ImageView>(R.id.iv_get_bg)
        val btn_get_diamand = mDialogView.findViewById<ImageView>(R.id.btn_get_diamand)
        if(type==3){
            imgbg.setImageResource(R.drawable.icon_diamand)
        }

        val tvGetDropCount = mDialogView?.findViewById<TextView>(R.id.tv_get_count)
        val layoutAd = mDialogView?.findViewById<FrameLayout>(R.id.layout_feed_ad)
        tvGetDropCount.text = "+${rewardCount}"

        AdUtils.showFeedAd(context,actionName,layoutAd)
        FilterUtils.addClickAlpha(btn_get_diamand)
        btn_get_diamand.setOnClickListener {
//            mWebView?.loadUrl("javascript:onResume()")
            mDialog?.dismiss()
        }
        mDialogView.findViewById<ImageView>(R.id.lv_get_drop_close).setOnClickListener {
//            mWebView?.loadUrl("javascript:onResume()")
            mDialog?.dismiss()
        }

        mDialog?.setOnCancelListener {
            listener.onCancel(it)
        }

        mDialog?.setCanceledOnTouchOutside(false)
        mDialog?.setCancelable(false)
        mDialog?.show()
    }


    var coinsDialog: Dialog? = null

    @RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
    fun showNewCoinsDialog(context: Activity, rewardCoins: Int): Dialog? {
        coinsDialog = Dialog(context, R.style.CenterCompatDialogTheme)
        val mDialogView: View? =
            showBottomDialog(R.layout.dialog_coins, context, coinsDialog!!, 0, Gravity.CENTER)
        val mCoinsText: TextView = mDialogView!!.findViewById(R.id.id_dialog_coins_num)
        coinsDialog?.window?.setDimAmount(0f)

        mCoinsText.text = rewardCoins.toString()
        mCoinsText.postDelayed(Runnable {
            if (context == null || context.isDestroyed() || context.isFinishing()) {
                return@Runnable
            }
            coinsDialog?.dismiss()

        }, 2000)
        try {
            if (context != null && !context.isDestroyed() && !context.isFinishing()) {
                coinsDialog?.show()
            }
        } catch (e: Exception) {

        }

        return coinsDialog
    }

    fun showDialogReadCoins(
        activity: Activity?,
        coins: Int,
        value: String,
        onClickListener: View.OnClickListener
    ) {
        if (activity == null) {
            return
        }
        val mDialog = Dialog(activity, R.style.UpdateVersionCompatDialogTheme)
        val mDialogView =
            showBottomDialog(R.layout.dialog_read_coins, activity, mDialog, 0, Gravity.CENTER)
        var closeImg = mDialogView.findViewById<ImageView>(R.id.id_dialog_read_coins_close)
        var mDesc = mDialogView.findViewById<TextView>(R.id.id_dialog_read_coins_desc)
        var mValue = mDialogView.findViewById<TextView>(R.id.id_dialog_read_coins_value)
        var mBtn = mDialogView.findViewById<TextView>(R.id.id_dialog_read_coins_btn)
        mValue?.text = "+" + coins + "金币"
        if (TextUtils.equals(value, "0")) {
            mDesc?.text = "恭喜您，任务达成"
            mBtn?.text = "立即提现"
        } else {
            mBtn?.text = "继续赚"
//            mDesc?.text = Html.fromHtml("再赚<font color=\"#FF6B6B\">${value}</font>金币即可提现")
        }
        closeImg?.setOnClickListener {
            mDialog?.dismiss()
        }
        mBtn.setOnClickListener {
            mDialog?.dismiss()
            if (TextUtils.equals(value, "0")) {
                mDialog?.dismiss()
                activity.finish()
                JumpUtils.withdrawCash()
                EventUtils.onEvent("kkz_go_withdraw_click")
            } else {
                EventUtils.onEvent("kkz_continue_click")
                onClickListener.onClick(it)
            }
        }

        mDialog?.setCancelable(false)
        mDialog?.show()
    }

    /**
     * 退出弹窗
     */
    fun showSignOutDialog(activity: Activity, callBack: View.OnClickListener) {
        if (activity == null) {
            return
        }
        MyConstant.isDialogActivity = 1
        val mDialog = Dialog(activity, R.style.UpdateVersionCompatDialogTheme)
        val mDialogView =
            showBottomDialog(R.layout.dialog_sign_out_layout, activity, mDialog, 0, Gravity.CENTER)
        val closeImg = mDialogView.findViewById<ImageView>(R.id.dialog_scratch_dialog_close_img)
        val btn = mDialogView.findViewById<TextView>(R.id.dialog_scratch_dialog_bg)
        val cancelBtn = mDialogView.findViewById<TextView>(R.id.dialog_scratch_dialog_cancel)

        closeImg?.setOnClickListener {
            mDialog?.dismiss()
        }

        btn?.setOnClickListener {
            mDialog?.dismiss()
        }
        cancelBtn?.setOnClickListener {
            callBack.onClick(it)
            activity?.finish()
        }
        mDialog?.setCancelable(false)
        mDialog?.show()
    }

    /**
     * 倒计时
     */
    fun countDown(time: Long, textView: TextView, img_close: ImageView) {
        var countDownTimer: CountDownTimer? = null
        //时间  倒计时   入参long类型
        countDownTimer = object : CountDownTimer(time, 1000) {
            @SuppressLint("SetTextI18n")
            override fun onTick(millisUntilFinished: Long) {
                textView.text = ((millisUntilFinished / 1000) + 1).toString() + "秒"
            }

            override fun onFinish() {
                countDownTimer?.cancel()
                countDownTimer = null
                textView.isEnabled = true
                textView.visibility = View.GONE
                img_close.visibility = View.VISIBLE
            }
        }
        countDownTimer?.start()
    }

    private fun countDown(time: Long, textView: TextView, type: Int) {
        var countDownTimer: CountDownTimer? = null
        //时间  倒计时   入参long类型
        countDownTimer = object : CountDownTimer(time, 1000) {
            @SuppressLint("SetTextI18n")
            override fun onTick(millisUntilFinished: Long) {
                val day = millisUntilFinished / (1000 * 24 * 60 * 60) //单位天
                val hour =
                    (millisUntilFinished - day * (1000 * 24 * 60 * 60)) / (1000 * 60 * 60) //单位时
                val minute =
                    (millisUntilFinished - day * (1000 * 24 * 60 * 60) - hour * (1000 * 60 * 60)) / (1000 * 60) //单位分
                val second =
                    (millisUntilFinished - day * (1000 * 24 * 60 * 60) - hour * (1000 * 60 * 60) - minute * (1000 * 60)) / 1000 //单位秒

                var hours = hour.toString()
                if (hours.length < 2) {//如果是 1 2 3 4 5 6 7 8 9 前边加0
                    hours = "0$hours"
                }
                var minutes = minute.toString()
                if (minutes.length < 2) {//如果是 1 2 3 4 5 6 7 8 9 前边加0
                    minutes = "0$minutes"
                }
                var seconds = second.toString()
                if (seconds.length < 2) {//如果是 1 2 3 4 5 6 7 8 9 前边加0
                    seconds = "0$seconds"
                }
                when (type) {
                    0 -> textView?.text = "离本场结束还有${hours}:${minutes}:${seconds}"
                    1, 2 -> textView?.text = "剩余${hours}:${minutes}:${seconds}"
                }
            }

            override fun onFinish() {
                countDownTimer?.cancel()
                countDownTimer = null
                when (type) {
                    0, 1 -> textView?.visibility = View.GONE
                    2 -> textView?.text = "剩余00:00:00"
                }
            }
        }
        countDownTimer?.start()
    }



    fun showPermission(
        activity: Activity,
        title: String,
        quitListener: View.OnClickListener,
        settingListener: View.OnClickListener
    ) {
        if (activity == null) {
            return
        }
        val mDialog = Dialog(activity, R.style.UpdateVersionCompatDialogTheme)
        val mDialogView = showBottomDialog(
            R.layout.dialog_permissisns,
            activity!!,
            mDialog,
            0,
            Gravity.CENTER
        )
        mDialogView.findViewById<TextView>(R.id.tv_info).text =
            "幸运农田缺少必要权限：\n\n${title}\n请点击\"设置\"-\"权限\"-打开所需权限。\n最后点击两次后退按钮，即可返回。"

        mDialogView.findViewById<TextView>(R.id.btn_permission_quit).setOnClickListener {
            quitListener.onClick(it)
        }

        mDialogView.findViewById<TextView>(R.id.btn_permission_setting).setOnClickListener {
            settingListener.onClick(it)
            mDialog?.dismiss()
        }

        mDialog?.setCanceledOnTouchOutside(false)
        mDialog?.setCancelable(false)
        mDialog?.show()
    }

    /**
     * 首页弹窗风格1，使用时查看布局
     */
    fun showHomeDialogStyle1(
        activity: Activity?,
        type: Int,
        onClickListener: View.OnClickListener,
        int1: Int,
        string1: String,
        string2: String
    ) {
        if (activity == null) return
        val mDialog = Dialog(activity, R.style.UpdateVersionCompatDialogTheme)
        val view =
            showBottomDialog(R.layout.dialog_home_style_1, activity, mDialog, 0, Gravity.CENTER)
        val id_tv_title = view?.findViewById<TextView>(R.id.id_tv_title)
        EventUtils.onEvent("guaka_reward_show","刮卡奖励弹窗曝光")

        view.findViewById<View>(R.id.id_iv_dismiss).setOnClickListener {
            mDialog.dismiss()
            if (string1.equals("H5_Dismiss")) {
                activity.finish()
            }

            if (string1.equals("H5_Not_Dimiss")) {
                onClickListener?.onClick(it)
            }

            if (string1.equals("0.3")) {
                onClickListener?.onClick(it)
            }

        }

        when (type) {
            0 -> {
                id_tv_title?.text = "猪财神助力"
                view?.findViewById<View>(R.id.id_ll_help).visibility = View.VISIBLE
                view?.findViewById<TextView>(R.id.id_tv_time_0)?.text = string1
                val iv_pig_upgrade = view?.findViewById<ImageView>(R.id.iv_pig_upgrade)
                view?.findViewById<View>(R.id.id_iv_btn_0).setOnClickListener {
                    val animationLocation = IntArray(2)
                    iv_pig_upgrade?.getLocationOnScreen(animationLocation)
                    MyConstant.animationLocation = animationLocation
                    onClickListener.onClick(it)
                    mDialog.dismiss()
                }
            }
            1 -> {
                id_tv_title?.text = "金币卡"
                view?.findViewById<View>(R.id.id_ll_pig_card).visibility = View.VISIBLE
                val id_iv_btn_1 = view?.findViewById<ImageView>(R.id.id_iv_btn_1)
                id_iv_btn_1.setOnClickListener(object : NoDoubleClickListener() {
                    override fun onNoDoubleClick(view: View?) {
                        onClickListener.onClick(id_iv_btn_1)
                        mDialog.dismiss()
                    }

                })

            }
            2 -> {
                id_tv_title?.text = "领取奖励"
                view?.findViewById<View>(R.id.id_ll_upgrade).visibility = View.VISIBLE
                val tv_number = view?.findViewById<TextView>(R.id.tv_number)
                val tv_title = view?.findViewById<TextView>(R.id.tv_title)
                tv_title.text = string1 + "元"
                tv_number.text = string1
                val iv_ok = view?.findViewById<ImageView>(R.id.iv_ok)
                iv_ok.setOnClickListener(object : NoDoubleClickListener() {
                    override fun onNoDoubleClick(view: View?) {
                        onClickListener.onClick(iv_ok)
                        mDialog.dismiss()
                    }

                })
            }
            3 -> {
                id_tv_title?.text = "恭喜获得"
                view?.findViewById<View>(R.id.id_ll_congratulations).visibility = View.VISIBLE
                view?.findViewById<TextView>(R.id.id_tv_number)?.text = "${int1}金币"
                val id_iv_double = view?.findViewById<ImageView>(R.id.id_iv_double)
                if (string1.equals("0") || string1.equals("H5_Dismiss") || string1.equals("H5_Not_Dimiss")) {//奖励翻倍
                   // id_iv_double.setImageResource(R.drawable.bg_dialog_home_double)
                    id_iv_double.setImageResource(R.drawable.icon_shouxia_bg)
                } else {//开心收下
                    id_iv_double.setImageResource(R.drawable.icon_shouxia_bg)
                }
                id_iv_double.setOnClickListener(object : NoDoubleClickListener() {
                    override fun onNoDoubleClick(view: View?) {
                        if (string1.equals("0") || string1.equals("H5_Dismiss") || string1.equals("H5_Not_Dimiss")) {
                            EventUtils.onEvent("guaka_double_video_btn_click","刮卡奖励翻倍按钮点击")
                           // onClickListener.onClick(view)
                            activity.finish()
                        }
                        mDialog.dismiss()
                    }
                })

                val id_tv_close_button = view.findViewById<TextView>(R.id.id_tv_close_button)
                val id_iv_dismiss = view.findViewById<ImageView>(R.id.id_iv_dismiss)
                DialogCloseUtils.setTimes(id_tv_close_button, id_iv_dismiss)

                val ad_framelayout = view?.findViewById<FrameLayout>(R.id.ad_framelayout)
                ad_framelayout.removeAllViews()
                AdUtils.showFeedAd(activity,"happy_receiver_bigimg",ad_framelayout)
//                AdManager.showFeedAd(
//                    ADConfig.AD_IMG_FADE,
//                    "happy_receiver_bigimg",
//                    ZXADSizeConfig(
//                        Utils.px2dip(PhoneUtils.getScreenWidth(activity).toFloat()) - 36,
//                        244
//                    ),
//                    activity,
//                    ad_framelayout
//                )
//                ad_framelayout.postDelayed(Runnable {
//                    AdManager.loadFeedAdToCache(
//                        ADConfig.AD_COMMOM_BIGIMAGE,
//                        activity,
//                        ZXADSizeConfig(
//                            Utils.px2dip(
//                                PhoneUtils.getScreenWidth(activity).toFloat()
//                            ) - 36, 244
//                        )
//                    )
//                }, 1500)
            }
            4 -> {
                id_tv_title?.text = "好友"
                view?.findViewById<View>(R.id.id_ll_friend).visibility = View.VISIBLE
                Glide.with(AppliContext.get()).load(string1)
                    .apply(RequestOptions.bitmapTransform(CircleCrop()))
                    .into(view?.findViewById(R.id.id_iv_avatar_4))
                view?.findViewById<TextView>(R.id.id_iv_name_4)?.text = string2
                val id_tv_time_4 = view?.findViewById<TextView>(R.id.id_tv_time_4)
                countDown((int1 * 1000).toLong(), id_tv_time_4, 2)
            }
            5 -> {
                id_tv_title?.text = "猪财神"
                view?.findViewById<View>(R.id.id_ll_delete).visibility = View.VISIBLE
                val id_tv_time = view?.findViewById<TextView>(R.id.id_tv_time)
                view?.findViewById<ImageView>(R.id.id_iv_delete)
                    .setOnClickListener(object : NoDoubleClickListener() {
                        override fun onNoDoubleClick(view: View?) {
                            onClickListener.onClick(view)
                            mDialog.dismiss()
                        }
                    })
                countDown((int1 * 1000).toLong(), id_tv_time, 2)
            }
            6 -> {
                id_tv_title?.text = "幸运转盘规则"
                view?.findViewById<View>(R.id.id_ll_rule).visibility = View.VISIBLE
                view?.findViewById<View>(R.id.id_iv_confirm).setOnClickListener {
                    mDialog.dismiss()
                }
            }
            7 -> {
                id_tv_title?.text = "免费领奖"
                view?.findViewById<View>(R.id.id_ll_dream).visibility = View.VISIBLE
                view?.findViewById<View>(R.id.id_iv_to_wish).setOnClickListener {
                    onClickListener.onClick(it)
                    mDialog.dismiss()
                }
            }
        }
        mDialog.setCanceledOnTouchOutside(true)
        mDialog.setOnDismissListener {}
        mDialog.show()
    }
    /**
     *
     * h5Page: 1:刮刮卡
     * h5Page：2：大富翁
     *
     *
     */
    fun showH5Dialog(
        activity: Activity,
        number: Double,
        type: Int,
        h5Page: Int,
        listener: H5Listener
    ) {
        LogUtils.e("huang", "h5page:" + h5Page + "type:" + type)
        if (activity == null) return
        val mDialog = Dialog(activity, R.style.UpdateVersionCompatDialogTheme)
        val view =
            showBottomDialog(R.layout.dialog_home_style_3, activity, mDialog, 0, Gravity.CENTER)

        val id_ll_congratulations = view.findViewById<LinearLayout>(R.id.id_ll_congratulations)
        val ll_big_money = view.findViewById<LinearLayout>(R.id.ll_big_money)
        val id_ll_upgrade = view.findViewById<LinearLayout>(R.id.id_ll_upgrade)
        val iv_ok = mDialog.findViewById<ImageView>(R.id.iv_ok)

        val id_tv_close_button = view.findViewById<TextView>(R.id.id_tv_close_button)
        val id_iv_dismiss = view.findViewById<ImageView>(R.id.id_iv_dismiss)
        DialogCloseUtils.setTimes(id_tv_close_button, id_iv_dismiss)

        id_iv_dismiss?.setOnClickListener {
            mDialog.dismiss()
            if ((type == 1 || type == 2) && h5Page == 1) {
                activity.finish()
            }

            if (type == 1) {
                listener.onDialogClose("2",0)
            } else if (type == 0) {
                listener.onDialogClose("1",0)
            }
        }
        iv_ok.setOnClickListener {
            mDialog.dismiss()
            if ((type == 1 || type == 2) && h5Page == 1) {
                activity.finish()
            }

            if (type == 1) {
                listener.onDialogClose("2",1)
            } else if (type == 0) {
                listener.onDialogClose("1",1)
            }

        }
        when (type) {
            1 -> {//金币
                id_ll_congratulations.visibility = View.VISIBLE
                iv_ok.visibility = View.VISIBLE
                val id_tv_number = view.findViewById<TextView>(R.id.id_tv_number)
                id_tv_number.text = "" + number.toInt() + "金币"
            }

            0 -> {//心愿值
                ll_big_money.visibility = View.VISIBLE
                iv_ok.visibility = View.VISIBLE
                val tv_number = view.findViewById<TextView>(R.id.tv_number)
                tv_number.setText("" + number.toInt() + "个心愿值")
            }
            2 -> {//红包

                id_ll_upgrade.visibility = View.VISIBLE
                val tv_red_title = view.findViewById<TextView>(R.id.tv_red_title)
                val tv_red_number = view.findViewById<TextView>(R.id.tv_red_number)
                val iv_red_ok = view.findViewById<ImageView>(R.id.iv_red_ok)
                tv_red_title.text = "" + number + "元"
                tv_red_number.text = "" + number
                iv_red_ok.setOnClickListener {
                    mDialog.dismiss()
                    if ((type == 1 || type == 2) && h5Page == 1) {
                        activity.finish()
                    }
                }
            }
        }


        val ad_framelayout = mDialog.findViewById<FrameLayout>(R.id.ad_framelayout)
        AdUtils.showFeedAd(activity,"h5_bigimg",ad_framelayout)
//        AdManager.showFeedAd(
//            ADConfig.AD_COMMOM_BIGIMAGE,
//            "h5_bigimg",
//            ZXADSizeConfig(Utils.px2dip(PhoneUtils.getScreenWidth(activity).toFloat()) - 38, 250),
//            activity,
//            ad_framelayout
//        )
        mDialog.setCanceledOnTouchOutside(true)
        mDialog.setOnDismissListener {}
        mDialog.show()
    }

    //h5弹窗 红包和金币
    fun showRedCoinDialog(activity: Activity, type: Int, number: Int?) {
        if (activity == null) return
        val mDialog = Dialog(activity, R.style.UpdateVersionCompatDialogTheme)
        val view =
            showBottomDialog(R.layout.dialog_home_style_1, activity, mDialog, 0, Gravity.CENTER)
        val id_tv_title = view?.findViewById<TextView>(R.id.id_tv_title)
        view.findViewById<View>(R.id.id_iv_dismiss).setOnClickListener {
            mDialog.dismiss()
        }
        when (type) {
            10 -> {//红包
                id_tv_title?.text = "恭喜获得"
                view?.findViewById<View>(R.id.id_ll_upgrade).visibility = View.VISIBLE
                val tv_number = view?.findViewById<TextView>(R.id.tv_number)
                val tv_title = view?.findViewById<TextView>(R.id.tv_title)
                tv_title.text = "" + number + "元"
                tv_number.text = "" + number
                view?.findViewById<ImageView>(R.id.iv_ok).setOnClickListener {
                    mDialog.dismiss()
                }
            }
            1 -> {// 金币
                id_tv_title?.text = "恭喜获得"
                view?.findViewById<View>(R.id.id_ll_congratulations).visibility = View.VISIBLE
                view?.findViewById<TextView>(R.id.id_tv_number)?.text = "${number}金币"
                val id_iv_double = view?.findViewById<ImageView>(R.id.id_iv_double)
                id_iv_double.setImageResource(R.drawable.bg_dialog_home_accept)
                id_iv_double.setOnClickListener(object : NoDoubleClickListener() {
                    override fun onNoDoubleClick(view: View?) {
                        mDialog.dismiss()
                    }
                })
            }
        }
        mDialog.setCanceledOnTouchOutside(true)
        mDialog.setOnDismissListener {}
        mDialog.show()
    }
}