package com.app.wallpaper.getdata;

import android.app.AlertDialog;
import android.app.Application;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;


import com.app.wallpaper.R;
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 SetData extends Application {

    private static final List<GetWalls> AllWalls=new ArrayList<>();
    private static final List<Urldata> dataUrls=new ArrayList<>();
    static Context context;
    public static final String abc="app_database";
    public static final int vs=1;


    public static Context getContext() {
        return context;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        context = getBaseContext();
        try {
            InputStream open = getAssets().open("test_new.json");
            String covertStr = ReadFile.getCovertStr(open);
            if (!covertStr.isEmpty()) {
                Gson gson = new Gson();
                Type type = new TypeToken<List<GetWalls>>() {
                }.getType();
                List<GetWalls> catas=gson.fromJson(covertStr,type);
                for (GetWalls categories:catas){
                    AllWalls.add(categories);
                 for (Urldata urldata:categories.getList()){
                     dataUrls.add(urldata);
                 }

                }

            }

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


    public static List<Urldata> getDataUrls() {
        return dataUrls;
    }

    public static List<GetWalls> getCataDatas() {
        return AllWalls;
    }
}
