package com.prank.tool.act;

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

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

import com.prank.tool.adapter.AdapterChild;
import com.prank.tool.databinding.ActivityLayoutInfoBinding;
import com.prank.tool.interf.OnSoundsListener;
import com.prank.tool.jbean.Info;
import com.prank.tool.jbean.MyBean;
import com.prank.tool.utils.Space;
import com.prank.tool.utils.Tools;

public class ActivityInfo extends AppCompatActivity implements View.OnClickListener, OnSoundsListener {

    private ActivityLayoutInfoBinding activityListBinding;
    private MyBean data;
    private int colorIndex;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Tools.setStatusBarTextColor(this,true);
        activityListBinding = ActivityLayoutInfoBinding.inflate(getLayoutInflater());
        setContentView(activityListBinding.getRoot());
        data = (MyBean) getIntent().getSerializableExtra(Tools.KEY_LIST_DATA);
        colorIndex =  getIntent().getIntExtra(Tools.KEY_LIST_COLOR_POS,0);
        activityListBinding.categoryName.setText(data.getName());
        onList();
        activityListBinding.back.setOnClickListener(this);
    }

    private void onList() {
        Space itemHelper = new Space(10, 10, 0);
        activityListBinding.listRecycler.addItemDecoration(itemHelper);
        activityListBinding.listRecycler.setLayoutManager(new GridLayoutManager(this, 3));
        AdapterChild adapterChild = new AdapterChild(this, data.getInfoList(),0,this);
        activityListBinding.listRecycler.setAdapter(adapterChild);
        adapterChild.setColorIndex(colorIndex);
    }

    @Override
    public void onClick(View v) {
        if(v.equals(activityListBinding.back)){
            finish();
        }

    }

    @Override
    public void onClickSoundsListener(Info data) {
        Intent intent = new Intent(this, ActivityPlay.class);
        intent.putExtra(Tools.KEY_PLAY_DATA, data);
        intent.putExtra(Tools.KEY_LIST_COLOR_POS, colorIndex);
         startActivity(intent);
    }
}