package com.easy.clean.ui.recyclebin

import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import com.easy.clean.R
import com.easy.clean.base.BaseFragment
import com.easy.clean.base.goToAc
import com.easy.clean.business.ads.AdsMgr
import com.easy.clean.databinding.FragmentRecycleBinBinding
import com.easy.clean.ui.main.MainActivity
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch

class RecycleBinFragment : BaseFragment<FragmentRecycleBinBinding>(FragmentRecycleBinBinding::inflate) {

    private val adapter = RecycleBinAdapter()
    override fun initView() {
        super.initView()
        AdsMgr.showNative(binding.flAd, R.layout.layout_admob_native_custom)
        binding.rv.adapter = adapter

        lifecycleScope.launch {
            (requireActivity() as MainActivity).viewModel.recycleBinFileFlow.collectLatest {
                binding.llEmpty.isVisible = it.isEmpty()
                adapter.submitList(it)
            }
        }
    }

    override fun initListener() {
        super.initListener()
        adapter.clickAction = {
            RecycleBinDetailActivity.recycleBinFile = it
            goToAc(RecycleBinDetailActivity::class.java)
        }
    }

}