package com.example.applock.fragment;

import android.annotation.SuppressLint;
import android.content.Intent;
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.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.applock.R;
import com.example.applock.allmanager.MyWorker;
import com.example.applock.lockadapter.SystemAdapter;
import com.example.applock.roombase.AppDataBase;
import com.example.applock.roombase.AppEntity;
import com.example.applock.roombase.SoftWareLockRoom;
import com.example.applock.value.Mytool;

import java.util.List;

public class SystemFragment extends Fragment {

    private RecyclerView recyclerView_apps;
    private List<AppEntity> list;
    private boolean system = true;

    @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_system, container, false);
        recyclerView_apps = view.findViewById(R.id.recyclerView_apps);
        setRecycleSystem();
        return view;
    }

    private void setRecycleSystem() {
        SoftWareLockRoom.RUNIO(new Runnable() {
            @Override
            public void run() {
                list = AppDataBase.getDatabaseInstance().getAppEntityDao().queryApplfrom(system);
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        SystemAdapter systemAdapter = new SystemAdapter(getActivity(),list);
                        recyclerView_apps.setAdapter(systemAdapter);
                        recyclerView_apps.setLayoutManager(new GridLayoutManager(getActivity(),1));
                    }
                });
            }
        });
    }

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