package com.fun.wave.pranksounds.activity;

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

import androidx.recyclerview.widget.GridLayoutManager;

import com.fun.wave.pranksounds.base.BaseActivity;
import com.fun.wave.pranksounds.dataListener.SoundsWrapper;
import com.fun.wave.pranksounds.utils.MyItemSpace;
import com.fun.wave.pranksounds.utils.MyUtils;
import com.fun.wave.pranksounds.dataListener.OnClickItemListener;
import com.fun.wave.pranksounds.dataListener.PrankBean;
import com.fun.pranksounds.databinding.AcCategoryListBinding;

public class AcCategoryList extends BaseActivity<AcCategoryListBinding> implements View.OnClickListener, OnClickItemListener {


    private SoundsWrapper data;
    private int colorIndex;



    @Override
    protected void init() {
        data = (SoundsWrapper) getIntent().getSerializableExtra(MyUtils.KEY_LIST_DATA);
        colorIndex =  getIntent().getIntExtra(MyUtils.KEY_LIST_COLOR_POS,0);
        viewBind.categoryName.setText(data.getName());
        onList();
        viewBind.back.setOnClickListener(this);
    }

    @Override
    protected AcCategoryListBinding initViewBinding() {
        return AcCategoryListBinding.inflate(getLayoutInflater());
    }

    private void onList() {
        MyItemSpace itemHelper = new MyItemSpace(5, 5, 0);
        viewBind.listRecycler.addItemDecoration(itemHelper);
        viewBind.listRecycler.setLayoutManager(new GridLayoutManager(this, 2));
        AdapterCategoryList adapterCategoryList = new AdapterCategoryList(this, data.getPrankBeanList(),0,this);
        viewBind.listRecycler.setAdapter(adapterCategoryList);
        adapterCategoryList.setColorIndex(colorIndex);
    }

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

    }

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