package com.sound.prankparty.Activity;

import android.graphics.Color;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;

import com.sound.prankparty.Adapter.AirHornRecyclerViewAdapter;
import com.sound.prankparty.JSON.Category;
import com.sound.prankparty.JSON.SoundItem;
import com.sound.prankparty.Utils.ItemDecoration;
import com.sound.prankparty.databinding.ActivityAirhonrBinding;

import java.util.List;

public class AirHornActivity extends AppCompatActivity {

    private ActivityAirhonrBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = ActivityAirhonrBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        binding.airHornRecyclerview.setLayoutManager(new GridLayoutManager(this, 3));

        // 接收传递的 List<Category> 对象
        Category categories = (Category) getIntent().getSerializableExtra("123");
        // 获取颜色值
        int receivedColor = getIntent().getIntExtra("color", Color.TRANSPARENT); // 默认值为透明色

        if (categories == null) {
            // 处理 categories 为 null 的情况
            return;
        }
        List<SoundItem> soundItemList = categories.getSoundItemList();
        String categoryName = categories.getCategoryName();

        binding.airHornRecyclerview.setAdapter(new AirHornRecyclerViewAdapter(this, soundItemList,receivedColor));

        binding.airHornTitle.setText(categoryName);
        binding.airHornBack.setOnClickListener(v -> finish());

        // 为 RecyclerView 添加自定义的间距装饰。
        ItemDecoration itemDecoration = new ItemDecoration(16, 19, 10);
        binding.airHornRecyclerview.addItemDecoration(itemDecoration);
    }
}
