package com.prank.sound.funnyapp;

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

import com.prank.sound.funnyapp.bean.MyInfo;

import com.prank.sound.funnyapp.bean.MyBean;
import com.prank.sound.funnyapp.bean.DbManager;
import com.prank.sound.funnyapp.mytool.Common;

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<MyBean> bean;

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        AssetManager assets = getAssets();
        defaultFont = Typeface.createFromAsset(assets, "prankfont.ttf");
        DbManager.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 (MyBean category:bean){
                    for (MyInfo info1 : category.getInfoList()) {
                        info1.setLike(false);
                        DbManager.getBoxBean().put(info1);
                    }
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
