package com.base.appzxhy.business.pangle

import android.view.Gravity
import android.widget.FrameLayout
import com.base.appzxhy.GlobalConfig.ID_PANGLE_BANNER_300X250
import com.base.appzxhy.GlobalConfig.ID_PANGLE_BANNER_320X50
import com.bytedance.sdk.openadsdk.api.banner.PAGBannerAd
import com.bytedance.sdk.openadsdk.api.banner.PAGBannerAdInteractionListener
import com.bytedance.sdk.openadsdk.api.banner.PAGBannerAdLoadListener
import com.bytedance.sdk.openadsdk.api.banner.PAGBannerRequest
import com.bytedance.sdk.openadsdk.api.banner.PAGBannerSize.BANNER_W_300_H_250
import com.bytedance.sdk.openadsdk.api.banner.PAGBannerSize.BANNER_W_320_H_50

class PangleBannerMgr {


    fun showBanner(fl: FrameLayout) {

        fl.removeAllViews()

        val bannerRequest = PAGBannerRequest(BANNER_W_320_H_50)


        PAGBannerAd.loadAd(ID_PANGLE_BANNER_320X50, bannerRequest, object : PAGBannerAdLoadListener {
            override fun onError(code: Int, message: String?) {
                fl.removeAllViews()
            }

            override fun onAdLoaded(bannerAd: PAGBannerAd?) {
                bannerAd ?: return

                val mPAGBannerAd = bannerAd
                mPAGBannerAd.setAdInteractionListener(object : PAGBannerAdInteractionListener {
                    override fun onAdShowed() {
                    }

                    override fun onAdClicked() {
                    }

                    override fun onAdDismissed() {
                    }
                })
                val params = FrameLayout.LayoutParams(
                    FrameLayout.LayoutParams.MATCH_PARENT,
                    FrameLayout.LayoutParams.WRAP_CONTENT
                )
                params.gravity = Gravity.CENTER
                fl.addView(mPAGBannerAd.bannerView, params)
            }

        })
    }
}