package com.light.prank.sound.app.utils;

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

import com.light.prank.sound.app.dataListener.SoundsWrapper;
import com.light.prank.sound.app.dataListener.PrankBean;

import com.light.prank.sound.app.dataListener.objectBoxMan;

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

public class App extends Application {

    public static App app;
    public static Typeface defaultFont;
    public static List<SoundsWrapper> bean;
    private List<PrankBean> prankBeanList;

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        AssetManager assets = getAssets();
        defaultFont = Typeface.createFromAsset(assets, "pranks.ttf");
        objectBoxMan.init(this);
        if (bean != null)
            return;
        try {
            prankBeanList = new ArrayList<>();
            InputStream open = getAssets().open("prank.json");
            String string = MyUtils.getString(open);
            if (!string.isEmpty()) {
                bean = MyUtils.getBean(string);
                for (SoundsWrapper category:bean){
                    for (PrankBean prankBean1 : category.getPrankBeanList()) {
                        prankBean1.setLike(false);
                        prankBeanList.add(prankBean1);

                    }
                }
            }
            Collections.shuffle(prankBeanList);
            objectBoxMan.getBoxBean().put(prankBeanList);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
