package com.app.paintingstool.myfrg;

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;

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

import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.app.paintingstool.R;
import com.app.paintingstool.databinding.FragmentPaintBinding;
import com.app.paintingstool.myact.PaintingActivity;
import com.app.paintingstool.myadapter.ImageAdapter;
import com.app.paintingstool.myuntils.Keys;
import com.app.paintingstool.myuntils.MyItemDecoration;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class PaintFragment extends Fragment {
    private FragmentPaintBinding binding;
    private static final String ARG_PARAM1 = "param1";
    private int position;
    private String dir;


    public PaintFragment() {
        // Required empty public constructor
    }
    public static PaintFragment newInstance(int position) {
        PaintFragment fragment = new PaintFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_PARAM1, position);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            position = getArguments().getInt(ARG_PARAM1);
        }
    }
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        binding = FragmentPaintBinding.inflate(getLayoutInflater());
        binding.recyclerView.setLayoutManager(new GridLayoutManager(requireContext(),
                2));
        binding.recyclerView.addItemDecoration(new MyItemDecoration(requireContext(),
                15, 24, 16));
        dir = Keys.getAllDir().get(position);
        List<String> list = Keys.fileExistsInAssets(requireContext(), dir);
        ImageAdapter adapter = new ImageAdapter(list,requireContext(),requireActivity());
        binding.recyclerView.setAdapter(adapter);
        return binding.getRoot();
    }
}