package com.tool.applockpro;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

import com.tool.applockpro.data.MyDataBase;
import com.tool.applockpro.data.Mydata;
import com.tool.applockpro.tool.Mytools;

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

public class ApplockSkin extends Application {
    public static final String DB_Name = "lock_database";
    public static final String Table_Name = "lock_table";
    public static final int DB_Version = 1;
    private static Context context;
    private static final String PREFS_NAME = "MyPrefs";
    private static final String KEY_PWD = "key_pwd";
    public static SharedPreferences sp;
    public static SharedPreferences.Editor et;
    public static final int checkpwd_0 = 0;
    public static List<Mydata> system = new ArrayList<>();
    public static List<Mydata> third = new ArrayList<>();
    public static List<Mydata> lock = new ArrayList<>();

    public static List<Mydata> getSystem() {
        return system;
    }

    public static List<Mydata> getThird() {
        return third;
    }

    public static List<Mydata> getLock() {
        return lock;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
        Mytools.getapplist(this);


        sp = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
        et = sp.edit();

        initData();
    }

    private void initData() {

//        Mytools.runIO(new Runnable() {
//            @Override
//            public void run() {
//                system = MyDataBase.getINSTANCE().mydao().getappissystem(true);
//                third = MyDataBase.getINSTANCE().mydao().getappissystem(false);
//                lock = MyDataBase.getINSTANCE().mydao().getlockapp(true);
//
//            }
//        });

    }

    public static void savePWD(String pwd) {
        et.putString(KEY_PWD, pwd);
        et.apply();
//        Log.e("zzj", "--------savepwd----------" + pwd);
    }

    public static String getPWD() {
        return sp.getString(KEY_PWD, "");
    }

    public static Context getContext() {
        return context;
    }
}
