package com.keyboard.bubble.skin.keyboard.fagment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.keyboard.bubble.skin.keyboard.App
import com.keyboard.bubble.skin.keyboard.R
import com.keyboard.bubble.skin.keyboard.myada.AdapterMain


class MainPage : Fragment() {

    private var paramIndex: Int = 0
    private lateinit var contentRecy: RecyclerView
    val  ARG_PARAM1 = "KEY"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            paramIndex = it.getInt(ARG_PARAM1)
        }
    }
    companion object {

        @JvmStatic
        fun newInstance(index: Int) =
            MainPage().apply {
                arguments = Bundle().apply {
                    putInt(ARG_PARAM1, index)
                }
            }
    }
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val viewMain = inflater.inflate(R.layout.layout_main_fragment, container, false)
        contentRecy = viewMain.findViewById(R.id.content_recycler)
        initContent()
        return viewMain
    }

    private fun initContent(){
        val mainBean = App.list[paramIndex]
        contentRecy.run {
            this.adapter = AdapterMain(
                requireContext()
            ).apply {
                val shufflList = mainBean.keyboardList.shuffled()
                setForYouList(shufflList)
            }
            this.layoutManager = GridLayoutManager(requireContext(), 2)
        }
    }


}