package com.app.sounds.prank.party;

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.app.sounds.prank.party.bean.Info;

import com.app.sounds.prank.party.bean.MyBean;
import com.app.sounds.prank.party.common.Db;
import com.app.sounds.prank.party.common.Utils;
import com.app.sounds.prank.party.top.AdManager;

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

public class PartyApp extends Application {

    public static PartyApp app;
    public static Typeface defaultFont;
    public static List<MyBean> bean;
    public static String TAG = "=======";
    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        initAd();
        AssetManager assets = getAssets();
        defaultFont = Typeface.createFromAsset(assets, "prankfont.ttf");
        Db.init(this);
        if (bean != null)
            return;
        try {
            InputStream open = getAssets().open("prank.json");
            String string = Utils.getString(open);
            if (!string.isEmpty()) {
                bean = Utils.getBean(string);
                for (MyBean category:bean){
                    for (Info info1 : category.getInfoList()) {
                        info1.setLike(false);
                        Db.getBoxBean().put(info1);
                    }
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    private void initAd(){
        String APPId = "h680609abae69b";
        String AppKey = "a54dd3bfc1d24d58cd365789e9fe15178";
        String debug_KEy = "";
        ATSDK.checkIsEuTraffic(this, new NetTrafficeCallback() {

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

            }

            @Override
            public void onErrorCallback(String errorMsg) {

            }
        });
        ATSDK.init( this, APPId, AppKey);
        //测试工具
//        ATDebuggerUITest.showDebuggerUI(this,debug_KEy);
        AdManager.loadAllAd();
    }
}
