package com.rich.keyboard.skin.uiactivity;

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

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

import com.rich.keyboard.skin.MyApp;
import com.rich.keyboard.skin.ad.AdManager;
import com.rich.keyboard.skin.ad.onActionListener;
import com.rich.keyboard.skin.databinding.ViewAllPageBinding;
import com.rich.keyboard.skin.listadapter.OtherList;
import com.rich.keyboard.skin.localdata.Child;
import com.rich.keyboard.skin.localdata.ParentData;
import com.rich.keyboard.skin.utils.ItemDec;
import com.rich.keyboard.skin.utils.MyCommon;

import java.util.List;

public class ViewAllUi extends AppCompatActivity {
    private ViewAllPageBinding vb;
    public static final String KEY_NAME = "class_name";
    private String name;
    private List<Child> data;

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

            }
        });
    }

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

}