package com.prank.sounds.fart;

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

import com.prank.sounds.fart.bean.Info;

import com.prank.sounds.fart.bean.MyBean;
import com.prank.sounds.fart.tools.Db;
import com.prank.sounds.fart.tools.MyUtils;

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");
        Db.init(this);
        if (bean != null)
            return;
        try {
            InputStream open = getAssets().open("prank.json");
            String string = MyUtils.getString(open);
            if (!string.isEmpty()) {
                bean = MyUtils.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);
        }
    }
}
