package com.ar.drawing.fragment;

import android.content.Intent;
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.ar.drawing.MyDraw;
import com.ar.drawing.activity.ListActivity;
import com.ar.drawing.adapter.MainAdapter;
import com.ar.drawing.listener.OnClickListener;
import com.ar.drawing.databinding.FragmentMainBinding;

public class FragmentHome extends Fragment implements OnClickListener {

    private FragmentMainBinding binding;

    public FragmentHome() {

    }

    public static FragmentHome newInstance() {
        FragmentHome fragment = new FragmentHome();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }


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

        return binding.getRoot();
    }

    private void onInitRecycler() {
        MainAdapter mainAdapter = new MainAdapter(requireContext());
        mainAdapter.setListener(this::onClickItem);
        binding.recyclerview.setAdapter(mainAdapter);
        binding.recyclerview.setLayoutManager(new GridLayoutManager(requireContext(), 2));
    }


    @Override
    public void onClickItem(String dir) {
        Intent intent = new Intent(requireContext(), ListActivity.class);
        intent.putExtra(MyDraw.Key_ViewDir, dir);
        startActivity(intent);

    }
}