package com.app.input.color.board.uiactivity;

import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;

import com.ad.tradpluslibrary.TPAdManager;
import com.app.input.color.board.App;
import com.app.input.color.board.bean.BeanDetails;
import com.app.input.color.board.bean.BeanWrapper;
import com.app.input.color.board.databinding.ActivityCategoryListBinding;
import com.app.input.color.board.listutils.HomeChildAdapter;
import com.app.input.color.board.utils.Common;
import com.app.input.color.board.utils.ListDecoration;

import java.util.List;

import kotlin.Unit;
import kotlin.jvm.functions.Function0;

public class CategoryListActivity extends AppCompatActivity {
    private ActivityCategoryListBinding vb;
    public static final String KEY_NAME = "class_name";
    private String name;
    private List<BeanDetails> data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        vb = ActivityCategoryListBinding.inflate(getLayoutInflater());
        Common.INSTANCE.initFullScreen(this, false);
        setContentView(vb.getRoot());
        name = getIntent().getStringExtra(KEY_NAME);
        initData();
        initClick();
        TPAdManager.INSTANCE.showTPAD(CategoryListActivity.this, new Function0<Unit>() {
            @Override
            public Unit invoke() {
                return null;
            }
        });
    }

    private void initData() {
        vb.className.setText(name);
        for (BeanWrapper beanWrapper : App.list) {
            if (beanWrapper.getParentName().equals(name)) {
                data = beanWrapper.getKeyboardList();
            }
        }
        ListDecoration listDecoration = new ListDecoration(3, 3, 0);
        HomeChildAdapter adapterMain = new HomeChildAdapter(this, data);
        vb.recycler.setLayoutManager(new GridLayoutManager(CategoryListActivity.this, 3));
        vb.recycler.setAdapter(adapterMain);
        vb.recycler.addItemDecoration(listDecoration);

    }

    private void initClick() {
        vb.back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TPAdManager.INSTANCE.showTPAD(CategoryListActivity.this, new Function0<Unit>() {
                    @Override
                    public Unit invoke() {
                        finish();
                        return null;
                    }
                });

            }
        });
    }

}