package com.base.filerecoveryrecyclebin.fragment

import android.animation.ValueAnimator
import android.annotation.SuppressLint
import android.content.Intent
import android.view.View
import com.base.filerecoveryrecyclebin.activity.MainActivity
import com.base.filerecoveryrecyclebin.activity.SettingActivity
import com.base.filerecoveryrecyclebin.activity.junkclean.ScanJunkActivity
import com.base.filerecoveryrecyclebin.activity.photomanager.PhotoManagerActivity
import com.base.filerecoveryrecyclebin.activity.photomanager.PhotoManagerAnimationActivity
import com.base.filerecoveryrecyclebin.activity.recovery.FileScanResultActivity
import com.base.filerecoveryrecyclebin.activity.vip.VipActivity
import com.base.filerecoveryrecyclebin.activity.whatsapp.WhatsAppCleanerAnimationActivity
import com.base.filerecoveryrecyclebin.bean.ConstObject.SCAN_AUDIOS
import com.base.filerecoveryrecyclebin.bean.ConstObject.SCAN_DOCUMENTS
import com.base.filerecoveryrecyclebin.bean.ConstObject.SCAN_PHOTOS
import com.base.filerecoveryrecyclebin.bean.ConstObject.SCAN_VIDEOS
import com.base.filerecoveryrecyclebin.databinding.FragmentHome3Binding
import com.base.filerecoveryrecyclebin.help.BaseFragment
import com.base.filerecoveryrecyclebin.help.KotlinExt.toFormatSize
import com.base.filerecoveryrecyclebin.utils.LogEx

class HomeFragment : BaseFragment<FragmentHome3Binding>() {
    private val TAG = "HomeFragment"

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

    @SuppressLint("SetTextI18n")
    override fun setView() {
        binding.tvTitle.text = "Dumpster"
        binding.lottie.repeatCount = ValueAnimator.INFINITE
    }

    override fun setListener() {
        binding.flScan.setOnClickListener {
            startActivity(Intent(requireContext(), ScanJunkActivity::class.java))
//            sendNotification(requireContext(), ConstObject.ID_SCREENSHOT_CLEAN)
        }
        binding.cardRyPhotos.setOnClickListener {
            startActivity(Intent(requireContext(), FileScanResultActivity::class.java).apply {
                putExtra("ScanType", SCAN_PHOTOS)
            })
        }
        binding.cardRyVideos.setOnClickListener {
            startActivity(Intent(requireContext(), FileScanResultActivity::class.java).apply {
                putExtra("ScanType", SCAN_VIDEOS)
            })
        }
        binding.cardRyDocuments.setOnClickListener {
            startActivity(Intent(requireContext(), FileScanResultActivity::class.java).apply {
                putExtra("ScanType", SCAN_DOCUMENTS)
            })
        }
        binding.cardRyAudios.setOnClickListener {
            startActivity(Intent(requireContext(), FileScanResultActivity::class.java).apply {
                putExtra("ScanType", SCAN_AUDIOS)
            })
        }
        binding.cardPhotoManager.setOnClickListener {
            startActivity(Intent(requireContext(), PhotoManagerAnimationActivity::class.java))
        }

        binding.cardWhatsapp.setOnClickListener {
            startActivity(Intent(requireContext(), WhatsAppCleanerAnimationActivity::class.java))
        }
        binding.flSetting.setOnClickListener {
            startActivity(Intent(requireContext(), SettingActivity::class.java))
        }
        binding.ivVip.setOnClickListener {
            startActivity(Intent(requireContext(), VipActivity::class.java))
        }
        (requireActivity() as MainActivity).photoSizeAction = {
            if (it == 0L) {
                binding.tvPhotoSize.visibility = View.INVISIBLE
                binding.tvPhotoSize.text = it.toFormatSize(0)
            } else {
                binding.tvPhotoSize.visibility = View.INVISIBLE
            }
        }
    }


    override fun onPause() {
        super.onPause()
        binding.lottie.pauseAnimation()

    }

    override fun onResume() {
        super.onResume()
        binding.lottie.resumeAnimation()
    }

}