package com.zxhy.simplefilesmanager.simplemanager

import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.zxhy.simplefilesmanager.R
import com.zxhy.simplefilesmanager.databinding.FragmentSimpleManagerBinding
import com.zxhy.simplefilesmanager.internalstorage.InternalStorageActivity
import com.zxhy.simplefilesmanager.simpledup.SimpleDupActivity
import com.zxhy.simplefilesmanager.simplejoke.DiskHelper
import com.zxhy.simplefilesmanager.simplelist.SimpleListActivity

class SimpleManagerFragment() : Fragment() {

    private lateinit var binding: FragmentSimpleManagerBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val root = inflater.inflate(R.layout.fragment_simple_manager, container, false)
        binding = FragmentSimpleManagerBinding.bind(root)
        return root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        binding.llDupPicture.setOnClickListener {
            startActivity(Intent(requireContext(), SimpleDupActivity::class.java))
        }
        binding.llLarge.setOnClickListener {
            startActivity(Intent(requireContext(), SimpleListActivity::class.java).apply {
                putExtra("Tittle", "LARGE FILE")
            })
        }
        binding.tvManager.setOnClickListener {
            startActivity(Intent(requireContext(), InternalStorageActivity::class.java))
        }
        val disk = DiskHelper.getMountInfoList(requireContext())[0]
        binding.tvFree.text = disk.getFreeContent(requireContext())
        binding.tvUsed.text = disk.getUsedContent(requireContext())

        val percentF = (disk.used.toFloat() / disk.total.toFloat()) * 100f
        val percent = String.format("%.0f", percentF)
        binding.tvStore.text = "$percent%"
    }

    companion object {
        const val DEEPLINK_SIMPLE_MANAGER_URI = "https://www.zxhy.com/simplemanager/"
    }
}