package com.study.sketch.learning.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.study.sketch.learning.SketchingApp;
import com.study.sketch.learning.activity.ActivityAllInfo;
import com.study.sketch.learning.activity.ActivitySketching;
import com.study.sketch.learning.databinding.FragmentMainBinding;
import com.study.sketch.learning.item.AdapterMain;
import com.study.sketch.learning.listener.OnClickListener;

public class FragmentMain extends Fragment implements OnClickListener {

    private FragmentMainBinding binding;

    public FragmentMain() {

    }

    public static FragmentMain newInstance() {
        FragmentMain fragment = new FragmentMain();
        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() {
        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(), ActivityAllInfo.class);
                intent.putExtra(SketchingApp.Key_ViewDir, dir);
                startActivity(intent);
                break;
            case 1:
                Intent intent1 = new Intent(requireContext(), ActivitySketching.class);
                intent1.putExtra(SketchingApp.Key_Camera, dir);
                startActivity(intent1);
                break;
        }


    }
}