package com.prank.tool.sounds.app;

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

import com.prank.tool.sounds.app.data.Sounds;
import com.prank.tool.sounds.app.data.detail;

import com.prank.tool.sounds.app.data.Db;
import com.prank.tool.sounds.app.common.MyUtils;

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

public class MyPrank extends Application {

    public static MyPrank app;
    public static Typeface defaultFont;
    public static List<Sounds> bean;

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        AssetManager assets = getAssets();
        defaultFont = Typeface.createFromAsset(assets, "pranks.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 (Sounds category:bean){
                    for (detail detail1 : category.getDetailList()) {
                        detail1.setLike(false);
                        Db.getBoxBean().put(detail1);
                    }
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
