package com.hd.wallpaper.free.walls;

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

import com.hd.wallpaper.free.walls.json.Category;
import com.hd.wallpaper.free.walls.utils.CommonUtils;
import com.hd.wallpaper.free.walls.utils.CommonKt;
import com.hd.wallpaper.free.walls.db.DbManager;
import com.hd.wallpaper.free.walls.json.Data;

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

public class MyWallpaper extends Application {
    public static Context mAppContext;

    private static List<Data> natureList;
    private static List<Data> animalsList;

    private static List<Data> experimentalList;
    private static List<Data> filmList;
    private static List<Data> patternsList;
    private static List<Data> streetList;

    private static List<Data> travelList;
    public static String TAG = "-------MyApp---------";
    public static Typeface defaultFont;

//    private String APPId="h673ddf8ae8467";
//    private String AppKey="a17cd7a62720b00498a8dc5c538c92303";
//    private String debug_Key="";

    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 static List<Category>  data = new ArrayList<>();
    @Override
    public void onCreate() {
        super.onCreate();
        mAppContext = this;
        defaultFont = Typeface.createFromAsset(getAssets(), "custfont.ttf");
        DbManager.init(this);
        String[] names = {animasName,exName,filmName,natureName,pattName,streetName,travelName};
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    for(String name:names){
                        InputStream open = getAssets().open(name);
                        String covertStr = CommonUtils.getCovertStr(open);
                        if (!covertStr.isEmpty()) {
                            List<Data> data1 = CommonKt.INSTANCE.getData(covertStr);
                            Category category = new Category();
                             String realName = name.substring(0, name.indexOf("."));
                            category.setClassName(realName);
                            List<Data> data2 = data1.subList(0, 200);
                            Collections.shuffle(data2);
                            category.setDataList(data2);
                            data.add(category);

                        }
                    }
                    Log.d(MyWallpaper.TAG,"------------data complete");
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }).start();
    }

    public static List<Category> getData() {
//        Collections.shuffle(data);
        return data;
    }



//    private void initTop(){
//        ATSDK.checkIsEuTraffic(this, new NetTrafficeCallback() {
//
//            @Override
//            public void onResultCallback(boolean isEU) {
//                Log.e(TAG, "onResultCallback:" + isEU);
//                if (isEU && ATSDK.getGDPRDataLevel( MyApp.mAppContext) == ATSDK.UNKNOWN) {
//                    ATSDK.showGdprAuth(MyApp.mAppContext);
//                }
//
//            }
//
//            @Override
//            public void onErrorCallback(String errorMsg) {
//                Log.e(TAG, "onErrorCallback:" + errorMsg);
//            }
//        });
//
//        ATSDK.init( this, APPId, AppKey);
//        //测试工具
////        ATDebuggerUITest.showDebuggerUI(this,debug_Key);
//        AdManager.loadAllAd();
//
//    }
}
