package com.base.appzxhy.ui.deviceinfo

import android.content.Context
import android.view.ViewGroup
import com.base.appzxhy.R
import com.base.appzxhy.base.BaseActivity
import com.base.appzxhy.bean.DeviceInfoBean
import com.base.appzxhy.bean.DeviceInfoBean.Companion.BATTERY_INFORMATION
import com.base.appzxhy.bean.DeviceInfoBean.Companion.CAMERA_INFORMATION
import com.base.appzxhy.bean.DeviceInfoBean.Companion.DEVICE_INFORMATION
import com.base.appzxhy.bean.DeviceInfoBean.Companion.DISPLAY_INFORMATION
import com.base.appzxhy.bean.DeviceInfoBean.Companion.PROCESSOR_INFORMATION
import com.base.appzxhy.bean.DeviceInfoBean.Companion.RAM_INFORMATION
import com.base.appzxhy.bean.DeviceInfoBean.Companion.ROM_INFORMATION
import com.base.appzxhy.bean.DeviceInfoBean.Companion.WIFI_INFORMATION
import com.base.appzxhy.business.ads.AdsMgr
import com.base.appzxhy.business.ads.AdsShowCallBack
import com.base.appzxhy.databinding.ActivityDeviceInfoBinding
import com.base.appzxhy.databinding.ItemDeviceInformationBinding
import com.base.appzxhy.ui.adapter.CommonViewHolder
import com.base.appzxhy.ui.deviceinfo.DeviceInfoDetailActivity.Companion.DeviceInfoKey
import com.base.appzxhy.utils.XmlEx.inflate
import com.chad.library.adapter4.BaseQuickAdapter

class DeviceInfoActivity : BaseActivity<ActivityDeviceInfoBinding>(ActivityDeviceInfoBinding::inflate) {

    private val list by lazy {
        listOf(
            DeviceInfoBean(DEVICE_INFORMATION, R.drawable.icon_shouji, R.string.device_information),
            DeviceInfoBean(PROCESSOR_INFORMATION, R.drawable.icon_processor, R.string.processor_information),
            DeviceInfoBean(BATTERY_INFORMATION, R.drawable.icon_battery, R.string.battery_information),
            DeviceInfoBean(WIFI_INFORMATION, R.drawable.icon_wifi, R.string.wifi_information),
            DeviceInfoBean(DISPLAY_INFORMATION, R.drawable.icon_display, R.string.display_information),
            DeviceInfoBean(RAM_INFORMATION, R.drawable.icon_ram, R.string.ram_information),
            DeviceInfoBean(ROM_INFORMATION, R.drawable.icon_rom, R.string.rom_information),
            DeviceInfoBean(CAMERA_INFORMATION, R.drawable.icon_camera, R.string.camera_information),
        )
    }
    val adapter = object : BaseQuickAdapter<DeviceInfoBean, CommonViewHolder>() {
        override fun onBindViewHolder(
            holder: CommonViewHolder,
            position: Int,
            item: DeviceInfoBean?
        ) {
            item ?: return
            val itemBinding = ItemDeviceInformationBinding.bind(holder.itemView)
            itemBinding.ivIcon.setImageResource(item.iconRes)
            itemBinding.tv.setText(item.titleRes)
            itemBinding.root.setOnClickListener {
                AdsMgr.showInsert(this@DeviceInfoActivity, showCallBack = object : AdsShowCallBack() {
                    override fun next() {
                        DeviceInfoKey = item.key
                        goToAc(DeviceInfoDetailActivity::class.java)
                        overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left)
                    }
                })
            }
        }

        override fun onCreateViewHolder(
            context: Context,
            parent: ViewGroup,
            viewType: Int
        ): CommonViewHolder {
            return CommonViewHolder(R.layout.item_device_information.inflate(parent))
        }
    }

    override fun initView() {
        super.initView()
        binding.rv.adapter = adapter
        adapter.submitList(list)
    }

    override fun initListener() {
        super.initListener()
        binding.ivBack.setOnClickListener {
            onBackPressedDispatcher.onBackPressed()
        }
    }


}