//package com.zxhyis.toolss.ui.home
//
//
//import android.annotation.SuppressLint
//import android.content.Intent
//import android.os.Bundle
//import android.os.Environment
//import android.os.StatFs
//import android.view.LayoutInflater
//import android.view.View
//import android.view.ViewGroup
//import androidx.core.content.ContextCompat
//import com.bumptech.glide.Glide
//import com.zxhyis.toolss.R
//import com.zxhyis.toolss.ad.AdmobUtils
//import com.zxhyis.toolss.base.TopFragment
//import com.zxhyis.toolss.cx.FileHelps.toFormatSize
//import com.zxhyis.toolss.databinding.FragmentHomeBinding
//import com.zxhyis.toolss.logic.setOnClick
//import com.zxhyis.toolss.logic.setStatusBarTextLight
//import com.zxhyis.toolss.logic.startActivity
//import com.zxhyis.toolss.ui.page.AllFilesActivity
//import com.zxhyis.toolss.ui.page.AppManagerActivity
//import com.zxhyis.toolss.ui.page.BatteryInfoActivity
//import com.zxhyis.toolss.ui.page.JunksActivity
//import com.zxhyis.toolss.ui.page.StorageInfoActivity
//import com.zxhyis.toolss.ui.page.VirusActivity
//
//
//@SuppressLint("SetTextI18n")
//class HomeFragment : TopFragment<FragmentHomeBinding>() {
//
//    override fun createBinding(
//        inflater: LayoutInflater,
//        container: ViewGroup?
//    ): FragmentHomeBinding {
//        return FragmentHomeBinding.inflate(inflater, container, false)
//    }
//
//    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
//        super.onViewCreated(view, savedInstanceState)
//        init()
//    }
//
//    private fun init() {
//
//        Glide.with(this)
//            .asGif()
//            .load(R.drawable.start)
//            .into(mK.ivStart)
//
//        Glide.with(this)
//            .asGif()
//            .load(R.drawable.end)
//            .into(mK.ivEnd)
//
//
//        mK.ivBg.setOnClick(javaClass.simpleName) {
//            requireActivity().startActivity<StorageInfoActivity>()
////            AdmobUtils.showInterstitialAd(requireActivity()){
////
////            }
//
//        }
//
//        mK.tvCleanSpace.setOnClick(javaClass.simpleName) {
//            mK.tvCleanSpace.setBackgroundResource(R.drawable.bg_shape_set_click)
//            requireActivity().startActivity<JunkCleanActivity>()
//            startActivity(Intent(requireActivity(), JunksActivity::class.java))
////            AdmobUtils.showInterstitialAd(requireActivity()){
////
////            }
//
//        }
//        mK.clBattery.setOnClick(javaClass.simpleName) {
//            mK.clBattery.setBackgroundResource(R.drawable.bg_shape_home_item1_click)
//            requireActivity().startActivity<BatteryInfoActivity>()
////            AdmobUtils.showInterstitialAd(requireActivity()){
////
////            }
//
//        }
//
//        mK.clBin.setOnClick(javaClass.simpleName) {
//            mK.clBin.setBackgroundResource(R.drawable.bg_shape_home_item1_click)
//            requireActivity().startActivity<AppManagerActivity>()
//        }
//
//        mK.clLargeFile.setOnClick(javaClass.simpleName) {
//
//            mK.clLargeFile.setBackgroundResource(R.drawable.bg_shape_home_item1_click)
//            AllFilesActivity.launch(requireActivity(), AllFilesActivity.large)
////            AdmobUtils.showInterstitialAd(requireActivity()){
////
////            }
//
//        }
//        mK.virusSacn.setOnClick(javaClass.simpleName) {
//            startActivity(Intent(requireActivity(), VirusActivity::class.java))
////            AdmobUtils.showInterstitialAd(requireActivity()){
////
////            }
//
//        }
//        AdmobUtils.showNativeAd(requireActivity(), mK.flAd)
//    }
//
//    override fun onResume() {
//        super.onResume()
//        requireActivity().window.statusBarColor =
//            ContextCompat.getColor(requireActivity(), R.color.tool_top)
//        setStatusBarTextLight(requireActivity())
//        initStorage()
//        updateUi()
//    }
//
//    private fun updateUi() {
//        mK.tvCleanSpace.setBackgroundResource(R.drawable.bg_shape_set)
//        mK.clBattery.setBackgroundResource(R.drawable.bg_shape_home_item1)
//        mK.clBin.setBackgroundResource(R.drawable.bg_shape_home_item1)
//        mK.clLargeFile.setBackgroundResource(R.drawable.bg_shape_home_item1)
//    }
//
//    private fun initStorage() {
//        val stat = StatFs(Environment.getExternalStorageDirectory().path)
//        val totalSize = f()
//        val availableSize = b()
//        val usedSize = totalSize - availableSize
//        val usedPercentage = usedSize.toFloat() / totalSize * 100
//        mK.pbTool.progress = usedPercentage.toInt()
//        mK.tvPercent.text = "${usedPercentage.toInt()}"
//        mK.tvStorage.text = "${usedSize.toFormatSize()}/ ${totalSize.toFormatSize()}"
//    }
//
//
//    fun b(): Long {
//        try {
//            val statFs = StatFs(Environment.getExternalStorageDirectory().path)
//            val statFs2 = StatFs(Environment.getRootDirectory().path)
//            val blackSize =
//                statFs2.blockSizeLong * statFs2.availableBlocksLong + statFs.blockSizeLong * statFs.availableBlocksLong
//            return a(blackSize)
//        } catch (e10: Exception) {
//           return 0L
//        }
//    }
//
//    var totalsize = 0L
//    fun f(): Long {
//        return if (totalsize > 0) {
//            totalsize
//        } else try {
//            val statFs = StatFs(Environment.getExternalStorageDirectory().path)
//            val statFs2 = StatFs(Environment.getRootDirectory().path)
//            val blockSizeLong =
//                statFs2.blockSizeLong * statFs2.blockCountLong + statFs.blockSizeLong * statFs.blockCountLong
//            totalsize = blockSizeLong
//            blockSizeLong
//        } catch (e10: java.lang.Exception) {
//            0L
//        }
//    }
//
//    fun a(j10: Long): Long {
//        var j10 = j10
//        var i7 = 0
//        while (true) {
//            val j11: Long = 1000
//            if (j10 < j11) {
//                break
//            }
//            j10 /= j11
//            i7++
//        }
//        for (i10 in 0 until i7) {
//            j10 *= 1024
//        }
//        return j10
//    }
//
//}
