package com.zxhy.hfilemanagermaster.files

import android.Manifest
import android.os.Bundle
import android.view.Display
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import com.example.hfilemanagermaster.R
import com.example.hfilemanagermaster.databinding.FragmentFilesBinding
import com.zxhy.hfilemanagermaster.OverviewActivity
import com.zxhy.hfilemanagermaster.knife.getRecentPhoto
import com.zxhy.hfilemanagermaster.knife.testPhoto
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.security.Permission
import java.security.Permissions

/**
 * A simple [Fragment] subclass.
 * Use the [FilesFragment.newInstance] factory method to
 * create an instance of this fragment.
 */
class FilesFragment : Fragment() {
    private lateinit var binding: FragmentFilesBinding
    private lateinit var imageAdapter: ImageAdapter

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
        }
        (activity as OverviewActivity).setStatusBarColor(R.color.white)
    }

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

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        imageAdapter = ImageAdapter()
        binding.ivImage.setOnClickListener {
            findNavController().navigate(R.id.imageActivity)

        }
        binding.ivVideo.setOnClickListener {
            findNavController().navigate(R.id.videoActivity)
        }
        lifecycleScope.launch(Dispatchers.IO) {
            val list = requireContext().testPhoto()
            launch(Dispatchers.Main) {
                binding.rv.adapter = imageAdapter
                imageAdapter.setData(list)
            }
        }
    }

    companion object {
        @JvmStatic
        fun newInstance(param1: String, param2: String) =
            FilesFragment().apply {
                arguments = Bundle().apply {
                }
            }
    }
}