package com.prank.sound.funnyapp.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.sound.funnyapp.bean.MyInfo;
import com.prank.sound.funnyapp.bean.MyBean;
import com.prank.sound.funnyapp.myinterface.OnClickItem;
import com.prank.sound.funnyapp.databinding.ActivityViewAllBinding;
import com.prank.sound.funnyapp.myadapter.AdapterViewAll;
import com.prank.sound.funnyapp.mytool.Decoration;
import com.prank.sound.funnyapp.mytool.Common;

public class ViewAllActivity extends AppCompatActivity implements View.OnClickListener, OnClickItem {

    private ActivityViewAllBinding activityListBinding;
    private MyBean data;
    private int colorIndex;

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

    private void onList() {
        Decoration itemHelper = new Decoration(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(MyInfo data) {
        Intent intent = new Intent(this, PlayItemActivity.class);
        intent.putExtra(Common.KEY_PLAY_DATA, data);
        intent.putExtra(Common.KEY_LIST_COLOR_POS, colorIndex);
         startActivity(intent);
    }
}