package com.convenient.android.lib.ui.sample.ad

import android.os.Bundle
import android.util.Log
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import com.composition.android.ad.admob.impl.AdmobInitialize
import com.composition.android.ad.applovinmax.impl.AppLovinMaxInitialize
import com.composition.android.ad.csj.impl.CSJInitialize
import com.composition.android.ad.gromore.impl.GroMoreInitialize
import com.composition.android.lib.ad.AdManager
import com.composition.android.lib.ad.AdUnitConfigManager
import com.composition.android.lib.ad.bean.AdUnitBean
import com.convenient.android.lib.ui.sample.ad.model.Datas
import com.convenient.android.lib.ui.sample.ad.page.AdMainPage
import com.convenient.android.lib.ui.theme.SampleTheme

class AdMainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            SampleTheme {
                AdMainPage()
            }
        }
        initAd()
    }


    private fun initAd() {
        AdManager.instance.init(applicationContext, true)
        AdManager.instance.initAdvertisersSDK(applicationContext, AdmobInitialize(), CSJInitialize("5320990"), GroMoreInitialize("5320990"), AppLovinMaxInitialize(logging = true))
        val list = mutableListOf<AdUnitBean>()
        list.addAll(Datas.AdmobAdUnitList)
        AdUnitConfigManager.instance.setAdUnits(list)

//        list.addAll(Datas.CSJAdUnitList)
//        list.addAll(Datas.GroMoreAdUnitList)
//        list.addAll(Datas.AppLovinMaxAdUnitList)
        AdManager.instance.addGlobalAdShowListener {
            Log.e("广告全局展示监听", "广告位名称：${it.adSlotName}\n广告商:${it.advertisersName}\n广告id:${it.adUnitId}\n广告类型:${it.adType}")
        }
    }


}