package com.prank.app.color.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.app.color.dbdata.MyData;
import com.prank.app.color.dbdata.MyInfo;
import com.prank.app.color.databinding.ActivityListBinding;
import com.prank.app.color.list.AdapterList;
import com.prank.app.color.api.OnClickListener;
import com.prank.app.color.utils.Common;
import com.prank.app.color.utils.ItemDecoration;

public class ActivityList extends AppCompatActivity implements View.OnClickListener, OnClickListener {

    private ActivityListBinding activityListBinding;
    private MyData data;
    private int colorIndex;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Common.setStatusBarTextColor(this,true);
        activityListBinding = ActivityListBinding.inflate(getLayoutInflater());
        setContentView(activityListBinding.getRoot());
        data = (MyData) 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() {
        ItemDecoration itemHelper = new ItemDecoration(10, 10, 0);
        activityListBinding.listRecycler.addItemDecoration(itemHelper);
        activityListBinding.listRecycler.setLayoutManager(new GridLayoutManager(this, 2));
        AdapterList adapterList = new AdapterList(this, data.getInfoList(),0,this);
        activityListBinding.listRecycler.setAdapter(adapterList);
        adapterList.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, ActivityPlay.class);
        intent.putExtra(Common.KEY_PLAY_DATA, data);
        intent.putExtra(Common.KEY_LIST_COLOR_POS, colorIndex);
         startActivity(intent);
    }
}