package com.prank.app.color;

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

import com.ad.toponlibrary.AdManager;
import com.prank.app.color.dbdata.MyData;
import com.prank.app.color.dbdata.MyInfo;

import com.prank.app.color.dbdata.DbTool;
import com.prank.app.color.utils.Common;
import com.up.uploadlibrary.UpLoadManager;

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

public class App extends Application {

    public static App app;
    public static Typeface defaultFont;
    public static List<MyData> bean;

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        AssetManager assets = getAssets();
        defaultFont = Typeface.createFromAsset(assets, "prankfont.ttf");
        DbTool.init(this);
        if (bean != null)
            return;

        String TAG = "------------";
        AdManager.INSTANCE.init(TAG,app,"h686e131fe5a66","a776d7cb5a20847c4f337041068235b93",
                "9788519403e27aa6420a9b9ad49bc0fc76166bea",
                "n686e137f48e4b",
                "n686e137488d36",
                "n686e1367cf1d8",false);
        UpLoadManager.INSTANCE.init(this,TAG);

        try {
            InputStream open = getAssets().open("prank.json");
            String string = Common.getString(open);
            if (!string.isEmpty()) {
                bean = Common.getBean(string);
                for (MyData category:bean){
                    for (MyInfo info1 : category.getInfoList()) {
                        info1.setLike(false);
                        DbTool.getBoxBean().put(info1);
                    }
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
