package com.prank.tool.sounds.app.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.tool.sounds.app.adapter.AdaList;
import com.prank.tool.sounds.app.common.MyItemDecoration;
import com.prank.tool.sounds.app.common.MyUtils;
import com.prank.tool.sounds.app.data.detail;
import com.prank.tool.sounds.app.data.Sounds;
import com.prank.tool.sounds.app.data.OnSounds;
import com.prank.tool.sounds.app.databinding.ViewInfoBinding;

public class ViewInfo extends AppCompatActivity implements View.OnClickListener, OnSounds {

    private ViewInfoBinding activityListBinding;
    private Sounds data;
    private int colorIndex;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MyUtils.setStatusBarTextColor(this,true);
        activityListBinding = ViewInfoBinding.inflate(getLayoutInflater());
        setContentView(activityListBinding.getRoot());
        data = (Sounds) 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(5, 5, 0);
        activityListBinding.listRecycler.addItemDecoration(itemHelper);
        activityListBinding.listRecycler.setLayoutManager(new GridLayoutManager(this, 3));
        AdaList adaList = new AdaList(this, data.getDetailList(),0,this);
        activityListBinding.listRecycler.setAdapter(adaList);
        adaList.setColorIndex(colorIndex);
    }

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

    }

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