package com.app;

import androidx.multidex.MultiDex;
import androidx.multidex.MultiDexApplication;

import com.app.duck.BuildConfig;
import com.app.duck.Config;
import com.app.duck.util.HxUtils;
import com.app.duck.util.WsManager;
import com.blankj.utilcode.util.Utils;
import com.elvishew.xlog.LogConfiguration;
import com.elvishew.xlog.XLog;
import com.elvishew.xlog.flattener.ClassicFlattener;
import com.elvishew.xlog.printer.Printer;
import com.elvishew.xlog.printer.file.FilePrinter;
import com.elvishew.xlog.printer.file.backup.BackupStrategy2;
import com.elvishew.xlog.printer.file.backup.FileSizeBackupStrategy2;
import com.elvishew.xlog.printer.file.clean.FileLastModifiedCleanStrategy;
import com.elvishew.xlog.printer.file.naming.ChangelessFileNameGenerator;
import com.microsoft.appcenter.AppCenter;
import com.microsoft.appcenter.analytics.Analytics;
import com.microsoft.appcenter.crashes.Crashes;

import org.xutils.x;

public class MainApp extends MultiDexApplication {

    @Override
    public void onCreate() {
        super.onCreate();
        MultiDex.install(this);
        x.Ext.init(this);
        x.Ext.setDebug(BuildConfig.DEBUG);
        AppCenter.start(this, BuildConfig.UPDATE_KEY, Analytics.class, Crashes.class);
        WsManager.connectWebSocket();
        Printer filePrinter = new FilePrinter
                .Builder(Utils.getApp().getFilesDir().getPath() + "/ulog")
                .fileNameGenerator(new ChangelessFileNameGenerator(BuildConfig.UPDATE_KEY + ".txt"))
                .backupStrategy(new FileSizeBackupStrategy2(1024 * 1024 * 5, BackupStrategy2.NO_LIMIT))
                .cleanStrategy(new FileLastModifiedCleanStrategy(1000 * 60 * 24 * 7))
                .flattener(new ClassicFlattener())
                .build();
        LogConfiguration config = new LogConfiguration.Builder()
                .tag(Config.LOG_TAG).build();
        XLog.init(config, filePrinter);
    }

}
