package com.ym.game.view

import android.app.Activity
import android.app.Dialog
import android.content.Context
import android.content.DialogInterface
import android.view.Gravity
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.widget.*
import com.ym.game.listener.IDialogViewCloseCallback
import com.ym.modulecommon.AppliContext
import com.ym.xynt.R
import com.ym.game.wedget.FontTextView
import com.ym.library.module.FlyBoxEntity
import com.ym.library.module.TurntableEntity
import com.ym.library.net.NetConfig
import com.ym.library.utils.*
import com.ym.modulecommon.utils.PhoneUtils
import org.jetbrains.anko.act

object MainDialog {

    fun showBottomDialog(
        layout: Int,
        activity: Context,
        setHeadDialog: Dialog,
        animation: Int,
        gravity: Int
    ): View {
        val mDialogView = View.inflate(activity, layout, null)
        setHeadDialog.setContentView(mDialogView)
        val window = setHeadDialog.window
        window?.setGravity(gravity)
        val lp = window?.attributes
        window?.decorView?.setPadding(0, 0, 0, 0)
        lp?.width = PhoneUtils.getScreenWidth(AppliContext.get())
        lp?.height = ViewGroup.LayoutParams.MATCH_PARENT
        if (gravity == Gravity.TOP) {
            lp?.height = PhoneUtils.getScreenHeight(AppliContext.get())
        }
        window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
        window?.attributes = lp
        if (animation > 0)
            window?.setWindowAnimations(animation)//设置动画
        return mDialogView
    }

    /**
     * 领取红包奖励
     */
    fun getTaskRewardDialog(
        activity: Activity,
        reward: String,
        withdrawClick: View.OnClickListener
    ) {
        val mDialog = Dialog(activity, R.style.UpdateVersionCompatDialogTheme)
        val mDialogView =
            CenterDialog.showBottomDialog(
                R.layout.dialog_get_water_drop2,
                activity,
                mDialog,
                0,
                Gravity.CENTER
            )
        val layoutAd = mDialogView?.findViewById<FrameLayout>(R.id.layout_feed_ad)

        AdUtils.showFeedAd(activity, "receive_redPack_double_click", layoutAd)

        mDialogView.findViewById<ImageView>(R.id.lv_get_drop_close2).setOnClickListener {
            EventUtils.onEvent("click_close_receive_redPack_dialog", "点击关闭领取红包弹窗")
            mDialog.dismiss()
        }
        mDialogView.findViewById<TextView>(R.id.tv_get_drop_count4)?.text = reward
        mDialogView.findViewById<TextView>(R.id.btn_get_six_reward)?.setOnClickListener {
            if (Utils.isFastClick()) {
                withdrawClick.onClick(it)
                mDialog.dismiss()
            }
        }
        mDialog?.setCanceledOnTouchOutside(false)
        mDialog?.setCancelable(false)
        if (activity.isFinishing) {
            return
        }
        mDialog?.show()
    }

    /**
     * 转盘奖励
     * type:   奖励类型
     * waterDropCount:   奖励数量
     * adType: 广告的类型
     */
    fun showgetWaterDrop(
        context: Activity?,
        type: Int,
        adType: String,
        rewardCount: Int,
        list: TurntableEntity.SeedListEntity?
    ) {
        if (context == null) {
            return
        }
        val mDialog = Dialog(context, R.style.UpdateVersionCompatDialogTheme)
        val mDialogView =
            showBottomDialog(
                R.layout.dialog_get_water_drop,
                context,
                mDialog,
                0,
                Gravity.CENTER
            )

        val ivGetDropBg = mDialogView?.findViewById<ImageView>(R.id.iv_get_drop_bg)
        val ivtitle = mDialogView?.findViewById<ImageView>(R.id.id_img_title)
        val tvGetDropCount = mDialogView?.findViewById<TextView>(R.id.tv_get_drop_count)
        val layoutAd = mDialogView?.findViewById<FrameLayout>(R.id.layout_feed_ad)
        val llcontent2 = mDialogView?.findViewById<LinearLayout>(R.id.id_ll_content_2)
        val ivGetDropBg2 = mDialogView?.findViewById<ImageView>(R.id.iv_get_drop_bg2)
        val tvGetDropCount2 = mDialogView?.findViewById<TextView>(R.id.tv_get_drop_count2)
        val llcontent3 = mDialogView?.findViewById<LinearLayout>(R.id.id_ll_content_3)
        val ivGetDropBg3 = mDialogView?.findViewById<ImageView>(R.id.iv_get_drop_bg3)
        val tvGetDropCount3 = mDialogView?.findViewById<TextView>(R.id.tv_get_drop_count3)
        val tvget = mDialogView?.findViewById<FontTextView>(R.id.id_tv_gongxi_get)
        val btn_get_drop_happy_accept =
            mDialogView?.findViewById<ImageView>(R.id.btn_get_drop_happy_accept)
        //3 种子 4 金币 5 加速剂
        when (type) {
            3 -> {
                tvget.text = "恭喜获得种子"
                // ivtitle.setImageResource(R.mipmap.icon_img_title_get_zhongzi)
                llcontent2.visibility = View.GONE
                llcontent3.visibility = View.GONE
                if (list?.seedList?.size == 1) {
                    setImage(ivGetDropBg, list?.seedList[0].id)
                    tvGetDropCount.text = "+${list?.seedList[0].num}"
                } else if (list?.seedList?.size == 2) {
                    llcontent2.visibility = View.VISIBLE
                    setImage(ivGetDropBg, list?.seedList[0].id)
                    tvGetDropCount.text = "+${list?.seedList[0].num}"
                    setImage(ivGetDropBg2, list?.seedList[1].id)
                    tvGetDropCount2.text = "+${list?.seedList[1].num}"

                } else if (list?.seedList?.size == 3) {
                    llcontent2.visibility = View.VISIBLE
                    llcontent3.visibility = View.VISIBLE
                    setImage(ivGetDropBg, list?.seedList[0].id)
                    setImage(ivGetDropBg2, list?.seedList[1].id)
                    setImage(ivGetDropBg3, list?.seedList[2].id)
                    tvGetDropCount.text = "+${list?.seedList[0].num}"
                    tvGetDropCount2.text = "+${list?.seedList[1].num}"
                    tvGetDropCount3.text = "+${list?.seedList[2].num}"
                }

            }
            4 -> {
                // ivtitle.setImageResource(R.mipmap.icon_img_title_get_coin_)
                tvget.text = "恭喜获得"
                ivGetDropBg.setImageResource(R.mipmap.icon_speed_water)
                tvGetDropCount.text = "营养液x${rewardCount}"
            }
            5 -> {
                tvget.text = "恭喜获得"
                // ivtitle.setImageResource(R.mipmap.icon_img_title_get_speed_water)
                ivGetDropBg.setImageResource(R.mipmap.icon_speed_water)
                tvGetDropCount.text = "+${rewardCount}"
            }
        }

        AdUtils.showFeedAd(context, adType, layoutAd)
        FilterUtils.addClickAlpha(btn_get_drop_happy_accept)
        btn_get_drop_happy_accept.setOnClickListener {
            mDialog.dismiss()
        }
        mDialogView.findViewById<ImageView>(R.id.lv_get_drop_close).setOnClickListener {
            mDialog.dismiss()
        }

        mDialog.setCanceledOnTouchOutside(false)
        mDialog.setCancelable(false)
        if (context.isFinishing) {
            return
        }
        mDialog.show()
    }

    fun setImage(img: ImageView, id: Int) {
        when (id) {
            1 -> {
                img.setImageResource(R.mipmap.icon_flower_one)
            }
            2 -> {
                img.setImageResource(R.mipmap.icon_flower_two)
            }
            3 -> {
                img.setImageResource(R.mipmap.icon_flower_three)
            }
            4 -> {
                img.setImageResource(R.mipmap.icon_flower_four)
            }
            5 -> {
                img.setImageResource(R.mipmap.icon_flower_five)
            }
            6 -> {
                img.setImageResource(R.mipmap.icon_flower_six)
            }
            7 -> {
                img.setImageResource(R.mipmap.icon_flower_seven)
            }
            8 -> {
                img.setImageResource(R.mipmap.icon_flower_eight)
            }
            9 -> {
                img.setImageResource(R.mipmap.icon_flower_eight)
            }

        }
    }

    //
    fun showopenBox(
        context: Activity?,
        type: Int,
        adType: String,
        rewardCount: Int,
        result: FlyBoxEntity,
        mListener: IDialogViewCloseCallback
    ) {
        if (context == null) {
            return
        }
        val mDialog = Dialog(context, R.style.UpdateVersionCompatDialogTheme)
        val mDialogView =
            showBottomDialog(
                R.layout.dialog_get_water_drop,
                context,
                mDialog,
                0,
                Gravity.CENTER
            )

        val ivGetDropBg = mDialogView?.findViewById<ImageView>(R.id.iv_get_drop_bg)
        val tvGetDropCount = mDialogView?.findViewById<TextView>(R.id.tv_get_drop_count)
        val layoutAd = mDialogView?.findViewById<FrameLayout>(R.id.layout_feed_ad)
        val llcontent2 = mDialogView?.findViewById<LinearLayout>(R.id.id_ll_content_2)
        val ivGetDropBg2 = mDialogView?.findViewById<ImageView>(R.id.iv_get_drop_bg2)
        val tvGetDropCount2 = mDialogView?.findViewById<TextView>(R.id.tv_get_drop_count2)
        val llcontent3 = mDialogView?.findViewById<LinearLayout>(R.id.id_ll_content_3)
        val ivGetDropBg3 = mDialogView?.findViewById<ImageView>(R.id.iv_get_drop_bg3)
        val tvGetDropCount3 = mDialogView?.findViewById<TextView>(R.id.tv_get_drop_count3)
        var tvget = mDialogView?.findViewById<TextView>(R.id.id_tv_gongxi_get)
        var btn_get_drop_happy_accept =
            mDialogView?.findViewById<ImageView>(R.id.btn_get_drop_happy_accept)

        if (type == 1) {
            ivGetDropBg.setImageResource(R.mipmap.img_jiasuji)
            tvGetDropCount.text = "加速剂x${rewardCount}"
        }

        if (type == 2) {
            ivGetDropBg.setImageResource(R.mipmap.icon_clean_bug)
            tvGetDropCount.text = "杀虫剂x${rewardCount}"
        }

        //3 种子 4 金币 5 加速剂
//        when (type) {
//            1 -> {
//                tvget.text = "恭喜获得种子"
//                llcontent2.visibility = View.GONE
//                llcontent3.visibility = View.GONE
//                if (result.seedList?.size == 1) {
//                    setImage(ivGetDropBg, result.seedList[0].id)
//                    tvGetDropCount.text = "+${result.seedList[0].num}"
//                } else if (result.seedList?.size == 2) {
//                    llcontent2.visibility = View.VISIBLE
//                    setImage(ivGetDropBg, result.seedList[0].id)
//                    setImage(ivGetDropBg2, result.seedList[1].id)
//                    tvGetDropCount.text = "+${result.seedList[0].num}"
//                    tvGetDropCount2.text = "+${result.seedList[1].num}"
//
//                } else if (result.seedList?.size == 3) {
//                    llcontent2.visibility = View.VISIBLE
//                    llcontent3.visibility = View.VISIBLE
//                    setImage(ivGetDropBg, result.seedList[0].id)
//                    setImage(ivGetDropBg2, result.seedList[1].id)
//                    setImage(ivGetDropBg3, result.seedList[2].id)
//                    tvGetDropCount.text = "+${result.seedList[0].num}"
//                    tvGetDropCount2.text = "+${result.seedList[1].num}"
//                    tvGetDropCount3.text = "+${result.seedList[2].num}"
//                }
//
//            }
//            2 -> {
//                tvget.text = "恭喜获得金币"
//                ivGetDropBg.setImageResource(R.mipmap.icon_coin)
//                tvGetDropCount.text = "+${rewardCount}"
//            }
//            3 -> {
//                tvget.text = "恭喜获得加速剂"
//                ivGetDropBg.setImageResource(R.mipmap.icon_speed_water)
//                tvGetDropCount.text = "+${rewardCount}"
//            }
//        }

        //shwoAd(adType, context, layoutAd)
        FilterUtils.addClickAlpha(btn_get_drop_happy_accept)
        btn_get_drop_happy_accept.setOnClickListener {
            mDialog.dismiss()
            mListener.onCloseViewSuccess(true)
        }

        mDialogView.findViewById<ImageView>(R.id.lv_get_drop_close).setOnClickListener {
            mDialog.dismiss()
            mListener.onCloseViewSuccess(true)
        }

        AdUtils.showFeedAd((context), adType, layoutAd)

        mDialog.setCanceledOnTouchOutside(false)
        mDialog.setCancelable(false)
        if (context.isFinishing) {
            return
        }
        mDialog.show()
    }

    //福利中心开宝箱
    fun showWelfareOpenBox(
        context: Activity?,
        results: List<FlyBoxEntity>,
        mListener: IDialogViewCloseCallback
    ) {
        if (context == null) {
            return
        }
        EventUtils.onEvent("welfare_task_reward_box_show")
        val mDialog = Dialog(context, R.style.UpdateVersionCompatDialogTheme)
        val mDialogView =
            showBottomDialog(
                R.layout.dialog_get_welfare_drop,
                context,
                mDialog,
                0,
                Gravity.CENTER
            )

        val layout_seed = mDialogView?.findViewById<LinearLayout>(R.id.layout_seed)
        val layout_coins = mDialogView?.findViewById<LinearLayout>(R.id.layout_coins)
        val layout_accelerator = mDialogView?.findViewById<LinearLayout>(R.id.layout_accelerator)

        val tv_seed = mDialogView?.findViewById<TextView>(R.id.tv_seed)
        val iv_seed_bg = mDialogView?.findViewById<ImageView>(R.id.iv_seed_bg)
        val tv_coin = mDialogView?.findViewById<TextView>(R.id.tv_coin)
        val tv_accelerator = mDialogView?.findViewById<TextView>(R.id.tv_accelerator)
        val btn_get_drop_happy_accept =
            mDialogView.findViewById<ImageView>(R.id.btn_get_drop_happy_accept)
        val layoutAd = mDialogView?.findViewById<FrameLayout>(R.id.layout_feed_ad)

        for (entity in results) {
            //1种子 2金币 3加速剂
            when (entity.awardType) {
                1 -> {
                    layout_seed.visibility = View.VISIBLE
                    setImage(iv_seed_bg, entity.id)
                    tv_seed.text = "+${entity.awardNum}"
                }
                2 -> {
                    layout_coins.visibility = View.VISIBLE
                    tv_coin.text = "+${entity.awardNum}"
                }
                3 -> {
                    layout_accelerator.visibility = View.VISIBLE
                    tv_accelerator.text = "+${entity.awardNum}"
                }

            }
        }
        FilterUtils.addClickAlpha(btn_get_drop_happy_accept)
        btn_get_drop_happy_accept.setOnClickListener {
            mDialog.dismiss()
            mListener.onCloseViewSuccess(true)
        }
        mDialogView.findViewById<ImageView>(R.id.lv_get_drop_close).setOnClickListener {
            mDialog.dismiss()
            mListener.onCloseViewSuccess(true)
        }

        //  AdUtils.showFeedAd((context as Activity), "welfare_openbox", layoutAd)

        mDialog.setCanceledOnTouchOutside(false)
        mDialog.setCancelable(false)
        if (context.isFinishing) {
            return
        }
        mDialog.show()
    }

    //提现弹窗
    fun showWithDraw(
        context: Activity?,
        status: Int,
        title: String,
        reason: String,
        buttonText: String,
        buttonStatus: Int,
        id: Int?,
        type: Int?,
        jine: String?,
        isWelfarePage: Boolean,
        dialog: Dialog

    ) {
        if (context == null) {
            return
        }
        val mDialog = Dialog(context, R.style.UpdateVersionCompatDialogTheme)
        val mDialogView =
            showBottomDialog(
                R.layout.dialog_layout_with_draw_success,
                context,
                mDialog,
                0,
                Gravity.CENTER
            )

        val tvtitle = mDialogView?.findViewById<TextView>(R.id.id_img_title)
        val tvcashcontent = mDialogView?.findViewById<TextView>(R.id.id_tv_cash_content)
        val imggoon = mDialogView?.findViewById<ImageView>(R.id.id_tv_go_on_make_money)
        val withLL = mDialogView?.findViewById<LinearLayout>(R.id.withdraw_success_ll)
        val with_money = mDialogView?.findViewById<TextView>(R.id.withdraw_success_tv)
        tvtitle.text = title
        tvcashcontent.visibility = View.VISIBLE
        when (status) {
            1 -> {
                tvcashcontent.visibility = View.GONE
                withLL.visibility = View.VISIBLE
                with_money.text = buttonText + "元";
                // imgtitle.setImageResource(R.mipmap.img_duihuan_success)
                tvtitle.text = title
                imggoon.setImageResource(R.mipmap.img_go_zhongcai)
                /*if (type == 1) {
                    EventUtils.onEvent("xinshou0.3_show", "新手0.3")
                } else if (type == 4) {
                    EventUtils.onEvent("show_fuli0.3", "福利0.3")
                } else if (type == 7) {
                    EventUtils.onEvent("welfare_withdraw_success_dialog_show")
                } else if (type == 8) {
                    EventUtils.onEvent("attendance_withdraw_success_dialog_show")
                } else if (type == 10) {
                    EventUtils.onEvent("tixian_success_dfw_show", "大富翁提现成功")
                } else if (type == 11) {
                    EventUtils.onEvent("tixian_success_guaka_show", "刮卡提现成功")
                } else {
                    if (id != null) {
                        when (id) {
                            1 -> {
                                EventUtils.onEvent("show_hongmeigui", "番茄" + jine)
                            }
                            2 -> {
                                EventUtils.onEvent("show_zimeigui", "南瓜" + jine)
                            }
                            3 -> {
                                EventUtils.onEvent("show_linglan", "萝卜" + jine)
                            }
                            4 -> {
                                EventUtils.onEvent("show_juhua", "玉米" + jine)
                            }
                        }
                    }
                }*/
            }
            2 -> {
                //  imgtitle.setImageResource(R.mipmap.img_duihuan_success)
                imggoon.setImageResource(R.mipmap.img_go_zhongcai)
                // tvtitle.text = title
            }
            3 -> {
                // imgtitle.setImageResource(R.mipmap.img_wenxin_trip)
                imggoon.setImageResource(R.mipmap.img_i_konw)
                // tvtitle.text = title
            }
            4 -> {
                // imgtitle.setImageResource(R.mipmap.img_wenxin_trip)
                imggoon.setImageResource(R.mipmap.icon_go_shaizi)
            }
            5 -> {
                // imgtitle.setImageResource(R.mipmap.img_wenxin_trip)
                imggoon.setImageResource(R.mipmap.icon_go_guajiang)
            }
            6 -> {
                // imgtitle.setImageResource(R.mipmap.img_wenxin_trip)
                imggoon.setImageResource(R.mipmap.img_go_zhongcai)
            }
            7 -> {
                // imgtitle.setImageResource(R.mipmap.img_wenxin_trip)
                imggoon.setImageResource(R.mipmap.img_go_invite_friend)
            }
            8 -> {
                // imgtitle.setImageResource(R.mipmap.img_wenxin_trip)
                imggoon.setImageResource(R.mipmap.img_go_get_diamand)
            }
        }

        tvcashcontent.text = reason
        FilterUtils.addClickAlpha(imggoon)
        //imggoon.addClickScale()
        imggoon.setOnClickListener {
            if (buttonStatus == 0) {
                mDialog.dismiss()
            } else if (buttonStatus == 1) {
                mDialog.dismiss()
                dialog.dismiss()
                JumpUtils.jumpWelfareActivity()
//                JumpUtils.h5Jump("每日福利", Constant.Param.WelfareCenter, false, context as Activity)
            } else if (buttonStatus == 2) {
                if (isWelfarePage) {
//                    context.finish()
                }
                mDialog.dismiss()
                dialog.dismiss()

            } else if (buttonStatus == 4) {
                //免费领奖
                mDialog.dismiss()
                dialog.dismiss()
                JumpUtils.h5NormalJump(
                    "免费领奖",
                    NetConfig.H5.CONFIRMURL,
                    false,
                    context
                )
            } else if (buttonStatus == 5) {
                //刮刮卡
                mDialog.dismiss()
                dialog.dismiss()
                JumpUtils.h5Jump(
                    "幸运刮卡",
                    NetConfig.H5.guaguakaurl,
                    false,
                    context
                )

            } else if (buttonStatus == 6) {
                //邀请页
                mDialog.dismiss()
                dialog.dismiss()
                JumpUtils.h5NormalJump(
                    "邀请赚钱",
                    NetConfig.H5.InviteFriendsurl,
                    false,
                    context
                )
            }
        }

        mDialogView.findViewById<ImageView>(R.id.id_img_dialog_close).setOnClickListener {
            mDialog.dismiss()
        }
        mDialog?.setCanceledOnTouchOutside(false)
        mDialog?.setCancelable(false)
        if (context.isFinishing) {
            return
        }
        mDialog?.show()
    }

    fun showActivityDesc(activity: Activity) {
        if (activity == null) return
        val mDialog = Dialog(activity, R.style.UpdateVersionCompatDialogTheme)
        val mDialogView = showBottomDialog(
            R.layout.dialog_activity_desc,
            activity,
            mDialog,
            0,
            Gravity.CENTER
        )
        mDialogView.findViewById<ImageView>(R.id.id_img_dialog_activity_desc).setOnClickListener {
            mDialog.dismiss()
        }
        mDialog?.setCanceledOnTouchOutside(false)
        mDialog?.setCancelable(false)
        if (activity.isFinishing) {
            return
        }
        mDialog?.show()
    }

    // 获取碎片红包时的弹窗
    fun showDialoggetPuzzle(
        activity: Activity?,
        diffCardsNum: Int,
        onClickListener: View.OnClickListener
    ) {
        if (activity == null) return
        val mDialog = Dialog(activity, R.style.UpdateVersionCompatDialogTheme)
        val mDialogView = showBottomDialog(
            R.layout.dialog_get_puzzle,
            activity,
            mDialog,
            0,
            Gravity.CENTER
        )
        EventUtils.onEvent("show_suipianbuzu_dialog", "碎片不足弹窗曝光")
        mDialogView.findViewById<TextView>(R.id.id_tv_num_puzzle)?.text = "${diffCardsNum}"
        mDialogView.findViewById<ImageView>(R.id.id_img_close_get_puzzle).setOnClickListener {
            mDialog.dismiss()
        }
        mDialogView.findViewById<ImageView>(R.id.id_img_canle).setOnClickListener {
            mDialog.dismiss()
        }
        mDialogView.findViewById<ImageView>(R.id.id_img_sure).setOnClickListener {
            mDialog.dismiss()
            EventUtils.onEvent("click_pintu_quhuode_video", "去获得视频按钮点击")
            onClickListener.onClick(it)
        }
        mDialog?.setCanceledOnTouchOutside(false)
        mDialog?.setCancelable(false)
        if (activity.isFinishing) {
            return
        }
        mDialog?.show()
    }

    // 云朵加速的弹窗
    fun showDialogCloud(
        activity: Activity?,
        speedtime: Int,
        speedtimes: Int,
        onClickListener: View.OnClickListener
    ) {
        if (activity == null) return
        val mDialog = Dialog(activity, R.style.UpdateVersionCompatDialogTheme)
        val mDialogView = showBottomDialog(
            R.layout.dialog_cloud_speed,
            activity,
            mDialog,
            0,
            Gravity.CENTER
        )
        EventUtils.onEvent("show_cloud_speed_up_dialog", "云朵加速弹窗")
        val layoutAd = mDialogView?.findViewById<FrameLayout>(R.id.layout_feed_ad)
        val id_img_all_speed = mDialogView?.findViewById<ImageView>(R.id.id_img_all_speed)
        //AdUtils.showFeedAd(activity, "cloud_speed_bigimage", layoutAd)
        mDialogView.findViewById<TextView>(R.id.id_tv_speed_time)?.text = "所有土地获得${speedtime}分钟加速"
        mDialogView.findViewById<TextView>(R.id.id_cloud_speed_num)?.text =
            "今天剩余${speedtimes}次"
        mDialogView.findViewById<ImageView>(R.id.id_img_close_cloud_speed).setOnClickListener {
            mDialog.dismiss()
        }
        FilterUtils.addClickAlpha(id_img_all_speed)
        id_img_all_speed.setOnClickListener {
            EventUtils.onEvent("alljiasu_video_btn_click", "云朵加速视频点击")
            onClickListener.onClick(it)
            mDialog.dismiss()
        }

        mDialog?.setCanceledOnTouchOutside(false)
        mDialog?.setCancelable(false)
        if (activity.isFinishing) {
            return
        }
        mDialog?.show()
    }

    //生虫弹窗
    fun showDialogWorm(
        activity: Activity?,
        isShow: Boolean,
        onClickListener: View.OnClickListener,
        onClickNoVideoListener: View.OnClickListener
    ) {
        if (activity == null) return
        val mDialog = Dialog(activity, R.style.UpdateVersionCompatDialogTheme)
        val mDialogView = showBottomDialog(
            R.layout.dialog_worm,
            activity,
            mDialog,
            0,
            Gravity.CENTER
        )
        EventUtils.onEvent("stop_show", "除虫弹窗")
        val layoutAd = mDialogView?.findViewById<FrameLayout>(R.id.layout_feed_ad)
        //  AdUtils.showFeedAd(activity, "clean_worm", layoutAd)
        mDialogView.findViewById<ImageView>(R.id.id_img_close_clean_worm).setOnClickListener {
            mDialog.dismiss()
        }
        var cleanWormBtn = mDialogView.findViewById<ImageView>(R.id.id_img_clean_worm)
        cleanWormBtn.setOnClickListener {
            EventUtils.onEvent("weixiu_video_btn_click", "除虫看视频点击")
            onClickListener.onClick(it)
            mDialog.dismiss()
        }
        var cleanWormBtnNoVideo =
            mDialogView.findViewById<ImageView>(R.id.id_img_clean_worm_no_video)
        cleanWormBtnNoVideo.setOnClickListener {
            EventUtils.onEvent("weixiu_btn_click", "除虫点击")
            onClickNoVideoListener.onClick(it)
            mDialog.dismiss()
        }
        FilterUtils.addClickAlpha(cleanWormBtn)
        FilterUtils.addClickAlpha(cleanWormBtnNoVideo)
        //需要看视频
        if (isShow) {
            cleanWormBtn.visibility = View.VISIBLE
            cleanWormBtnNoVideo.visibility = View.GONE
        } else {
            cleanWormBtn.visibility = View.GONE
            cleanWormBtnNoVideo.visibility = View.VISIBLE
        }


        mDialog.setOnDismissListener(object : DialogInterface.OnDismissListener {
            override fun onDismiss(p0: DialogInterface?) {
//                onDestroy()
                AdUtils.loadFeedCacheAdToCache(activity)
            }
        })
        mDialog?.setCanceledOnTouchOutside(false)
        mDialog?.setCancelable(false)
        if (activity.isFinishing) {
            return
        }
        mDialog?.show()
    }

    /**
     * 加速器不足
     */
    fun showAccelerator(activity: Activity, getnum: Int, num: Int, listener: View.OnClickListener) {
        if (activity == null) return
        EventUtils.onEvent("jiasu_show")
        val mDialog = Dialog(activity, R.style.UpdateVersionCompatDialogTheme)
        val mDialogView =
            showBottomDialog(
                R.layout.dialog_layout_accelerator,
                activity,
                mDialog,
                0,
                Gravity.CENTER
            )

        val layout_dialog_root =
            mDialogView.findViewById<LinearLayout>(R.id.layout_accelerator_root)
        val btn_accelerator_btn = mDialogView.findViewById<ImageView>(R.id.btn_accelerator_btn)
        val tv_accelerator_num = mDialogView.findViewById<TextView>(R.id.tv_accelerator_num)
        val tv_get_num = mDialogView.findViewById<TextView>(R.id.tv_get_num)
        val iv_accelerator_close = mDialogView.findViewById<ImageView>(R.id.iv_accelerator_close)
        val layout_ad = mDialogView?.findViewById<FrameLayout>(R.id.layout_feed_ad)
        //  AdUtils.showFeedAd(activity, "accelerator_dialog_dialog", layout_ad)
        tv_get_num.text = "+${getnum}"
        tv_accelerator_num.text = "今天剩余${num}次"

        btn_accelerator_btn.setOnClickListener {
            mDialog?.dismiss()
            EventUtils.onEvent("jiasu_video_btn_click", "营养液视频按钮点击")
            listener.onClick(it)
        }

        iv_accelerator_close.setOnClickListener {
            mDialog?.dismiss()

        }

        FilterUtils.addClickAlpha(btn_accelerator_btn)

        mDialog.setCanceledOnTouchOutside(false)
        mDialog.setCancelable(false)
        if (activity.isFinishing) {
            return
        }
        mDialog?.show()

    }


    /**
     * 加速器不足
     */
    fun showCleanBug(activity: Activity, getnum: Int, num: Int, listener: View.OnClickListener) {
        if (activity == null) return
        EventUtils.onEvent("jiasu_show")
        val mDialog = Dialog(activity, R.style.UpdateVersionCompatDialogTheme)
        val mDialogView =
            showBottomDialog(
                R.layout.dialog_layout_cleanbug,
                activity,
                mDialog,
                0,
                Gravity.CENTER
            )

        val layout_dialog_root =
            mDialogView.findViewById<LinearLayout>(R.id.layout_accelerator_root)
        val btn_accelerator_btn = mDialogView.findViewById<ImageView>(R.id.btn_accelerator_btn)
        val tv_accelerator_num = mDialogView.findViewById<TextView>(R.id.tv_accelerator_num)
        val tv_get_num = mDialogView.findViewById<TextView>(R.id.tv_get_num)
        val iv_accelerator_close = mDialogView.findViewById<ImageView>(R.id.iv_accelerator_close)
        val layout_ad = mDialogView?.findViewById<FrameLayout>(R.id.layout_feed_ad)
        //  AdUtils.showFeedAd(activity, "accelerator_dialog_dialog", layout_ad)
        tv_get_num.text = "+${getnum}"
        tv_accelerator_num.text = "今天剩余${num}次"

        btn_accelerator_btn.setOnClickListener {
            mDialog?.dismiss()
            EventUtils.onEvent("jiasu_video_btn_click", "营养液视频按钮点击")
            listener.onClick(it)
        }

        iv_accelerator_close.setOnClickListener {
            mDialog?.dismiss()

        }

        FilterUtils.addClickAlpha(btn_accelerator_btn)

        mDialog.setCanceledOnTouchOutside(false)
        mDialog.setCancelable(false)
        if (activity.isFinishing) {
            return
        }
        mDialog?.show()

    }


    /**
     * 恭喜获得宝箱
     */
    fun showGetBox(
        activity: Activity,
        adNum: Int,
        adListener: View.OnClickListener
    ) {
        if (activity == null) return
        val mDialog = Dialog(activity, R.style.UpdateVersionCompatDialogTheme)
        val mDialogView =
            showBottomDialog(
                R.layout.dialog_layout_get_box,
                activity,
                mDialog,
                0,
                Gravity.CENTER
            )
        EventUtils.onEvent("box_show", "宝箱弹窗展示")
        val layout_dialog_root =
            mDialogView?.findViewById<LinearLayout>(R.id.layout_get_box_root)
        val iv_close = mDialogView?.findViewById<ImageView>(R.id.iv_get_box_close)
        val tv_get_box_num = mDialogView?.findViewById<TextView>(R.id.tv_get_box_num)
        val btn_get_box_btn =
            mDialogView?.findViewById<ImageView>(R.id.btn_get_box_btn)
        val layout_ad = mDialogView?.findViewById<FrameLayout>(R.id.layout_feed_ad)

        tv_get_box_num.text = "今天剩余${adNum}次"

        btn_get_box_btn.setOnClickListener {
            adListener.onClick(it)
            EventUtils.onEvent("box_video_btn_click", "宝箱视频按钮点击")
            mDialog?.dismiss()
        }

        FilterUtils.addClickAlpha(btn_get_box_btn)

        iv_close?.setOnClickListener {
            mDialog?.dismiss()
        }
        //   AdUtils.showFeedAd(activity, "get_box_dialog", layout_ad)


        mDialog.setCanceledOnTouchOutside(false)
        mDialog.setCancelable(false)
        if (!activity?.isFinishing) {
            mDialog?.show()
        }

//        layout_ad?.postDelayed({
//            layout_ad.visibility = View.VISIBLE
//            if (layout_ad?.visibility == View.VISIBLE) {
//                layout_dialog_root?.gravity = Gravity.BOTTOM
//            }
//        }, 500)
    }

    /**
     * 天天提现提示
     */
    fun showDailyTrip(activity: Activity, type: Int, num: Int, listener: View.OnClickListener) {
        if (activity == null) return
        // EventUtils.onEvent("")
        val mDialog = Dialog(activity, R.style.UpdateVersionCompatDialogTheme)
        val mDialogView =
            showBottomDialog(
                R.layout.dialog_layout_daily_trip,
                activity,
                mDialog,
                0,
                Gravity.CENTER
            )


        val id_img_go_todo = mDialogView.findViewById<ImageView>(R.id.id_img_go_todo)
        val tv_desc = mDialogView.findViewById<TextView>(R.id.tv_desc)
        val iv_daily_trip_close = mDialogView.findViewById<ImageView>(R.id.iv_daily_trip_close)
        val layout_ad = mDialogView?.findViewById<FrameLayout>(R.id.layout_feed_ad)
        //  AdUtils.showFeedAd(activity, "daily_trip_dialog_dialog", layout_ad)
        if (type == 10) {
            tv_desc.text = "去“免费领奖”掷骰子${num}次\n即可直接提现"
            id_img_go_todo.setImageResource(R.mipmap.icon_go_shaizi)
        } else if (type == 11) {
            tv_desc.text = "去“幸运抽奖”掷骰子${num}次\n即可直接提现"
            id_img_go_todo.setImageResource(R.mipmap.icon_go_guajiang)
        }
        id_img_go_todo.setOnClickListener {
            mDialog?.dismiss()
            //  EventUtils.onEvent("jiasu_video_btn_click", "加速器视频按钮点击")
            listener.onClick(it)
        }

        iv_daily_trip_close.setOnClickListener {
            mDialog?.dismiss()
        }

        FilterUtils.addClickAlpha(id_img_go_todo)

        mDialog.setCanceledOnTouchOutside(false)
        mDialog.setCancelable(false)
        if (activity.isFinishing) {
            return
        }
        mDialog?.show()

//        layout_ad?.postDelayed({
//            layout_ad.visibility = View.VISIBLE
//            if (layout_ad?.visibility == View.VISIBLE) {
//                layout_dialog_root?.gravity = Gravity.BOTTOM
//            }
//        }, 500)
    }

    /**
     * 添加点击缩放效果
     */
    fun View.addClickScale(scale: Float = 0.9f, duration: Long = 150) {
        this.setOnTouchListener { _, event ->
            when (event.action) {
                MotionEvent.ACTION_DOWN -> {
                    this.animate().scaleX(scale).scaleY(scale).setDuration(duration).start()
                }
                MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
                    this.animate().scaleX(1f).scaleY(1f).setDuration(duration).start()
                }
            }
            // 点击事件处理，交给View自身
            this.onTouchEvent(event)
        }
    }

}