package com.prank.sounds.fart.activity;

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.sounds.fart.bean.Info;
import com.prank.sounds.fart.bean.MyBean;
import com.prank.sounds.fart.tools.MyItemDecoration;
import com.prank.sounds.fart.tools.MyUtils;
import com.prank.sounds.fart.databinding.InfoActBinding;
import com.prank.sounds.fart.myadapter.AdapterViewAll;
import com.prank.sounds.fart.callback.OnClickSounds;

public class InfoAct extends AppCompatActivity implements View.OnClickListener, OnClickSounds {

    private InfoActBinding activityListBinding;
    private MyBean data;
    private int colorIndex;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MyUtils.setStatusBarTextColor(this,true);
        activityListBinding = InfoActBinding.inflate(getLayoutInflater());
        setContentView(activityListBinding.getRoot());
        data = (MyBean) 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() {
        MyItemDecoration itemHelper = new MyItemDecoration(10, 10, 0);
        activityListBinding.listRecycler.addItemDecoration(itemHelper);
        activityListBinding.listRecycler.setLayoutManager(new GridLayoutManager(this, 3));
        AdapterViewAll adapterViewAll = new AdapterViewAll(this, data.getInfoList(),0,this);
        activityListBinding.listRecycler.setAdapter(adapterViewAll);
        adapterViewAll.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, PlaySoundsAct.class);
        intent.putExtra(MyUtils.KEY_PLAY_DATA, data);
        intent.putExtra(MyUtils.KEY_LIST_COLOR_POS, colorIndex);
         startActivity(intent);
    }
}