package com.light.prank.sound.app.allui;

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

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

import com.light.prank.sound.app.dataListener.SoundsWrapper;
import com.light.prank.sound.app.utils.MyItemSpace;
import com.light.prank.sound.app.utils.MyUtils;
import com.light.prank.sound.app.dataListener.OnClickItemListener;
import com.light.prank.sound.app.dataListener.PrankBean;
import com.prank.tool.sounds.app.databinding.AcCategoryListBinding;

public class AcCategoryList extends AppCompatActivity implements View.OnClickListener, OnClickItemListener {

    private AcCategoryListBinding activityListBinding;
    private SoundsWrapper data;
    private int colorIndex;

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

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

    @Override
    public void onClick(View v) {
        if(v.equals(activityListBinding.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);
    }
}