package com.datarecovery.master;

import android.content.Context;

import com.atmob.app.lib.base.BaseApplication;
import com.atmob.common.runtime.ProcessUtil;
import com.atmob.user.AtmobUser;
import com.datarecovery.master.data.consts.Constants;
import com.datarecovery.master.sdk.gravity.GravityHelper;
import com.datarecovery.master.sdk.umeng.UmengHelper;

import dagger.hilt.android.HiltAndroidApp;


@HiltAndroidApp
public class App extends BaseApplication {


    private static App INSTANCE;


    public static App getInstance() {
        return INSTANCE;
    }


    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        INSTANCE = this;
    }


    @Override
    protected boolean isDebug() {
        return BuildConfig.DEBUG;
    }

    @Override
    protected String defaultChannel() {
        return Constants.App_DefaultChannel;
    }

    @Override
    protected int defaultAppId() {
        return Constants.App_DefaultAppId;
    }

    @Override
    protected int defaultTgPlatformId() {
        return Constants.App_DefaultTgPlatformId;
    }

    @Override
    protected int complianceStrategy() {
        return AtmobUser.CHINA;
    }

    @Override
    protected void initCommon(boolean isMainProcess) {
        if (isMainProcess) {
            initBugly();
            initUmeng();
        }
    }

    @Override
    public void initAfterGrant(boolean isMainProcess) {
        if (isMainProcess) {
            GravityHelper.init(this);
        }
    }

    private void initUmeng() {
        UmengHelper.init(this);
    }

    private void initBugly() {
//        BuglyHelper.init(this);
    }

    public void firstPrivacyRelated() {
        AtmobUser.recordPolicyGrant(true);
        UmengHelper.initAfterGrantedAgreement(getApplicationContext());
        UmengHelper.submitPolicyGrantResult(getApplicationContext(), true);
//        BuglyHelper.initAfterGrantedAgreement();
        initAfterGrant(ProcessUtil.isMainProcess(this));
    }
}
