package com.ar.drawing.art.fragmen;

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.art.activity.UIAllList;
import com.ar.drawing.art.activity.UIDetail;
import com.ar.drawing.art.adapter.AdaMain;
import com.ar.drawing.art.databinding.FragHomeBinding;
import com.ar.drawing.art.listener.OnClickListener;
import com.ar.drawing.art.utils.ArtApp;

public class FragHome extends Fragment implements OnClickListener {

    private FragHomeBinding binding;

    public FragHome() {

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


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


        return binding.getRoot();
    }

    private void onInitRecycler() {
        AdaMain adaMain = new AdaMain(requireContext());
        adaMain.setListener(this::onClickItem);
        binding.recyclerview.setAdapter(adaMain);
        binding.recyclerview.setLayoutManager(new GridLayoutManager(requireContext(), 1));
    }


    @Override
    public void onClickItem(int type, String dir) {
        switch (type) {
            case 0:
                Intent intent = new Intent(requireContext(), UIAllList.class);
                intent.putExtra(ArtApp.Key_ViewDir, dir);
                startActivity(intent);
                break;
            case 1:
                Intent intent1 = new Intent(requireContext(), UIDetail.class);
                intent1.putExtra(ArtApp.Key_Camera, dir);
                startActivity(intent1);
                break;
        }


    }
}