package com.test.basd.fastcleanerjunk.fragment

import android.content.Intent
import com.test.basd.fastcleanerjunk.activity.AppManagerActivity
import com.test.basd.fastcleanerjunk.activity.BatteryInfoActivity
import com.test.basd.fastcleanerjunk.activity.LargeFileCleanActivity
import com.test.basd.fastcleanerjunk.activity.NetWorkActivity
import com.test.basd.fastcleanerjunk.activity.RecentAppActivity
import com.test.basd.fastcleanerjunk.activity.PreparedPhotoActivity
import com.test.basd.fastcleanerjunk.activity.ScanJunkActivity
import com.test.basd.fastcleanerjunk.activity.ScreenShotActivity
import com.test.basd.fastcleanerjunk.activity.photocompress.photo.StartCompressionPhotoActivity
import com.test.basd.fastcleanerjunk.adapter.ToolsAdapter
import com.test.basd.fastcleanerjunk.databinding.FragmentLayoutToolsBinding
import com.test.basd.fastcleanerjunk.helps.BaseFragment
import com.test.basd.fastcleanerjunk.helps.ConfigHelper
import com.test.basd.fastcleanerjunk.helps.KotlinExt.toFormatSize
import com.test.basd.fastcleanerjunk.notificationclean.NotificationGuestActivity
import com.test.basd.fastcleanerjunk.view.AFunOb
import com.test.basd.fastcleanerjunk.view.AFunOb.APP_MANAGER
import com.test.basd.fastcleanerjunk.view.AFunOb.BATTERY_INFO
import com.test.basd.fastcleanerjunk.view.AFunOb.LARGE_FILE_CLEANER
import com.test.basd.fastcleanerjunk.view.AFunOb.NETWORK_TRAFFIC
import com.test.basd.fastcleanerjunk.view.AFunOb.NOTIFICATION_CLEANER
import com.test.basd.fastcleanerjunk.view.AFunOb.PHOTO_COMPRESS
import com.test.basd.fastcleanerjunk.view.AFunOb.RECENT_APP_USAGE
import com.test.basd.fastcleanerjunk.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(), PreparedPhotoActivity::class.java))
                }


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

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

                AFunOb.SCREENSHOT_CLEANER -> {
                    startActivity(Intent(requireActivity(), ScreenShotActivity::class.java))
                }

            }
        }
        binding.rvTools.adapter = adapter

    }

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