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.databinding.ListActivityBinding;
import com.fun.wave.pranksounds.listener.ClickSoundsListener;
import com.fun.wave.pranksounds.listener.PrankBean;
import com.fun.wave.pranksounds.listener.SoundsWrapper;
import com.fun.wave.pranksounds.main.ListAdapter;
import com.fun.wave.pranksounds.utils.Common;
import com.fun.wave.pranksounds.utils.ItemDec;

public class ListActivity extends BaseActivity<ListActivityBinding> implements View.OnClickListener, ClickSoundsListener {


    private SoundsWrapper data;
    private int colorIndex;



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

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

    private void onList() {
        ItemDec itemHelper = new ItemDec(5, 5, 0);
        viewBind.listRecycler.addItemDecoration(itemHelper);
        viewBind.listRecycler.setLayoutManager(new GridLayoutManager(this, 2));
        ListAdapter listAdapter = new ListAdapter(this, data.getPrankBeanList(),0,this);
        viewBind.listRecycler.setAdapter(listAdapter);
        listAdapter.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, PlayActivity.class);
        intent.putExtra(Common.KEY_PLAY_DATA, data);
        intent.putExtra(Common.KEY_LIST_COLOR_POS, colorIndex);
         startActivity(intent);
    }
}