package com.ar.sketch.paint.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.paint.drawing.act.PageList;
import com.ar.sketch.paint.drawing.act.PagePreview;
import com.ar.sketch.paint.drawing.ad.MaxManager;
import com.ar.sketch.paint.drawing.adapter.ListMain;
import com.ar.sketch.paint.drawing.api.OnClick;
import com.ar.sketch.paint.drawing.databinding.FragmentHomeBinding;
import com.ar.sketch.paint.drawing.tool.MyArApp;

public class PageHome extends Fragment implements OnClick {

    private FragmentHomeBinding binding;

    public PageHome() {

    }

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

    @Override
    public void onResume() {
        super.onResume();
        MaxManager.onLoadAd();
    }

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


        return binding.getRoot();
    }

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


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


    }
}