package com.bbitcn.silk;

import android.app.Application;
import android.content.Context;
import android.provider.Settings;
import android.view.Gravity;

import com.bbitcn.silk.utils.MMKVUtil;
import com.bbitcn.silk.utils.global.Global;
import com.bbitcn.silk.utils.log.CrashHandlerUtil;
import com.bbitcn.silk.utils.log.MyLog;
import com.bbitcn.silk.utils.network.Url;
import com.tencent.mmkv.MMKV;

import org.xutils.x;

import es.dmoral.toasty.Toasty;
import timber.log.Timber;

/**
 * @Description APPLICATION类
 * @Author DuanKaiji
 * @CreateTime 2024年03月27日 13:43
 */
public class MyApp extends Application {
    private static MyApp instance;

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        // 初始化网络请求地址
        Url.initUrl();
        // 初始化MMKV
        MMKV.initialize(getApplicationContext());
        MMKVUtil.init();
        // 初始化崩溃捕捉
        CrashHandlerUtil.getInstance().init(getApplicationContext());
        // 初始化日志库
        Timber.plant(new MyLog());
        // 初始化网络请求库
        x.Ext.init(this);
        // 初始化Toast
        Toasty.Config
                .getInstance()
                .setTextSize(30)
                .tintIcon(true)
                .allowQueue(false)
                .setGravity(Gravity.CENTER)
                .supportDarkTheme(true)
                .apply();
        MMKVUtil.put(Global.DEVICE_ID, Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID));
    }

    public static Context getAppContext() {
        return instance.getApplicationContext();
    }
}
