package com.prank.simulator.sounds;

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.anythink.debug.api.ATDebuggerUITest;
import com.prank.simulator.sounds.data.Category;
import com.prank.simulator.sounds.data.ChildData;
import com.prank.simulator.sounds.helper.Db;
import com.prank.simulator.sounds.helper.Utils;
import com.prank.simulator.sounds.topon.AdManager;

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

public class PrankApp extends Application {

    public static PrankApp app;
    public static Typeface defaultFont;
    public static List<Category> bean;
    public static final String TAG = "==========";

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        AssetManager assets = getAssets();
        initAd();
        defaultFont = Typeface.createFromAsset(assets, "115.ttf");
        Db.init(this);
        if (bean != null)
            return;
        try {
            InputStream open = getAssets().open("sounds.json");
            String string = Utils.getString(open);
            if (!string.isEmpty()) {
                bean = Utils.getBean(string);
                for (Category category : bean) {
                    for (ChildData childData1 : category.getChildDataList()) {
                        childData1.setLike(false);
                        Db.getBoxBean().put(childData1);
                    }
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    private void initAd() {
        ATSDK.checkIsEuTraffic(this, new NetTrafficeCallback() {

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

            @Override
            public void onErrorCallback(String s) {

            }
        });
        String APPId = "h67d2713402dfe";
        String AppKey = "a93991341a41d40221ddada4c4675e7d2";
        ATSDK.init(this, APPId, AppKey);
//        ATSDK.setNetworkLogDebug(true);
        AdManager.loadAllAd();
        //测试工具
//        ATDebuggerUITest.showDebuggerUI(this,"62eed2fbebbb41fdc21186f66533e9d2904185ce");
    }
}
