package com.prank.master;

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

import com.anythink.core.api.ATSDK;
import com.anythink.core.api.NetTrafficeCallback;
import com.prank.master.db.Bean;
import com.prank.master.db.Category;
import com.prank.master.db.ObManager;
import com.prank.master.topon.AdManager;
import com.prank.master.utils.CommonUtils;

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

public class MyApp extends Application {

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

    public static String TAG = "---------Prank Master-----";

    private String APPId ="h67a4770754962";

    private String AppKey ="a44a46425ef9951c1f2c22a24338b5000";

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        initSDk();
        AssetManager assets = getAssets();
        defaultFont = Typeface.createFromAsset(assets, "115_Black.ttf");
        ObManager.init(this);
        if (bean != null)
            return;
        try {
            InputStream open = getAssets().open("audio.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(){
        ATSDK.checkIsEuTraffic(this, new NetTrafficeCallback() {

            @Override
            public void onResultCallback(boolean isEU) {
                if (isEU && ATSDK.getGDPRDataLevel(MyApp.this) == ATSDK.UNKNOWN) {
                    ATSDK.showGdprAuth(MyApp.this);
                }

            }

            @Override
            public void onErrorCallback(String errorMsg) {

            }
        });
        ATSDK.init( this, APPId, AppKey);
        AdManager.loadAllAd();
    }
}
