package com.test.basd.smartjunkcleaner.fragment

import android.content.Intent
import com.test.basd.smartjunkcleaner.activity.AppManagerActivity
import com.test.basd.smartjunkcleaner.activity.BatteryInfoActivity
import com.test.basd.smartjunkcleaner.activity.LargeFileCleanActivity
import com.test.basd.smartjunkcleaner.activity.NetWorkActivity
import com.test.basd.smartjunkcleaner.activity.RecentAppActivity
import com.test.basd.smartjunkcleaner.activity.RepeaterdPhotoActivity
import com.test.basd.smartjunkcleaner.activity.ScanJunkActivity
import com.test.basd.smartjunkcleaner.activity.photocompress.photo.StartCompressionPhotoActivity
import com.test.basd.smartjunkcleaner.adapter.ToolsAdapter
import com.test.basd.smartjunkcleaner.databinding.FragmentLayoutToolsBinding
import com.test.basd.smartjunkcleaner.helps.BaseFragment
import com.test.basd.smartjunkcleaner.helps.ConfigHelper
import com.test.basd.smartjunkcleaner.helps.KotlinExt.toFormatSize
import com.test.basd.smartjunkcleaner.notificationclean.NotificationGuestActivity
import com.test.basd.smartjunkcleaner.view.AFunOb
import com.test.basd.smartjunkcleaner.view.AFunOb.APP_MANAGER
import com.test.basd.smartjunkcleaner.view.AFunOb.BATTERY_INFO
import com.test.basd.smartjunkcleaner.view.AFunOb.LARGE_FILE_CLEANER
import com.test.basd.smartjunkcleaner.view.AFunOb.NETWORK_TRAFFIC
import com.test.basd.smartjunkcleaner.view.AFunOb.NOTIFICATION_CLEANER
import com.test.basd.smartjunkcleaner.view.AFunOb.PHOTO_COMPRESS
import com.test.basd.smartjunkcleaner.view.AFunOb.RECENT_APP_USAGE
import com.test.basd.smartjunkcleaner.view.AFunOb.SIMILAR_PHOTOS

class ToolsFragment : BaseFragment<FragmentLayoutToolsBinding>() {
    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))
                }

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

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

                NOTIFICATION_CLEANER -> {
                    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(), RepeaterdPhotoActivity::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]
    }
}