package com.app.sounds.prank.party;

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

import com.app.sounds.prank.party.bean.Info;

import com.app.sounds.prank.party.bean.MyBean;
import com.app.sounds.prank.party.common.Db;
import com.app.sounds.prank.party.common.Utils;

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

public class PartyApp extends Application {

    public static PartyApp 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 = Utils.getString(open);
            if (!string.isEmpty()) {
                bean = Utils.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);
        }
    }
}
