package com.keyboard.skinning.cool.activity;

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

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

import com.keyboard.skinning.cool.App;
import com.keyboard.skinning.cool.ad.AdManager;
import com.keyboard.skinning.cool.ad.onActionListener;
import com.keyboard.skinning.cool.adpter.AdapterChild;
import com.keyboard.skinning.cool.data.ChildData;
import com.keyboard.skinning.cool.data.ClassData;
import com.keyboard.skinning.cool.databinding.ActivityAllBinding;
import com.keyboard.skinning.cool.tools.ItemDec;
import com.keyboard.skinning.cool.tools.Helper;

import java.util.List;

public class AllActivity extends AppCompatActivity {
    private ActivityAllBinding 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 = ActivityAllBinding.inflate(getLayoutInflater());
        Helper.INSTANCE.initFullScreen(this, false);
        setContentView(vb.getRoot());
        AdManager.loadAllAd();
        name = getIntent().getStringExtra(KEY_NAME);
        initData();
        initClick();
        AdManager.showTopOn(AllActivity.this, new onActionListener() {
            @Override
            public void onAction() {

            }
        });
    }

    private void initData() {
        vb.className.setText(name);
        for (ClassData classData : App.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(AllActivity.this, 3));
        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(AllActivity.this, new onActionListener() {
                    @Override
                    public void onAction() {
                        finish();
                    }
                });

            }
        });
    }

}