package com.apps.sketchmaster.view

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.GridLayoutManager
import com.ad.maxlibrary.MaxManager
import com.apps.sketchmaster.adapter.ThreeTypeAdapter
import com.apps.sketchmaster.event.DeleteClickListener
import com.apps.sketchmaster.utils.AllUtils
import com.apps.sketchmaster.databinding.ActivityShowTitleBinding

class ShowTitleActivity : AppCompatActivity(),DeleteClickListener {
    private lateinit var binding: ActivityShowTitleBinding
    companion object{
        var TITLE_KEY="name"
    }
    private var dirName=""
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding=ActivityShowTitleBinding.inflate(layoutInflater)
        setContentView(binding.root)
        dirName = intent.getStringExtra(TITLE_KEY)!!
        MaxManager.onLoadAd()
        init()
        MaxManager.startShowMaxAd (this@ShowTitleActivity){  }
    }
    private fun init(){
        val adapter=ThreeTypeAdapter()
        val allPic = AllUtils.loadEachPic(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() }

    }

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