package com.prankster.fx;

import android.app.Application;
import android.content.res.AssetManager;
import android.graphics.Typeface;

import com.applovin.sdk.AppLovinMediationProvider;
import com.applovin.sdk.AppLovinSdk;
import com.applovin.sdk.AppLovinSdkConfiguration;
import com.applovin.sdk.AppLovinSdkInitializationConfiguration;
import com.prankster.fx.db.Bean;
import com.prankster.fx.db.Category;
import com.prankster.fx.db.ObManager;
import com.prankster.fx.topon.AdManager;
import com.prankster.fx.utils.CommonUtils;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class FXApp extends Application {

    public static FXApp app;
    public static Typeface defaultFont;
    public static List<Category> bean;

    public static String TAG = "---------FX-----";

    private String APPId ="";

    private String AppKey ="";

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        initSDk();
        AssetManager assets = getAssets();
        defaultFont = Typeface.createFromAsset(assets, "black.ttf");
        ObManager.init(this);
        if (bean != null)
            return;
        try {
            InputStream open = getAssets().open("FxAudio.json");
            String string = CommonUtils.getString(open);
            if (!string.isEmpty()) {
                bean = CommonUtils.getBean(string);
                for (Category category:bean){
                    for (Bean bean1 : category.getBeanList()) {
                        bean1.setLike(false);
                        ObManager.getBoxBean().put(bean1);
                    }
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }


    private void initSDk(){
        String maxSdkKey = "qNJuTfHqsau8CXZyxyv2w4XapOhr48XdPZvBWB6wVzgv5pvEz__XieITRDapHWhsllKNSSy_H7yf6GgkkK1ziI";
        // Create the initialization configuration
        AppLovinSdkInitializationConfiguration initConfig = AppLovinSdkInitializationConfiguration.builder( maxSdkKey, this )
                .setMediationProvider( AppLovinMediationProvider.MAX )
// Perform any additional configuration/setting changes
                .build();

        // Initialize the SDK with the configuration
        AppLovinSdk.getInstance( this ).initialize( initConfig, new AppLovinSdk.SdkInitializationListener()
        {
            @Override
            public void onSdkInitialized(final AppLovinSdkConfiguration sdkConfig)
            {
                // Start loading ads
            }
        } );

        AdManager.loadAllAd();
    }
}
