package com.prank.tool.sounds.app.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;

import com.prank.tool.sounds.app.MyPrank;
import com.prank.tool.sounds.app.adapter.AdaMain;
import com.prank.tool.sounds.app.common.MyItemDecoration;
import com.prank.tool.sounds.app.data.Sounds;
import com.prank.tool.sounds.app.data.detail;
import com.prank.tool.sounds.app.databinding.FragmentMainBinding;

import java.util.ArrayList;
import java.util.List;


public class FragmentMain extends Fragment {


    private FragmentMainBinding binding;

    private List<detail> list;
    private boolean first = true;

    public FragmentMain() {
    }

    @SuppressWarnings("unused")
    public static FragmentMain newInstance() {
        FragmentMain fragment = new FragmentMain();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

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

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        binding = FragmentMainBinding.inflate(inflater);

        MyItemDecoration itemHelper = new MyItemDecoration(10, 10, 10);
        binding.recyclerView.addItemDecoration(itemHelper);
        binding.recyclerView.setLayoutManager(new GridLayoutManager(requireContext(), 2));
        binding.recyclerView.setAdapter(new AdaMain(requireContext(), MyPrank.bean));
        initAudioData();


        return binding.getRoot();
    }

    private void initAudioData() {
        list = new ArrayList<>();
        for (Sounds category : MyPrank.bean) {
            list.addAll(category.getDetailList());
        }
        initAudio();
    }

    private void initAudio() {

    }

}