package com.lc.myapplication.security.locks;

import android.app.Application;
import android.content.Intent;
import android.util.Log;

import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import com.applovin.sdk.AppLovinMediationProvider;
import com.applovin.sdk.AppLovinSdk;
import com.applovin.sdk.AppLovinSdkConfiguration;
import com.applovin.sdk.AppLovinSdkInitializationConfiguration;
import com.bytedance.frameworks.encryptor.BuildConfig;
import com.lc.myapplication.security.locks.lockroom.SecurityLockDataBase;
import com.lc.myapplication.security.locks.lockroom.SecurityLockEntity;
import com.lc.myapplication.security.locks.tool.AppsManager;
import com.lc.myapplication.security.locks.tool.MyTools;
import com.lc.myapplication.security.locks.value.MeValues;

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

public class Securitylocks extends Application {
    public static String TAG = "=============";

    public static boolean initSDkOK = false;
    public static String initAction = "ACTION_INIT";

    public static int userOption =0;

    private String SDK_KEY = "i4k2zRVkJrBdZ2AlcVyiG2B1feL1OvMldT2ea5279uyuoGXtC_5uGTbx7Up_JehNT_K0TmZK42hpEAFFwlHLEb";
    public static List<SecurityLockEntity> securityLockEntities = new ArrayList<>();

    @Override
    public void onCreate() {
        super.onCreate();
        MeValues.lock = this;
        initMAxSDk();
        MyTools.init(this);
        Set<SecurityLockEntity> entities = AppsManager.queryapps(this);
        //Log.d("--------en1","----------"+entities.size());
        AppsManager.insertEntity(entities);
        // Log.d("--------en2","----------"+securityLockEntities.size());
        MyTools.RUNIO(new Runnable() {
            @Override
            public void run() {
                securityLockEntities = SecurityLockDataBase.getSecurityLockDataBase().getsecurityLockDAO().GetAllapp();
            }
        });
    }

    private void initMAxSDk() {

        AppLovinSdkInitializationConfiguration initConfig = AppLovinSdkInitializationConfiguration.builder(SDK_KEY, this)
                .setMediationProvider(AppLovinMediationProvider.MAX)
                .build();
        // Initialize the SDK with the configuration
        AppLovinSdk.getInstance(this).initialize(initConfig, new AppLovinSdk.SdkInitializationListener() {
            @Override
            public void onSdkInitialized(AppLovinSdkConfiguration appLovinSdkConfiguration) {
                initSDkOK = true;
                Log.d(TAG, "-------------ok");
                LocalBroadcastManager.getInstance(Securitylocks.this).sendBroadcast(new Intent(initAction));
            }
        });

//        AppLovinSdk.getInstance(Securitylocks.this).showMediationDebugger();
    }
}
