package com.example.wallpapermagazine;

import android.app.Application;
import android.content.Context;

import com.example.wallpapermagazine.json.Info;
import com.example.wallpapermagazine.json.Info_data;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class WallPaperSelect extends Application {
    private static final List<Info> userList = new ArrayList<>();
    private static List<Info_data> cataname = new ArrayList<>();
    public static Context context;
    public static final String aaa = "app_database";
    public static final int vvvaa = 1;
    public static String TAG = "=============";

    public static boolean initSDkOK = false;
    public static String initAction = "ACTION_INIT";

    private String SDK_KEY = "B16JDnq2XTvLHqPBl7HpoKPpP15v1VLRuFdB8wtkJXGdiJHxXSbizUSrFaaz4t5rmRXbHbTcqO1o6tm779ymUf";

    @Override
    public void onCreate() {
        super.onCreate();
        context = getBaseContext();
        initMAxSDk();
        try {
            InputStream open = getAssets().open("wallpaper.json");
            String covertStr = ReadFile.getCovertStr(open);
            if (!covertStr.isEmpty()) {
                Gson gson = new Gson();
                Type type = new TypeToken<List<Info_data>>() {
                }.getType();
                List<Info_data> names = gson.fromJson(covertStr, type);
                for (Info_data Name : names) {
                    cataname.add(Name);
                    for (Info info : Name.getDatas()) {
                        userList.add(info);
                    }
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static List<Info_data> getCataName() {

        return cataname;
    }

    public static List<Info> getUserList() {
        Collections.shuffle(userList);
        return userList;
    }

    private void initMAxSDk() {


    }
}
