package com.shiny.keyboard.ui;

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

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

import com.shiny.keyboard.MyApplication;
import com.shiny.keyboard.ad.AdManager;
import com.shiny.keyboard.ad.onActionListener;
import com.shiny.keyboard.bean.ChildData;
import com.shiny.keyboard.bean.ClassData;
import com.shiny.keyboard.databinding.ActAllBinding;
import com.shiny.keyboard.helper.ItemDec;
import com.shiny.keyboard.helper.Utils;
import com.shiny.keyboard.recycler.AdapterChild;

import java.util.List;

public class SeeAllActivity extends AppCompatActivity {
    private ActAllBinding vb;
    public static final String KEY_NAME = "class_name";
    private String name;
    private List<ChildData> data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        vb = ActAllBinding.inflate(getLayoutInflater());
        Utils.INSTANCE.initFullScreen(this, false);
        setContentView(vb.getRoot());
        AdManager.loadAllAd();
        name = getIntent().getStringExtra(KEY_NAME);
        initData();
        initClick();
        AdManager.showTopOn(SeeAllActivity.this, new onActionListener() {
            @Override
            public void onAction() {

            }
        });
    }

    private void initData() {
        vb.className.setText(name);
        for (ClassData classData : MyApplication.list) {
            if (classData.getParentName().equals(name)) {
                data = classData.getKeyboardList();
            }
        }
        ItemDec itemDec = new ItemDec(3, 3, 0);
        AdapterChild adapterMain = new AdapterChild(this, data);
        vb.recycler.setLayoutManager(new GridLayoutManager(SeeAllActivity.this, 2));
        vb.recycler.setAdapter(adapterMain);
        vb.recycler.addItemDecoration(itemDec);

    }

    private void initClick() {
        vb.back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                AdManager.showTopOn(SeeAllActivity.this, new onActionListener() {
                    @Override
                    public void onAction() {
                        finish();
                    }
                });

            }
        });
    }

}