package com.key.board.journey.inputmethod.activity;

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

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

import com.ad.toponlibrary.AdManager;
import com.ad.toponlibrary.onActionListener;
import com.key.board.journey.inputmethod.MyKeyboard;
import com.key.board.journey.inputmethod.list.ItemMore;
import com.key.board.journey.inputmethod.data.ChildBean;
import com.key.board.journey.inputmethod.data.ClassBean;
import com.key.board.journey.inputmethod.databinding.ActivityListAllBinding;
import com.key.board.journey.inputmethod.tools.Common;
import com.key.board.journey.inputmethod.tools.ItemDec;

import java.util.List;

public class ListActivity extends AppCompatActivity {
    private ActivityListAllBinding vb;
    public static final String KEY_NAME ="class_name";
    private String name;
    private List<ChildBean> data;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        vb =  ActivityListAllBinding.inflate(getLayoutInflater());
        Common.INSTANCE.initFullScreen(this, true);
        setContentView(vb.getRoot());
        AdManager.loadAllAd();
        name = getIntent().getStringExtra(KEY_NAME);
        initData();
        initClick();
        AdManager.showTopOn(this, new onActionListener() {
            @Override
            public void onAction() {

            }
        });
    }

    private void initData(){
        vb.className.setText(name);
        for (ClassBean classBean : MyKeyboard.list) {
            if(classBean.getParentName().equals(name)){
                data = classBean.getKeyboardList();
            }
        }
        ItemDec itemDec = new ItemDec(3, 3, 0);
        ItemMore adapterMain = new ItemMore(this);
        adapterMain.setForYouList(data);
        vb.recycler.setLayoutManager(new GridLayoutManager(ListActivity.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(ListActivity.this, new onActionListener() {
                  @Override
                  public void onAction() {
                      finish();
                  }
              });
            }
        });
    }

}