package com.haircut.pranks.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.haircut.pranks.app.data.ChildData;

import com.haircut.pranks.app.data.ParentData;
import com.haircut.pranks.app.manager.DataManager;
import com.haircut.pranks.app.manager.Tools;
import com.haircut.pranks.app.topon.AdManager;

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

public class HaircutApp extends Application {

    public static HaircutApp app;
    public static Typeface defaultFont;
    public static List<ParentData> bean;
    public static String TAG = "--------";

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

    private void initAd() {
        String APPId = "h67c180c9e9413";
        String AppKey = "a64c37c4d589074e219ba13b4be08a693";
        String debug = "529b9d845e53ac839536d321c0b6be5f6928b24d";
        ATSDK.checkIsEuTraffic(this, new NetTrafficeCallback() {

            @Override
            public void onResultCallback(boolean isEU) {

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

            }

            @Override
            public void onErrorCallback(String errorMsg) {

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