package com.zxhl.main.page.view


import android.animation.ValueAnimator
import android.app.Dialog
import android.content.Context
import android.util.Log

import android.view.Gravity
import android.view.animation.AnimationUtils
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import com.airbnb.lottie.LottieAnimationView
import com.zxhl.cms.common.Constant
import com.zxhl.cms.net.ApiClient
import com.zxhl.cms.net.RxSchedulers
import com.zxhl.cms.net.callback.BaseObserver
import com.zxhl.cms.net.model.box.MarqueeEntity
import com.zxhl.cms.utils.JumpUtils
import com.zxhl.main.R
import kotlinx.android.synthetic.main.layout_top_box.*

//新人免费弹窗
object FreeGoodsDialog {
    private var context: Context? = null
    private var mDialog: Dialog? = null
    private var tv_yi_fa: TextView? = null
    private var dialog_lottie_view: LottieAnimationView? = null
    fun showFreeGoosDialog(context: Context?) {
        if (context == null) {
            return
        }
        this.context = context
        mDialog = Dialog(context, R.style.CenterCompatDialogTheme)
        val mDialogView =
            DialogUtils.showBottomDialog(
                R.layout.dialog_layout_free_goods,
                context,
                mDialog!!,
                0,
                Gravity.CENTER
            )
        dialog_lottie_view =
            mDialogView?.findViewById<LottieAnimationView>(R.id.id_dialog_lottie_view)
        tv_yi_fa = mDialogView?.findViewById<TextView>(R.id.id_tv_yi_fa)
        mDialogView?.findViewById<Button>(R.id.id_img_dialog_close).setOnClickListener {
            mDialog?.dismiss()
            ApiClient.homeApi.canceChoose("-2")
                .compose(RxSchedulers.observableIO2Main())
                .subscribe(object : BaseObserver<Any>() {
                    override fun onSuccess(result: Any?) {

                    }

                    override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
                        Log.e("MXL", "error" + errorMsg + "code" + code + e)
                    }
                })
        }
        dialog_lottie_view?.imageAssetsFolder = "xinren/images/"
        dialog_lottie_view?.setAnimation("xinren/data.json")
        dialog_lottie_view?.playAnimation()
        tv_yi_fa?.animation =
            AnimationUtils.loadAnimation(context, R.anim.button_scale_anim)
        dialog_lottie_view?.setOnClickListener {
            JumpUtils.lotteryBoxJump("-2", Constant.Key.ONE_LOTTERY, "0")
            mDialog?.dismiss()
        }
        mDialog?.setCanceledOnTouchOutside(false)
        mDialog?.setCancelable(false)
        mDialog?.show()

        mDialog?.setOnDismissListener {
            Log.d("MXL","我被关闭了")
        }
    }
}