package com.apps.quicksketchtrace.activity

import android.content.Intent
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.GridLayoutManager
import com.apps.quicksketchtrace.R
import com.apps.quicksketchtrace.ad.TPManager
import com.apps.quicksketchtrace.adapter.ThreeLineAdapter
import com.apps.quicksketchtrace.databinding.ActivityEachCategoryBinding
import com.apps.quicksketchtrace.listener.MainClickListener
import com.apps.quicksketchtrace.util.OpenConvert

class EachCategoryActivity : AppCompatActivity(),MainClickListener {
    private lateinit var binding:ActivityEachCategoryBinding
    companion object{
        var TITLE_KEY="name"
    }
    private var dirName=""
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding=ActivityEachCategoryBinding.inflate(layoutInflater)
        setContentView(binding.root)
        dirName = intent.getStringExtra(TITLE_KEY)!!
        init()
    }
    private fun init(){
        val adapter=ThreeLineAdapter()
        val allPic = OpenConvert.getAllPic(this, dirName)
        adapter.setCategoryList(list = allPic, type = 0)
        adapter.setListener(this)
        val gridLayoutManager = GridLayoutManager(this, 3)
        binding.recyclerView.adapter=adapter
        binding.recyclerView.layoutManager=gridLayoutManager
        binding.imgBack.setOnClickListener { finish() }
        TPManager.showTPAD(this@EachCategoryActivity) {  }

    }

    override fun onClick(name: String) {
        val tag = "ImageDialog"
        if (supportFragmentManager.findFragmentByTag(tag) == null) {
            val dialog = ImageDialogFragment.newInstance(name)
            dialog.show(supportFragmentManager, tag)
        }
    }
}