package com.prank.master;

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

import com.prank.master.db.Bean;
import com.prank.master.db.Category;
import com.prank.master.db.ObManager;
import com.prank.master.utils.CommonUtils;

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

public class MyApp extends Application {

    public static MyApp app;
    public static Typeface defaultFont;
    public static List<Category> bean;

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        AssetManager assets = getAssets();
        defaultFont = Typeface.createFromAsset(assets, "115_Black.ttf");
        ObManager.init(this);
        if (bean != null)
            return;
        try {
            InputStream open = getAssets().open("audio.json");
            String string = CommonUtils.getString(open);
            if (!string.isEmpty()) {
                bean = CommonUtils.getBean(string);
                for (Category category:bean){
                    for (Bean bean1 : category.getBeanList()) {
                        bean1.setLike(false);
                        ObManager.getBoxBean().put(bean1);
                    }
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
