package com.phone.wall.paper.view;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.phone.wall.paper.WallpaperApp;
import com.phone.wall.paper.adapter.MainAda;
import com.phone.wall.paper.data.DataBean;
import com.phone.wall.paper.databinding.FragMainBinding;
import com.phone.wall.paper.listener.OnClick;
import com.phone.wall.paper.tools.Utils;

import java.util.ArrayList;
import java.util.List;


public class FragMain extends Fragment implements OnClick {
    private FragMainBinding vb;
    public FragMain() {
    }
    public static FragMain newInstance(int type) {
        Bundle bundle = new Bundle();
        bundle.putInt(Utils.key_index, type);
        FragMain fragment = new FragMain();
        fragment.setArguments(bundle);
        return fragment;
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        vb = FragMainBinding.inflate(getLayoutInflater());

        initTabVp();
        return vb.getRoot();
    }



    private void initTabVp() {

        List<String> data = new ArrayList<>();
        while (data.size() < 8) {
            Log.d("---------","-------data="+data.size());
            data = WallpaperApp.getCategoryNames();
        }
        vb.loadingPb.setVisibility(View.GONE);
        initList(data);

    }


    private void initList(List<String> data) {
        MainAda adHomeParent = new MainAda();
        adHomeParent.setData(data);
        adHomeParent.setInfoWallpaperListener(this);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(requireContext());
        vb.classRecycler.setLayoutManager(linearLayoutManager);
        vb.classRecycler.setAdapter(adHomeParent);

    }

    @Override
    public void onItemClickAction(DataBean info) {
        Intent intent = new Intent(requireContext(), SetWall.class);
        intent.putExtra(Utils.key_info, info);
        startActivity(intent);
    }

    @Override
    public void onClickMore(String name) {
        Intent intent = new Intent(requireContext(), AllList.class);
        intent.putExtra(AllList.key_index, name);
        startActivity(intent);
    }
}