package com.duben.microtribe.ui.activitys

import android.animation.ValueAnimator
import android.app.Dialog
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.text.TextUtils
import android.view.KeyEvent
import android.view.View
import android.widget.CompoundButton
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.daimajia.androidanimations.library.Techniques
import com.daimajia.androidanimations.library.YoYo
import com.duben.library.utils.GlideUtils
import com.duben.library.utils.nodoubleclick.AntiShake
import com.duben.microtribe.BuildConfig
import com.duben.microtribe.R
import com.duben.microtribe.common.AppConfig
import com.duben.microtribe.common.Constant
import com.duben.microtribe.manager.ActivityPageManager
import com.duben.microtribe.manager.UserManager
import com.duben.microtribe.mvp.model.*
import com.duben.microtribe.mvp.presenters.VipPresenter
import com.duben.microtribe.mvp.views.VipView
import com.duben.microtribe.ui.activitys.base.BaseActivity
import com.duben.microtribe.ui.adapter.VipAdapter
import com.duben.microtribe.ui.adapter.VipBannerAdapter
import com.duben.microtribe.ui.widgets.*
import com.duben.microtribe.ui.widgets.countdowntimer.CountDownTimerSupport
import com.duben.microtribe.ui.widgets.countdowntimer.OnCountDownTimerListener
import com.jobo.alipay.AliPay
import com.jobo.alipay.AlipayInfoImpl
import com.jobo.rxpay.RxPay
import com.jobo.rxpay.callback.IPayCallback
import com.jobo.wxpay.WXPay
import com.jobo.wxpay.WXPayInfoImpl
import com.youth.banner.listener.OnPageChangeListener
import kotlinx.android.synthetic.main.activity_new_vip.*


/**
 * 描述：支付
 * 作者：孟崔广
 * 时间：2022/12/22 14:48
 */
class VipActivity : BaseActivity(), VipView, View.OnClickListener,
    VipAdapter.OnItemClickListener,
    CompoundButton.OnCheckedChangeListener {

    companion object {
        const val IS_DETAIL = "IS_DETAIL"//是否从剧集详情页进入
        const val IS_MAIN = "IS_MAIN"//是否从首页进入
        const val IS_RECOMMEND = "IS_RECOMMEND"//是否从推荐页进入
        const val wxAppId = BuildConfig.WEIXIN_APP_PAY_ID
        const val WEIXIN_PAY = "WEIXIN_PAY"
        const val ALIPAY = "ALIPAY"
        const val THIRD_ID = "THIRD_ID"
        const val VEDIO_ID = "VEDIO_ID"
    }

    var timer: CountDownTimerSupport? = null

    private var breathAnim: YoYo.YoYoString? = null
    private var payAgreementDialog: PayAgreementDialog? = null
    private var payYesDialog: PayYesDialog? = null
    private var ruleAgreementDialog: RuleAgreementDialog? = null

    private val vipPresenter by lazy { VipPresenter() }
    private lateinit var vipAdapter: VipAdapter
    private var vipList: MutableList<VipBean.ListBean>? = null
    private var isCheckAgreeFlag: Boolean = true
    private var isDetail: Boolean = false
    private var isMain: Boolean = false
    private var isRecommend: Boolean = false
    private var payType = WEIXIN_PAY// 支付类型
    private var vedioId = ""
    private var thirdId = ""

    private val mainHandler = Handler(Looper.getMainLooper())

    override fun getContentViewLayoutID() = R.layout.activity_new_vip

    override fun toggleOverridePendingTransition() = true

    override fun getOverridePendingTransitionMode() = TransitionMode.BOTTOM

    override fun isApplyKitKatTranslucency() = false

    override fun getBundleExtras(extras: Bundle?) {
        super.getBundleExtras(extras)
        extras?.let {
            isDetail = it.getBoolean(IS_DETAIL, false)
            isMain = it.getBoolean(IS_MAIN, false)
            isRecommend = it.getBoolean(IS_RECOMMEND, false)
            thirdId = it.getString(THIRD_ID, "")
            vedioId = it.getString(VEDIO_ID, "")
        }
    }

    override fun initViewsAndEvents() {
        vipPresenter.attachView(this)
        if (!TextUtils.isEmpty(UserManager.getInstance().userID)) {
            vipPresenter.getVipProducts(isAliPayInstalled())
        } else {
            vipPresenter.userLogin(isAliPayInstalled())
        }
        if (isDetail && UserManager.getInstance().newFlag) {
            AppConfig.showVipAdDialog = true
        }

        vipPresenter.orders()

        AppConfig.enterVipAct = true

        initListener()
    }

    override fun finish() {
        super.finish()
        //关闭窗体动画显示
        overridePendingTransition(0, R.anim.push_bottom_out)
    }

    override fun onResume() {
        super.onResume()
        if (AppConfig.enterAlipay) {
            AppConfig.enterAlipay = false
            showLoading("查询支付结果...")
            startTimer()
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        if (!isMain) {
            AppConfig.enterVipAct = false
        }
        breathAnim?.stop()

        if (timer != null) { //防止计时器重复
            timer!!.stop()
            timer = null
        }

        vipPresenter.detachView()
    }

    override fun getVipProductSuc(data: VipBean) {
        if (!isFinishing) {
            if (data.list != null && data.list.size > 0) {
                vipList = data.list

                //设置content样式
                if (vipList != null && vipList!!.size > 0) {
                    setVipContent(vipList!![0])
                    cbVipAgreement.isChecked = data.isNeedClick
                }
                initRvView()
            }
        }
    }

    /**
     * 设置content样式
     */
    private fun setVipContent(bean: VipBean.ListBean) {
//        if (bean.isAlipay && bean.isWeixin) {
//            ll_vip_alipay.visibility = View.VISIBLE
//            ll_vip_wx.visibility = View.VISIBLE
//            payType = WEIXIN_PAY
//            iv_vip_wx.setImageResource(R.mipmap.ic_vip_enable_blue)
//            iv_vip_alipay.setImageResource(R.mipmap.ic_vip_none)
//        } else if (bean.isAlipay && !bean.isWeixin) {
//            ll_vip_alipay.visibility = View.VISIBLE
//            ll_vip_wx.visibility = View.GONE
//            payType = ALIPAY
//            iv_vip_alipay.setImageResource(R.mipmap.ic_vip_enable_blue)
//            iv_vip_wx.setImageResource(R.mipmap.ic_vip_none)
//        } else if (!bean.isAlipay && bean.isWeixin) {
//            ll_vip_alipay.visibility = View.GONE
//            ll_vip_wx.visibility = View.VISIBLE
//            payType = WEIXIN_PAY
//            iv_vip_wx.setImageResource(R.mipmap.ic_vip_enable_blue)
//            iv_vip_alipay.setImageResource(R.mipmap.ic_vip_none)
//        }

        ll_vip_alipay.visibility = View.VISIBLE
        ll_vip_wx.visibility = View.GONE
        payType = ALIPAY
        iv_vip_alipay.setImageResource(R.mipmap.ic_vip_enable_blue)
        iv_vip_wx.setImageResource(R.mipmap.ic_vip_none)


        if (!TextUtils.isEmpty(bean.remarks)) {
            tv_vip_hint.text = bean.remarks
            tv_vip_hint.visibility = View.VISIBLE
        } else {
            tv_vip_hint.visibility = View.INVISIBLE
        }

        if (!TextUtils.isEmpty(bean.buttonText)) {
            tvVipPay.text = bean.buttonText
            tvVipAgreement.text = "点击购买即表示您同意《自动续费协议》"
        } else {
            tvVipPay.text = "立即开通"
            tvVipAgreement.text = "点击购买即表示您同意《会员付费协议》"
        }
    }

    override fun getVipPayParamsSuc(payChannel: String, paramsBean: WxPayParamBean) {
        if (!isFinishing) {
            if (TextUtils.equals(payChannel, "WEIXIN")) {
                if (paramsBean.params == null) {
                    showToast("微信支付维护中")
                    return
                }

                wxPay(paramsBean)
            } else {
                if (paramsBean.params == null) {
                    showToast("支付宝支付维护中")
                    return
                }

                alipay(paramsBean)
            }
        }
    }

    override fun queryVipOrderSuc(isPay: Boolean) {
        if (isFinishing) return

        if (isPay) {
            showToast("支付成功")

//            if (isRecommend) {
//                finish()
//            } else {
//                if (!UserManager.getInstance().userIsLogin()) {
//                    val b = Bundle()
//                    b.putString(MobileLoginActivity.TYPE, "vip")
//                    readyGoThenKill(MobileLoginActivity::class.java, b)
//                } else {
//                    readyGoThenKill(MainActivity::class.java)
//                }
//            }
            if (!UserManager.getInstance().userIsLogin()) {
                val b = Bundle()
                b.putString(MobileLoginActivity.TYPE, "vip")
                readyGoThenKill(MobileLoginActivity::class.java, b)
            } else {
                readyGoThenKill(MainActivity::class.java)
            }
        }
    }

    override fun getUserSuc(data: UserBean) {
        if (data.expireTime > 0) {
            readyGo(MainActivity::class.java)
            val activity =
                ActivityPageManager.getInstance().getActivity(MainActivity::class.java)
            if (activity != null && activity is MainActivity) {
                activity.clickTab4Layout()
            }
        }
    }

    override fun ordersSuc(data: BannerList?) {
        data?.let {
            setBanner(it.list)
        }
    }

    override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
        when (keyCode) {
            KeyEvent.KEYCODE_BACK -> {
                if (UserManager.getInstance().newFlag
                    && vipList != null && vipList!!.size > 0
                ) {

                    vipAdapter.setPosition(0)
                    vipAdapter.notifyDataSetChanged()
                    val vipBean = vipList!![0]
                    if (vipBean.trial == 1) {
                        ll_vip_alipay.visibility = View.VISIBLE
                        ll_vip_wx.visibility = View.GONE
                        payType = ALIPAY
                        iv_vip_alipay.setImageResource(R.mipmap.ic_vip_enable_blue)
                        iv_vip_wx.setImageResource(R.mipmap.ic_vip_none)
                    }
                    backPayYesDialog(vipBean)
                    return true
                }

                finish()
            }
        }
        return true
    }

    override fun onClick(v: View?) {
        if (AntiShake.check(v?.id)) return

        when (v?.id) {
            R.id.ic_vip_quit -> {
                if (UserManager.getInstance().newFlag &&
                    vipList != null && vipList!!.size > 0
                ) {
                    vipAdapter.setPosition(0)
                    vipAdapter.notifyDataSetChanged()
                    val vipBean = vipList!![0]
                    if (vipBean.trial == 1) {
                        ll_vip_alipay.visibility = View.VISIBLE
                        ll_vip_wx.visibility = View.GONE
                        payType = ALIPAY
                        iv_vip_alipay.setImageResource(R.mipmap.ic_vip_enable_blue)
                        iv_vip_wx.setImageResource(R.mipmap.ic_vip_none)
                    }
                    backPayYesDialog(vipBean)
                } else {
                    finish()
                }
            }
            R.id.tvVipPay -> {
                if (vipList != null && vipList!!.size > 0) {
                    val vipBean = vipList!![vipAdapter.getPosition()]

                    if (!isCheckAgreeFlag) {
                        vipAgreementDialog(vipBean)
                        return
                    }

                    if (vipBean.isShowCycTips) {
                        agreementPayDialog()
                    } else {
                        if (TextUtils.equals(payType, WEIXIN_PAY)) {
                            vipPresenter.getVipPayParams(
                                "WEIXIN",
                                vipBean.pid, isAliPayInstalled()
                            )
                        } else if (TextUtils.equals(payType, ALIPAY)) {
                            vipPresenter.getVipPayParams(
                                "ALIPAY",
                                vipBean.pid, isAliPayInstalled()
                            )
                        }
                    }
                } else {
                    showToast("产品未配置")
                }
            }
            R.id.tvVipAgreement -> {
                val bundle = Bundle()
                bundle.putString(WebActivity.WEB_TITLE, getString(R.string.members_name))
                bundle.putString(WebActivity.WEB_URL, Constant.MEMBERS_URL)
                readyGo(WebActivity::class.java, bundle)
            }
            R.id.ll_vip_alipay -> {
                payType = ALIPAY
                iv_vip_alipay.setImageResource(R.mipmap.ic_vip_enable_blue)
                iv_vip_wx.setImageResource(R.mipmap.ic_vip_none)
            }
            R.id.ll_vip_wx -> {
                payType = WEIXIN_PAY
                iv_vip_wx.setImageResource(R.mipmap.ic_vip_enable_blue)
                iv_vip_alipay.setImageResource(R.mipmap.ic_vip_none)
            }
        }
    }

    private fun initRvView() {
        if (vipList != null && vipList!!.size > 0) {
            val gridLayoutManager = LinearLayoutManager(this)
            rvVip.layoutManager = gridLayoutManager
            vipAdapter = VipAdapter(vipList!!)
            rvVip.adapter = vipAdapter
            vipAdapter.setOnItemClickListener(this)
        }
    }

    private fun initListener() {
        shimmer_text?.postDelayed({
            shimmer_text?.startShimmerAnimation()
            breathAnim =
                YoYo.with(Techniques.Pulse).duration(700).repeat(-1).playOn(shimmer_text)
        }, 200)

        ic_vip_quit.setOnClickListener(this)
        tvVipPay.setOnClickListener(this)
        tvVipAgreement.setOnClickListener(this)
        ll_vip_alipay.setOnClickListener(this)
        ll_vip_wx.setOnClickListener(this)
        cbVipAgreement.setOnCheckedChangeListener(this)

    }

    override fun onItemClick(position: Int) {
        vipAdapter.setPosition(position)
        vipAdapter.notifyDataSetChanged()

        //设置content样式
        if (vipList != null && vipList!!.size > 0) {
            setVipContent(vipList!![position])
        }
    }

    fun wxPay(wxParanBean: WxPayParamBean) {
        val data = wxParanBean.params
        //实例化微信支付策略
        val wxPay: WXPay = WXPay.getInstance()
        //构造微信订单实体。一般都是由服务端直接返回。
        val wxPayInfoImpl = WXPayInfoImpl()
        wxPayInfoImpl.timestamp = data.timestamp
        wxPayInfoImpl.sign = data.sign
        wxPayInfoImpl.prepayId = data.prepayid
        wxPayInfoImpl.partnerid = data.partnerid
        wxPayInfoImpl.appid = wxAppId
        wxPayInfoImpl.nonceStr = data.noncestr
        wxPayInfoImpl.packageValue = data.packageX
        //策略场景类调起支付方法开始支付，以及接收回调。
        RxPay.pay(wxPay, this, wxPayInfoImpl, object : IPayCallback {
            override fun success() {
                AppConfig.showVipAdDialog = false
                UserManager.getInstance().vipFlag = true
                vipPresenter.queryVipOrder(wxParanBean.tid.toString(), true)
            }

            override fun failed(code: Int, message: String?) {
                vipPresenter.queryVipOrder(wxParanBean.tid.toString(), false)

            }

            override fun cancel() {
                vipPresenter.queryVipOrder(wxParanBean.tid.toString(), false)

            }
        })
    }

    fun alipay(wxParanBean: WxPayParamBean) {
        try {
            // 自动签约付费
            if (wxParanBean.params.isSign) {
                AppConfig.enterAlipay = true
                openAutoAlipay(wxParanBean.params.params)
                return
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }


        //实例化支付宝支付策略
        val aliPay = AliPay()
        //构造支付宝订单实体。一般都是由服务端直接返回。
        val alipayInfoImpl = AlipayInfoImpl()
        alipayInfoImpl.setOrderInfo(wxParanBean.params.params)
        //策略场景类调起支付方法开始支付，以及接收回调。
        RxPay.pay(aliPay, this, alipayInfoImpl, object : IPayCallback {
            override fun success() {
                AppConfig.showVipAdDialog = false
                UserManager.getInstance().vipFlag = true
                vipPresenter.queryVipOrder(wxParanBean.tid.toString(), true)
            }

            override fun failed(code: Int, message: String?) {
                vipPresenter.payError(code)
                if (!TextUtils.isEmpty(message)) {
                    showToast(message)
                }
            }

            override fun cancel() {
                vipPresenter.queryVipOrder(wxParanBean.tid.toString(), false)

                mainHandler.postDelayed(
                    {
                        if (isFinishing) return@postDelayed

                        // 挽留弹窗存在也不弹
                        if (payYesDialog != null && payYesDialog!!.isShowing) return@postDelayed

                        if (vipList != null && vipList!!.size > 0) {
                            val vipBean = vipList!![vipAdapter.getPosition()]
                            // 0.01
                            if (vipBean.trial != 0) {
                                showPayCancelDialog()
                            }
                        }

                    },
                    2000
                )
            }
        })
    }

    /**
     * 检测是否安装支付宝
     *
     * true-安装支付宝
     */
    fun isAliPayInstalled(): Boolean {
        try {
            val uri: Uri = Uri.parse("alipays://platformapi/startApp")
            val intent = Intent(Intent.ACTION_VIEW, uri)
            val componentName = intent.resolveActivity(context.getPackageManager())
            return componentName != null
        } catch (e: Exception) {
            e.printStackTrace()
            return false
        }
    }

    /**
     * 自动续费
     */
    fun openAutoAlipay(url: String) {
        val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
        startActivity(intent)
    }

    override fun onCheckedChanged(buttonView: CompoundButton?, isChecked: Boolean) {
        isCheckAgreeFlag = isChecked
    }

    /**
     * 返回支付弹窗-签约
     */
    private fun backPayYesDialog(vipBean: VipBean.ListBean) {
        payYesDialog = PayYesDialog(context, vipBean, object : DialogListener() {
            override fun onClick(v: View) {
                if (!isFinishing() && payYesDialog != null && payYesDialog!!.isShowing()) {
                    payYesDialog!!.dismiss()
                }
                when (v.id) {
                    R.id.iv_dialog_vip_quit -> {
                        finish()
//                        payYesDialog!!.dismiss()
                    }
                    R.id.tv_dialog_vip_next -> {
                        cbVipAgreement.isChecked = true

                        if (vipList != null && vipList!!.size > 0) {
                            val vipBean = vipList!![vipAdapter.getPosition()]
                            if (TextUtils.equals(payType, WEIXIN_PAY)) {
                                vipPresenter.getVipPayParams(
                                    "WEIXIN",
                                    vipBean.pid, isAliPayInstalled()
                                )
                            } else if (TextUtils.equals(payType, ALIPAY)) {
                                vipPresenter.getVipPayParams(
                                    "ALIPAY",
                                    vipBean.pid, isAliPayInstalled()
                                )
                            }
                        } else {
                            showToast("产品未配置")
                        }
                    }
                }
            }
        })
        payYesDialog!!.show()
    }

    /**
     * 自动续费协议弹窗-支付宝
     */
    private fun agreementPayDialog() {
        payAgreementDialog = PayAgreementDialog(context, object : DialogListener() {
            override fun onClick(v: View) {
                if (!isFinishing() && payAgreementDialog != null && payAgreementDialog!!.isShowing()) {
                    payAgreementDialog!!.dismiss()
                }
                when (v.id) {
                    R.id.tv_agreement_next -> {
                        ruleAgreementPayDialog()
                    }
                }
            }
        })
        payAgreementDialog!!.show()
    }

    /**
     * 试用订阅规则说明-仿支付宝
     */
    private fun ruleAgreementPayDialog() {
        if (vipList != null && vipList!!.size > 0) {
            val vipBean = vipList!![vipAdapter.getPosition()]
            ruleAgreementDialog = RuleAgreementDialog(context, object : DialogListener() {
                override fun onClick(v: View) {
                    if (!isFinishing() && ruleAgreementDialog != null && ruleAgreementDialog!!.isShowing()) {
                        ruleAgreementDialog!!.dismiss()
                    }
                    when (v.id) {
                        R.id.tv_agreement_next -> {
                            if (TextUtils.equals(payType, WEIXIN_PAY)) {
                                vipPresenter.getVipPayParams(
                                    "WEIXIN",
                                    vipBean.pid, isAliPayInstalled()
                                )
                            } else if (TextUtils.equals(payType, ALIPAY)) {
                                vipPresenter.getVipPayParams(
                                    "ALIPAY",
                                    vipBean.pid, isAliPayInstalled()
                                )
                            }

                        }
                    }
                }
            })
            ruleAgreementDialog!!.setText(
                vipBean.remarks,
                vipBean.trialFirstDay,
                vipBean.price,
                vipBean.title
            )
            ruleAgreementDialog!!.show()
        } else {
            showToast("产品未配置")
        }
    }

    /**
     * 未勾选协议弹窗
     */
    private fun vipAgreementDialog(bean: VipBean.ListBean) {
        var agreeStr = "会员付费协议"
        if (bean.isShowCycTips) {
            agreeStr = "自动续费协议"
        }
        val cdaa = CustomDialogAgreement(context, object : DialogListener() {
            override fun onClick(dialog: Dialog?, v: View?) {
                dialog?.dismiss()
                when (v?.id) {
                    R.id.dialog_btn_right -> {
                        cbVipAgreement.isChecked = true


                        if (vipList != null && vipList!!.size > 0) {
                            val vipBean = vipList!![vipAdapter.getPosition()]
                            if (vipBean.isShowCycTips) {
                                agreementPayDialog()
                            } else {
                                if (TextUtils.equals(payType, WEIXIN_PAY)) {
                                    vipPresenter.getVipPayParams(
                                        "WEIXIN",
                                        vipBean.pid, isAliPayInstalled()
                                    )
                                } else if (TextUtils.equals(payType, ALIPAY)) {
                                    vipPresenter.getVipPayParams(
                                        "ALIPAY",
                                        vipBean.pid, isAliPayInstalled()
                                    )
                                }
                            }
                        } else {
                            showToast("产品未配置")
                        }
                    }
                }
            }
        })
        cdaa.setTitle(agreeStr)
        cdaa.setContent(agreeStr)
        cdaa.setLeft("不同意")
        cdaa.setLeftColor(R.color.gray)
        cdaa.setRight("同意")
        cdaa.setRightColor(R.color.main_mints)
        cdaa.show()
    }

    private fun setBanner(data: List<VedioBean>) {
        mainHandler.postDelayed({
            val scrollToBottomAnimator =
                ValueAnimator.ofInt(0, nsv.getChildAt(0).height - nsv.height)
            scrollToBottomAnimator.addUpdateListener { animator ->
                val value = animator.animatedValue as Int
                nsv.scrollTo(0, value)
            }
            scrollToBottomAnimator.duration = 2000
            scrollToBottomAnimator.start()
        }, 500)

        mainHandler.postDelayed({
            val scrollToTopAnimator = ValueAnimator.ofInt(nsv.scrollY, 0)
            scrollToTopAnimator.addUpdateListener { animator ->
                val value = animator.animatedValue as Int
                nsv.scrollTo(0, value)
            }
            scrollToTopAnimator.duration = 1500
            scrollToTopAnimator.start()
        }, 3000)

        val adapter = VipBannerAdapter(data)
        // 绑定生命周期
        vip_banner.addBannerLifecycleObserver(this)
            .setBannerGalleryEffect(80, 15, 0.8f)
            .setAdapter(adapter)
            .addOnPageChangeListener(object : OnPageChangeListener {
                override fun onPageScrolled(
                    position: Int,
                    positionOffset: Float,
                    positionOffsetPixels: Int
                ) {
                }

                override fun onPageSelected(position: Int) {
                    GlideUtils.loadBlurImageView(mContext, data[position].coverImage, iv_blur)
                    tv_banner_title.text = String.format("《%1s》", data[position].title)
                }

                override fun onPageScrollStateChanged(state: Int) {}
            })
        GlideUtils.loadBlurImageView(mContext, data[0].coverImage, iv_blur)
        tv_banner_title.text = String.format("《%1s》", data[0].title)
    }

    private fun showPayCancelDialog() {
        val vipBean = vipList!![0]
        VipPayCancelDialog(this, vipBean.price, object : DialogListener() {
            override fun onClick(dialog: Dialog?, v: View?) {
                super.onClick(dialog, v)
                dialog?.dismiss()


                vipPresenter.getVipPayParams(
                    "ALIPAY",
                    vipBean.pid, isAliPayInstalled()
                )
            }
        })
            .show()
    }

    fun startTimer() {
        if (timer != null) { //防止计时器重复
            timer!!.stop()
            timer = null
        }
        timer = CountDownTimerSupport(9000, 1000)
        timer!!.setOnCountDownTimerListener(object : OnCountDownTimerListener {
            override fun onTick(millisUntilFinished: Long) {
                if (!isFinishing) {
                    if (millisUntilFinished == 4000L) {
                        vipPresenter.getMyInfo()
                    }
                }
            }

            override fun onFinish() {
                if (!isFinishing) {
                    hideLoading()
                    vipPresenter.getMyInfo()
                }
            }
        })
        timer!!.start()
    }
}