package com.soundapp.soundgags.ui

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.GridLayoutManager
import com.ad.tradpluslibrary.TPAdManager.showTPAD
import com.soundapp.soundgags.setting.TypeAdapter
import com.soundapp.soundgags.datame.Familiar
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.soundapp.soundgags.databinding.ActivityOpenSetBinding
import com.soundapp.soundgags.setting.TopBarUtils

class OpenSetActivity : AppCompatActivity() {
    private lateinit var binding: ActivityOpenSetBinding
    private lateinit var data: Familiar

    companion object {
        const val KEY_LIST_DATA = "list_data"
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityOpenSetBinding.inflate(layoutInflater)
        setContentView(binding.root)
        TopBarUtils.setStatusBar(this.window)
        TopBarUtils.setLightStatusBar(this.window, true)
        data = intent.getParcelableExtra(KEY_LIST_DATA)!!
        initView()
    }

    private fun initView() {
        Glide.with(this)
            .load(data.convert)
            .apply(RequestOptions.circleCropTransform())
            .into(binding.image)
        binding.title.text = data.name
        val adapter = TypeAdapter()
        binding.recyclerView.adapter = adapter
        binding.recyclerView.layoutManager = GridLayoutManager(this, 3)
        adapter.setList(data.infolist)
        binding.back.setOnClickListener { showTPAD(this){finish()} }
    }
}