package com.lc.myapplication.security.locks.activity;

import android.annotation.SuppressLint;
import android.app.FragmentManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.lc.myapplication.security.locks.R;
import com.lc.myapplication.security.locks.Securitylocks;
import com.lc.myapplication.security.locks.adapter.AllAppsAdapter;
import com.lc.myapplication.security.locks.dialog.MsgDialog;
import com.lc.myapplication.security.locks.lockroom.SecurityLockDataBase;
import com.lc.myapplication.security.locks.lockroom.SecurityLockEntity;
import com.lc.myapplication.security.locks.max.MaxManager;
import com.lc.myapplication.security.locks.tool.MyService;
import com.lc.myapplication.security.locks.tool.MyTools;

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

public class AllAppActivity extends AppCompatActivity {
    private LinearLayout all_main;

    private RecyclerView all_apps_view;
    private ImageView all_apps_back;
    private List<SecurityLockEntity> list;
    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_all_app);
        MaxManager.onLoadAd();
        all_apps_view = findViewById(R.id.all_apps_view);
        all_apps_back = findViewById(R.id.all_apps_back);
        all_main = findViewById(R.id.all_main);
        initbackground();
        onMyClick();
        gotoGetRecycle();
    }

    private void onMyClick() {
        all_apps_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void initbackground() {
        Window window = getWindow();
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        all_main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
    }

    private void gotoGetRecycle() {
        MyTools.RUNIO(new Runnable() {
            @Override
            public void run() {
                list = SecurityLockDataBase.getSecurityLockDataBase().getsecurityLockDAO().GetAllapp();
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {


                        AllAppsAdapter allAppsAdapter = new AllAppsAdapter(AllAppActivity.this, list);
                        all_apps_view.setAdapter(allAppsAdapter);
                        all_apps_view.setLayoutManager(new GridLayoutManager(AllAppActivity.this,3));
                    }
                });

            }
        });

    }

}