package com.lh.wallpaper2;

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

import com.anythink.core.api.ATSDK;
import com.anythink.core.api.NetTrafficeCallback;

import com.google.firebase.FirebaseApp;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lh.wallpaper2.file.ReadFile;
import com.lh.wallpaper2.json.Info;
import com.lh.wallpaper2.json.Url;
import com.lh.wallpaper2.topon.AdManager;

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

public class Wallpaper extends Application {
    public static Context mAppContext;
    private static List<Info> userList = new ArrayList<Info>();
    private List<Url> urlList = new ArrayList<Url>();
    public static final String dadgsfgsf = "app_database";
    public static final int aadasdasd = 1;

    private static final String AppKey = "afc3a0e543b433cd789b80bea2f3e9ea8";
    private static final String APPId = "h670f329117ad0";

    public static String TAG = "-------Wallpaper----------";

    @Override
    public void onCreate() {
        super.onCreate();
        mAppContext = this;

//        // 确保Firebase初始化
//        FirebaseApp.initializeApp(this);
//
//        // 输出日志以确认Firebase初始化
//        if (!FirebaseApp.getApps(this).isEmpty()) {
//            Log.d(TAG, "Firebase 初始化成功");
//        } else {
//            Log.e(TAG, "Firebase 初始化失败");
//        }

        initSDk();

        try {
            InputStream open = getAssets().open("pink_wallpaper.json");
            String covertStr = ReadFile.getCovertStr(open);
            if (!covertStr.isEmpty()) {
                Gson gson = new Gson();
                Type type = new TypeToken<List<Info>>() {
                }.getType();
                userList = gson.fromJson(covertStr, type);
                for (Info info : userList) {
                    for (Url url : info.getList()) {
                        urlList.add(url);
                    }
                }
                Log.d("22222222222222", "onCreate: " + urlList.size());
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static Context getmAppContext() {
        return mAppContext;
    }

    public static List<Info> getUserList() {
        Log.d("------------", "-------------userList=" + userList);
        return userList;
    }


    private void initSDk() {

        ATSDK.checkIsEuTraffic(this, new NetTrafficeCallback() {

            @Override
            public void onResultCallback(boolean isEU) {
                Log.e(TAG, "onResultCallback:" + isEU);
                if (isEU && ATSDK.getGDPRDataLevel(Wallpaper.this) == ATSDK.UNKNOWN) {
                    ATSDK.showGdprAuth(Wallpaper.this);
                }

            }

            @Override
            public void onErrorCallback(String errorMsg) {
                Log.e(TAG, "onErrorCallback:" + errorMsg);
            }
        });

        ATSDK.init(this, APPId, AppKey);
        AdManager.loadAllAd();
        //测试工具
//        ATDebuggerUITest.showDebuggerUI(this,"a8dd4a3f1c38a5a3cadb4f39385fb682af63df07");

    }


}
