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

import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.convenient.android.common.base.viewbinding.BaseBindingActivity
import com.convenient.android.lib.databinding.ActivityAdNativeListBinding
import com.convenient.android.lib.ui.sample.ad.adapter.NativeAdSampleListAdapter
import com.convenient.android.lib.ui.sample.ad.model.Datas
import kotlinx.coroutines.launch

/**
 * @classname:
 * @author: LiuXiaoLong
 * @date: 2022/9/8
 * description:原生广告在RecyclerView中的使用示例
 */
class AdNativeListActivity : BaseBindingActivity<ActivityAdNativeListBinding>(ActivityAdNativeListBinding::inflate) {

    private lateinit var adapter : NativeAdSampleListAdapter

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val adSlotName = intent.getStringExtra("ad_slot_name")?:Datas.NATIVE
        adapter = NativeAdSampleListAdapter()
        binding.recyclerView.layoutManager = LinearLayoutManager(this)
        binding.recyclerView.adapter = adapter

        lifecycleScope.launch {
            val list = Datas.getNativeADSampleLists(this@AdNativeListActivity, adSlotName)
            adapter.setData(list.toMutableList())
        }
    }
}