package com.prank.app.color;

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

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 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;
        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);
        }
    }
}
