package com.test.basd.onecleanmaster.fragment

import android.content.Intent
import com.blankj.utilcode.util.SPUtils
import com.test.basd.onecleanmaster.activity.AppManagerActivity
import com.test.basd.onecleanmaster.activity.BatteryInfoActivity
import com.test.basd.onecleanmaster.activity.LargeFileCleanActivity
import com.test.basd.onecleanmaster.activity.NetWorkActivity
import com.test.basd.onecleanmaster.activity.RecentAppActivity
import com.test.basd.onecleanmaster.activity.RepeatedPhotoActivity
import com.test.basd.onecleanmaster.activity.ScanJunkActivity
import com.test.basd.onecleanmaster.activity.SpeakerCleanerActivity
//import com.test.basd.quickclean.activity.VirusActivity
import com.test.basd.onecleanmaster.activity.photocompress.photo.StartCompressionPhotoActivity
import com.test.basd.onecleanmaster.adapter.ToolsAdapter
import com.test.basd.onecleanmaster.databinding.FragmentLayoutToolsBinding
import com.test.basd.onecleanmaster.helps.BaseFragment
import com.test.basd.onecleanmaster.helps.ConfigHelper
import com.test.basd.onecleanmaster.helps.KotlinExt.toFormatSize
import com.test.basd.onecleanmaster.notificationclean.NotificationCleanActivity
import com.test.basd.onecleanmaster.notificationclean.NotificationGuestActivity
import com.test.basd.onecleanmaster.view.AFunOb
import com.test.basd.onecleanmaster.view.AFunOb.APP_MANAGER
import com.test.basd.onecleanmaster.view.AFunOb.BATTERY_INFO
import com.test.basd.onecleanmaster.view.AFunOb.VIRUS_SCAN
import com.test.basd.onecleanmaster.view.AFunOb.LARGE_FILE_CLEANER
import com.test.basd.onecleanmaster.view.AFunOb.NETWORK_TRAFFIC
import com.test.basd.onecleanmaster.view.AFunOb.NOTIFICATION_CLEANER
import com.test.basd.onecleanmaster.view.AFunOb.PHOTO_COMPRESS
import com.test.basd.onecleanmaster.view.AFunOb.RECENT_APP_USAGE
import com.test.basd.onecleanmaster.view.AFunOb.SIMILAR_PHOTOS
import com.test.basd.onecleanmaster.view.AFunOb.SPEAK_CLEANER

class ToolsFragment : BaseFragment<FragmentLayoutToolsBinding>() {
    private val TAG = "ToolsFragment"
    private lateinit var adapter: ToolsAdapter

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

    override fun setView() {
        adapter = ToolsAdapter(requireActivity()) { kName ->
            when (kName) {
                AFunOb.JUNK_CLEANER -> {
                    startActivity(Intent(requireContext(), ScanJunkActivity::class.java))
                }

                VIRUS_SCAN -> {
//                    startActivity(Intent(requireActivity(), VirusActivity::class.java))
                }

                RECENT_APP_USAGE -> {
                    startActivity(Intent(requireActivity(), RecentAppActivity::class.java))
                }

                LARGE_FILE_CLEANER -> {
                    startActivity(Intent(requireContext(), LargeFileCleanActivity::class.java))
                }

                NOTIFICATION_CLEANER -> {
                    if (SPUtils.getInstance().getBoolean("notification_guest", false)) {
                        startActivity(Intent(requireActivity(), NotificationCleanActivity::class.java))
                    } else {
                        startActivity(Intent(requireActivity(), NotificationGuestActivity::class.java))
                    }
                }

                NETWORK_TRAFFIC -> {
                    startActivity(Intent(requireContext(), NetWorkActivity::class.java))
                }

                APP_MANAGER -> {
                    startActivity(Intent(requireContext(), AppManagerActivity::class.java))
                }

                SIMILAR_PHOTOS -> {
                    startActivity(Intent(requireContext(), RepeatedPhotoActivity::class.java))
                }

                SPEAK_CLEANER -> {
                    startActivity(Intent(requireContext(), SpeakerCleanerActivity::class.java))
                }

                PHOTO_COMPRESS -> {
                    startActivity(Intent(requireActivity(), StartCompressionPhotoActivity::class.java))
                }

                BATTERY_INFO -> {
                    startActivity(Intent(requireActivity(), BatteryInfoActivity::class.java))
                }

            }
        }
        binding.rvTools.adapter = adapter
    }

    override fun onResume() {
        super.onResume()
        val split = ConfigHelper.junkSizeClean.toFormatSize(1).split(' ')
        binding.tvSize.text = split[0]
        binding.tvSizeUnit.text = split[1]
    }
}