package com.prank.funny.pranks;

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

import com.prank.funny.pranks.bean.Info;

import com.prank.funny.pranks.bean.MyBean;
import com.prank.funny.pranks.tools.DataBase;
import com.prank.funny.pranks.tools.Common;

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

public class FunnyApp extends Application {

    public static FunnyApp 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");
        DataBase.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);
                Collections.shuffle(bean);
                for (MyBean category:bean){
                    for (Info info1 : category.getInfoList()) {
                        info1.setLike(false);
                        DataBase.getBoxBean().put(info1);
                    }
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
