package com.ar.sketch.drawing.frag;

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.sketch.drawing.MyApp;
import com.ar.sketch.drawing.activity.ActivityPreview;
import com.ar.sketch.drawing.myadapter.AdapterMain;
import com.ar.sketch.drawing.mycallback.OnClickListener;
import com.ar.sketch.drawing.databinding.FragmentHomeBinding;
import com.ar.sketch.drawing.activity.ActivityList;

public class FragmentHome extends Fragment implements OnClickListener {

    private FragmentHomeBinding 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 = FragmentHomeBinding.inflate(getLayoutInflater());
        onInitRecycler();


        return binding.getRoot();
    }

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


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


    }
}