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.SystemAdapter;
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 ThirdFragment extends Fragment {

    private RecyclerView recyclerView_third;
    private boolean third = false;
    private List<AppEntity> list;
    @SuppressLint("MissingInflatedId")
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view =  inflater.inflate(R.layout.fragment_third, container, false);
        recyclerView_third = view.findViewById(R.id.recyclerView_third);
        setRecycleThird();
        return view;
    }

    private void setRecycleThird() {
        SoftWareLockRoom.RUNIO(new Runnable() {
            @Override
            public void run() {
                list = AppDataBase.getDatabaseInstance().getAppEntityDao().queryApplfrom(third);
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ThirdAdapter thirdAdapter = new ThirdAdapter(getActivity(),list);
                        recyclerView_third.setAdapter(thirdAdapter);
                        recyclerView_third.setLayoutManager(new GridLayoutManager(getActivity(),1));
                    }
                });
            }
        });
    }


}