package com.haircut.pranks.app;

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

import com.haircut.pranks.app.data.ChildData;

import com.haircut.pranks.app.data.ParentData;
import com.haircut.pranks.app.manager.DataManager;
import com.haircut.pranks.app.manager.Tools;

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

public class HaircutApp extends Application {

    public static HaircutApp app;
    public static Typeface defaultFont;
    public static List<ParentData> bean;

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