package com.prank.simulator.sounds;

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

import com.prank.simulator.sounds.data.ChildData;
import com.prank.simulator.sounds.data.Category;
import com.prank.simulator.sounds.helper.Db;
import com.prank.simulator.sounds.helper.Utils;

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

public class PrankApp extends Application {

    public static PrankApp app;
    public static Typeface defaultFont;
    public static List<Category> bean;

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        AssetManager assets = getAssets();
        defaultFont = Typeface.createFromAsset(assets, "115.ttf");
        Db.init(this);
        if (bean != null)
            return;
        try {
            InputStream open = getAssets().open("sounds.json");
            String string = Utils.getString(open);
            if (!string.isEmpty()) {
                bean = Utils.getBean(string);
                for (Category category:bean){
                    for (ChildData childData1 : category.getChildDataList()) {
                        childData1.setLike(false);
                        Db.getBoxBean().put(childData1);
                    }
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
