package com.base.browserwhite.ui.activity.cleanjunk

import android.graphics.Color
import androidx.core.view.updatePadding
import androidx.lifecycle.lifecycleScope
import com.base.browserwhite.R
import com.base.browserwhite.bean.ParentBean
import com.base.browserwhite.databinding.ActivityScanJunkBinding
import com.base.browserwhite.ui.activity.BaseActivity
import com.base.browserwhite.ui.adapter.JunkScanAdapter
import com.base.browserwhite.utils.BarUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class ScanJunkActivity : BaseActivity<ActivityScanJunkBinding>() {

    private lateinit var junkScanAdapter: JunkScanAdapter

    override val binding: ActivityScanJunkBinding by lazy {
        ActivityScanJunkBinding.inflate(layoutInflater)
    }

    override fun initView() {
        BarUtils.setStatusBarLightMode(this, true)
        BarUtils.setStatusBarColor(this, Color.TRANSPARENT)
        binding.root.updatePadding(top = BarUtils.getStatusBarHeight())


        junkScanAdapter = JunkScanAdapter()
        binding.rv.adapter = junkScanAdapter

        beginScan()
    }

    override fun initListener() {
        super.initListener()
        binding.flFanhui.setOnClickListener {
            finishToMain()
        }
    }

    private fun beginScan() {
        lifecycleScope.launch(Dispatchers.Main) {
            junkScanAdapter.addData(ParentBean(R.mipmap.x_residual, "Residual File"), 0)
            delay(300)
            junkScanAdapter.addData(ParentBean(R.mipmap.x_useless, "Useless installation package"), 1)
            delay(300)
            junkScanAdapter.addData(ParentBean(R.mipmap.x_temp, "Temp Files"), 2)
            delay(300)
            junkScanAdapter.addData(ParentBean(R.mipmap.x_residual, "Log Files"), 3)

        }


    }


}