package com.example.prettywallpapers.fragment;

import android.annotation.SuppressLint;
import android.graphics.Typeface;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.prettywallpapers.R;
import com.example.prettywallpapers.prettyadapter.LIkePaperAdapter;
import com.example.prettywallpapers.room.PrettyPaperDatabase;
import com.example.prettywallpapers.room.PrettyPaperEntity;
import com.example.prettywallpapers.room.MyTool;

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

public class LikeFragment extends Fragment {
    //private PaperVM paperVM;
    private RecyclerView like_recycle;
    private TextView text_id;
    private ImageView like_back;
    private LIkePaperAdapter lIkePaperAdapter;
    private boolean islike = true;
    private List<PrettyPaperEntity> list;

    @SuppressLint("MissingInflatedId")
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        Log.d("----0,","----------+onCreateView");
        View view = inflater.inflate(R.layout.fragment_like, container, false);
        like_recycle = view.findViewById(R.id.like_recycle);
        text_id = view.findViewById(R.id.text_id);
        text_id.setTypeface(Typeface.createFromAsset(getActivity().getAssets(),"myfront.ttf"));
        /*Bundle bundle = new Bundle();
        bundle.putBoolean(MyValues.fragment_type, like);
        this.setArguments(bundle);*/

        setRecycleLike();
        return view;
    }
    private void setRecycleLike() {
        MyTool.runIO(new Runnable() {
            @Override
            public void run() {
                list = PrettyPaperDatabase.getPrettyPaperDatabase().getPrettyPaperDao().queryData(true);
                requireActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        LIkePaperAdapter lIkePaperAdapter = new LIkePaperAdapter(requireContext(), list);
                        Log.d("----------adapter","_____apapet"+lIkePaperAdapter);
                        like_recycle.setAdapter(lIkePaperAdapter);
                        GridLayoutManager gridLayoutManager = new GridLayoutManager(requireContext(),2);
                        like_recycle.setLayoutManager(gridLayoutManager);

                    }
                });

            }
        });

    }

    @Override
    public void onResume() {
        super.onResume();
        setRecycleLike();
        Log.d("----0,","----------+onResume");
    }
}