package com.paint.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.LinearLayoutManager;

import com.paint.ar.drawing.adapter.ChildAdapter;
import com.paint.ar.drawing.api.onItemListener;
import com.paint.ar.drawing.databinding.FragmentMainBinding;
import com.paint.ar.drawing.activity.AllActivity;
import com.paint.ar.drawing.MyApp;

public class MainFragment extends Fragment implements onItemListener {

    private FragmentMainBinding binding;

    public MainFragment() {

    }

    public static MainFragment newInstance() {
        MainFragment fragment = new MainFragment();
        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() {
        ChildAdapter mainAdapter = new ChildAdapter(requireContext());
        mainAdapter.setListener(this::onClickItem);
        binding.recyclerview.setAdapter(mainAdapter);
        binding.recyclerview.setLayoutManager(new LinearLayoutManager(requireContext()));
    }


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

    }
}