package com.fun.funnyprank.fragment;

import android.app.Activity;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.fun.funnyprank.R;
import com.fun.funnyprank.adapter.LikeAdapter;

import com.fun.funnyprank.data.LikeData;
import com.fun.funnyprank.data.MydataBase;
import com.fun.funnyprank.databinding.FragmentLikeBinding;
import com.fun.funnyprank.tools.Mytools;

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


public class LikeFragment extends Fragment {

    FragmentLikeBinding binding;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        binding = FragmentLikeBinding.inflate(inflater, container, false);
        initData();

        return binding.getRoot();
    }

    private void initData() {
        MydataBase.getInstance().likeDao().getLikelist(true).observe(getViewLifecycleOwner(), new Observer<List<LikeData>>() {
            @Override
            public void onChanged(List<LikeData> mydata) {
                if (mydata.isEmpty()) {
                    binding.likeHintText.setVisibility(View.VISIBLE);
                    binding.likeHintImage.setVisibility(View.VISIBLE);
                    binding.likeRv.setVisibility(View.GONE);
                } else {
                    binding.likeRv.setVisibility(View.VISIBLE);
                    binding.likeHintImage.setVisibility(View.GONE);
                    binding.likeHintText.setVisibility(View.GONE);
                    binding.likeRv.setAdapter(new LikeAdapter(requireActivity(), mydata));
                    binding.likeRv.setLayoutManager(new LinearLayoutManager(requireContext()));
                }
            }
        });
    }

}