package com.blue.running.keyboard.run_activity;

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

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

import com.blue.running.keyboard.RunningApp;
import com.blue.running.keyboard.databinding.ActListBinding;
import com.blue.running.keyboard.run_adapter.AdapterMainChild;
import com.blue.running.keyboard.run_jsonbean.ChildData;
import com.blue.running.keyboard.run_jsonbean.ClassData;
import com.blue.running.keyboard.run_manager.ComUttils;
import com.blue.running.keyboard.run_manager.ListSpace;

import java.util.List;

public class ActivityList extends AppCompatActivity {
    private ActListBinding 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 = ActListBinding.inflate(getLayoutInflater());
        ComUttils.INSTANCE.initFullScreen(this, true);
        setContentView(vb.getRoot());

        name = getIntent().getStringExtra(KEY_NAME);
        initData();
        initClick();
    }

    private void initData(){
        vb.className.setText(name);
        for (ClassData classData : RunningApp.list) {
            if(classData.getParentName().equals(name)){
                data = classData.getKeyboardList();
            }
        }
        ListSpace listSpace = new ListSpace(3, 3, 0);
        AdapterMainChild adapterMain = new AdapterMainChild(this,data,false);
        vb.recycler.setLayoutManager(new GridLayoutManager(ActivityList.this,2));
        vb.recycler.setAdapter(adapterMain);
        vb.recycler.addItemDecoration(listSpace);

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

}