package com.prank.sound.app;

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.sound.app.mydata.ChildData;
import com.prank.sound.app.mydata.Category;
import com.prank.sound.app.myutils.ObUtils;
import com.prank.sound.app.myutils.Utils;
import com.prank.sound.app.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 String TAG = "-------PrankApp-----";

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        AssetManager assets = getAssets();
        defaultFont = Typeface.createFromAsset(assets, "115_Black.ttf");
        ObUtils.init(this);
        initAd();
        if (bean != null)
            return;
        try {
            InputStream open = getAssets().open("audio.json");
            String string = Utils.getString(open);
            if (!string.isEmpty()) {

                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        bean = Utils.getBean(string);
                        for (Category category : bean) {
                            for (ChildData childData1 : category.getChildDataList()) {
                                childData1.setLike(false);
                                ObUtils.getBoxBean().put(childData1);
                            }
                        }
                    }
                }).start();

            }


        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    private void initAd() {
        String APPId = "h67c1520295911";
        String AppKey = "ac7ef64e75e744dfdbd150b224460e412";
        String debug = "4e26d6fdb6029c920a512f4d896f6331f47c82d0";
        ATSDK.checkIsEuTraffic(this, new NetTrafficeCallback() {

            @Override
            public void onResultCallback(boolean isEU) {

                if (isEU && ATSDK.getGDPRDataLevel(PrankApp.this) == ATSDK.UNKNOWN) {
                    ATSDK.showGdprAuth(PrankApp.this);
                }

            }

            @Override
            public void onErrorCallback(String errorMsg) {

            }
        });
        ATSDK.init(this, APPId, AppKey);
//        ATDebuggerUITest.showDebuggerUI(this,debug);
        AdManager.loadAllAd();
    }
}
