package com.ym.admodule.sh


import android.app.Activity
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.ym.admodule.config.ZXADCallback
import com.ym.admodule.listener.ZXADSplashListener
import com.ym.admodule.listener.ZXADVideoListener
import com.ym.modulecommon.module.NewsEntity
import com.ym.modulecommon.utils.AdEventUtils


object SHADUtils {
    private val TAG = "SHADUtils"
    //开屏
    fun loadSplashAd(newsEntity:NewsEntity,activity: Activity, container: ViewGroup, zxadListener: ZXADSplashListener?,
                     skipView: TextView?,zxadCallback: ZXADCallback) {
        CoralSplashImage(activity, 125)
            .container(container)
            .skip(skipView)
            .listen(object : CoralSplashImage.ISplashImageListener {
                override fun onAdError() {
                    AdEventUtils.onEventPullFail(newsEntity,AdEventUtils.AD_MODEL_SPLAH)
                    zxadCallback.onAdFail()
                }

                override fun onAdClicked() {
                    AdEventUtils.onEventClick(newsEntity,AdEventUtils.AD_MODEL_SPLAH)
                }

                override fun onAdShow() {
                    zxadListener?.onAdShow()
                    zxadCallback.onAdSuccess()
                    skipView?.visibility = View.VISIBLE
                    AdEventUtils.onEventShow(newsEntity)
                }

                override fun onTimeTick(msLeft: Long) {
                    skipView?.text = "跳过:" + msLeft / 1000
                    if(msLeft<=1000){
                        zxadListener?.onAdSkip()
                    }
                }

                override fun onTimesUp() {
                    zxadListener?.onAdSkip()
                    zxadCallback.onAdFail()
                    if (container.getChildAt(0) != null) {
                        container.removeAllViews()
                    }
                    skipView!!.text = "跳过:"
                }
            }).pull()

        skipView?.setOnClickListener {
            zxadListener?.onAdSkip()
        }
    }


    //激励视频
    fun loadRewardVideoAd(
        activity: Activity,
        entity: NewsEntity,
        listener: ZXADVideoListener,
        callback: ZXADCallback
    ) {

        CoralRewardVideo(activity, 104).build(entity,listener,callback).pull()
    }

    //视频流 带广告
    fun loadSHFeedSpecialVideoAd(activity: Activity,i:Int) {
        CoralVideoFeed(activity, 138).container(i).pull()
    }
}