package com.xyzshell.myphoneinfo.dashboard

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.xyzshell.myphoneinfo.R
import com.xyzshell.myphoneinfo.adapter.AppListAdapter
import com.xyzshell.myphoneinfo.databinding.FragmentAppsBinding
import com.xyzshell.myphoneinfo.dialog.AppDialogFragment

class AppsFragment : Fragment(),AppListAdapter.OnShowDialogListener {
    private lateinit var binding: FragmentAppsBinding
    private lateinit var dialogFragment: AppDialogFragment
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        binding = FragmentAppsBinding.inflate(inflater, container, false)
        val adapter= AppListAdapter()
        adapter.setOnclickListener(this)
        binding.recyclerView.adapter = adapter
        binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
        return binding.root
    }

    companion object {
        @JvmStatic
        fun newInstance() =
            AppsFragment().apply {
                arguments = Bundle().apply {

                }
            }
    }

    override fun onShowAppSelectDialog() {
         dialogFragment = AppDialogFragment()
         dialogFragment.show(requireActivity().supportFragmentManager, "AppDialogFragment")
    }
}