package com.example.applock.fragment;

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

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

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

import com.example.applock.R;
import com.example.applock.lockadapter.LockedAdapter;
import com.example.applock.lockadapter.ThirdAdapter;
import com.example.applock.roombase.AppDataBase;
import com.example.applock.roombase.AppEntity;
import com.example.applock.roombase.SoftWareLockRoom;

import java.util.List;

public class LockedFragment extends Fragment {
    private RecyclerView recyclerView_locked;
    private boolean locked = true;
    private List<AppEntity> list;
    @SuppressLint("MissingInflatedId")
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view =  inflater.inflate(R.layout.fragment_locked, container, false);
        recyclerView_locked = view.findViewById(R.id.recyclerView_locked);
       setRecycleLocked();
        return view;
    }

    private void setRecycleLocked() {
        SoftWareLockRoom.RUNIO(new Runnable() {
            @Override
            public void run() {
                list = AppDataBase.getDatabaseInstance().getAppEntityDao().queryApp(locked);
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        LockedAdapter lockedAdapter = new LockedAdapter(getActivity(),list);
                        recyclerView_locked.setAdapter(lockedAdapter);
                        recyclerView_locked.setLayoutManager(new GridLayoutManager(getActivity(),1));
                    }
                });
            }
        });
    }

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