package com.sound.prankparty.Activity;

import android.os.Bundle;

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

import com.sound.prankparty.Adapter.Main2RecyclerViewAdapter;
import com.sound.prankparty.JSON.Category;
import com.sound.prankparty.Utils.JsonParser;
import com.sound.prankparty.Utils.LoadJSON;
import com.sound.prankparty.databinding.ActivityMain2Binding;

import java.util.List;

public class MainActivity2 extends AppCompatActivity {

    private ActivityMain2Binding binding;

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

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

        // 从 assets 文件夹中读取 JSON 文件
        String jsonString = LoadJSON.loadJSONFromAsset("prank.json");
        // 解析读取的 String
        List<Category> categories = JsonParser.parseJson(jsonString);

        binding.mainRecycler.setLayoutManager(new GridLayoutManager(this, 1));
        binding.mainRecycler.setAdapter(new Main2RecyclerViewAdapter(this, categories));

    }
}