package com.phone.wall.paper;

import android.app.Application;
import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;

import com.ad.toponlibrary.AdManager;
import com.phone.wall.paper.tools.Utils;
import com.phone.wall.paper.tools.JsonData;
import com.phone.wall.paper.tools.RoomManager;
import com.up.uploadlibrary.UpLoadManager;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class WallpaperApp extends Application {
    public static Context mAppContext;

    public static String TAG = "-------MyApp---------";
    public static Typeface defaultFont;


    private String animasName = "Animals.json";
    private String exName = "Experimental.json";
    private String filmName = "Film.json";
    private String natureName = "Nature.json";
    private String pattName = "Patterns.json";
    private String streetName = "Street.json";
    private String travelName = "Travel.json";
    private String wallpaperName = "Featured.json";
    private ExecutorService executor;
    private static List<String> CategoryNames = new ArrayList<>();
    private int i = 0;

    @Override
    public void onCreate() {
        super.onCreate();
        mAppContext = this;
        defaultFont = Typeface.createFromAsset(getAssets(), "custfont.ttf");

        AdManager.INSTANCE.init(TAG,this,"h68786a3e636fd","a5739b4755d45478c83d95ecad9ae9485",
                "9788519403e27aa6420a9b9ad49bc0fc76166bea",
                "n68786a73d8ea1",
                "n68786a67e64b5",
                "n68786a591a90d",false);
        UpLoadManager.INSTANCE.init(this,TAG);

        RoomManager.init(this);
        executor = Executors.newFixedThreadPool(8);
        String[] names = {wallpaperName, animasName, exName, filmName, natureName, pattName, streetName, travelName};

        try {
            for (String name : names) {
                InputStream open = getAssets().open(name);
                String covertStr = Utils.getCovertStr(open);
                if (!covertStr.isEmpty()) {
                    String realName = name.substring(0, name.indexOf("."));
                    CategoryNames.add(realName);
                    executor.execute(new Runnable() {
                        @Override
                        public void run() {
                            i++;
                            Log.d(WallpaperApp.TAG, "------------111");
                            JsonData.INSTANCE.getData(covertStr, realName);
                        }
                    });
                }
            }


        } catch (IOException e) {
            throw new RuntimeException(e);
        }


    }

    public static List<String> getCategoryNames() {
        return CategoryNames;
    }

}
