package com.ss.android.ugc.aweme.assem;

import X.1hK;
import X.2HX;
import X.2Pr;
import X.2UX;
import X.2kf;
import X.2nK;
import X.4Cy;
import X.4U3;
import X.7lW;
import X.8Ze;
import X.9BJ;
import X.9DV;
import X.C4836EnQ;
import X.C5957FDd;
import X.C5959FDf;
import X.C5964FDk;
import X.C5990FEk;
import X.CuL;
import X.EMX;
import X.LSI;
import X.M12;
import X.TkP;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.base.MainBusinessAbility;
import com.ss.android.ugc.aweme.homepage.api.interaction.ScrollSwitchStateManager;
import com.ss.android.ugc.aweme.journey.NewUserGuideAbility;
import com.ss.android.ugc.aweme.main.IPerformanceAbility;
import com.ss.android.ugc.aweme.out.AVExternalServiceImpl;
import com.ss.android.ugc.aweme.services.IMainService;
import com.ss.android.ugc.aweme.services.MainServiceImpl;
import com.ss.android.ugc.aweme.services.external.ui.RecordConfig;
import com.ss.android.ugc.aweme.services.publish.Publish;
import com.ss.android.ugc.aweme.utils.ActivityStack;
import java.util.concurrent.FutureTask;
import kotlin.h.b.n;

public final class ToolsActivityAssem extends C4836EnQ {
    public boolean LJFF;
    public Bundle LJI;
    public FutureTask<2Pr> LJII;

    static {
        Covode.recordClassIndex(53548);
    }

    public final void LJIILJJIL() {
        super.LJIILJJIL();
        MainServiceImpl.createIMainServicebyMonsterPlugin(false).startCleanEffect(EMX.LIZJ(this));
    }

    public static Bundle LIZIZ(Intent intent) {
        try {
            return intent.getExtras();
        } catch (Exception unused) {
            return null;
        }
    }

    public static Context LIZ(1hK r1) {
        Context applicationContext = r1.getApplicationContext();
        if (7lW.LIZJ && applicationContext == null) {
            return 7lW.LIZ;
        }
        return applicationContext;
    }

    private void LIZ(boolean z) {
        EMX.LIZJ(EMX.LIZ((CuL) this), MainBusinessAbility.class).LIZ(EMX.LIZJ(this), "changeTabAfterPublish", Boolean.valueOf(z));
    }

    public final void LIZ(Intent intent) {
        M12.LIZ(intent);
        if (!LIZIZ(intent, false)) {
            1hK LIZJ = EMX.LIZJ(this);
            if (LIZJ != null) {
                EMX.LIZJ(EMX.LIZ((CuL) this), MainBusinessAbility.class).LIZ(LIZJ, "onNewIntent", intent);
                if (intent == null || !TextUtils.equals(intent.getAction(), "android.intent.action.MAIN") || !intent.hasCategory("android.intent.category.LAUNCHER")) {
                    ScrollSwitchStateManager.LJIILL.LIZ(LIZJ).LIZ("page_feed", false);
                }
            }
            M12.LIZ(intent);
            LIZ(intent, intent.getBooleanExtra("enter_record_from_other_platform", false));
        }
    }

    public final void LIZ(Bundle bundle) {
        long uptimeMillis = SystemClock.uptimeMillis();
        this.LJI = bundle;
        if (!TkP.LIZIZ()) {
            LIZIZ(bundle);
        } else {
            this.LJII = new FutureTask<>(new C5964FDk(this, bundle));
        }
        EMX.LIZJ(EMX.LIZ((CuL) this), IPerformanceAbility.class).LIZ(new C5959FDf(this));
        4Cy.LIZ(getClass().getCanonicalName(), SystemClock.uptimeMillis() - uptimeMillis, "ON_CREATE_WITH_BUNDLE", (String) null);
    }

    public final void LIZIZ(Bundle bundle) {
        super.cZ_();
        2HX.LIZ.LIZ("main_act_tools_activity_observer_duration", false);
        IMainService createIMainServicebyMonsterPlugin = MainServiceImpl.createIMainServicebyMonsterPlugin(false);
        n.LIZIZ(createIMainServicebyMonsterPlugin, "");
        8Ze cleanEffectsTask = createIMainServicebyMonsterPlugin.getCleanEffectsTask();
        4U3 r0 = new 4U3();
        n.LIZIZ(cleanEffectsTask, "");
        r0.LIZ(cleanEffectsTask);
        r0.LIZ();
        9DV.LIZ();
        1hK LIZJ = EMX.LIZJ(this);
        if (LIZJ != null) {
            Intent intent = LIZJ.getIntent();
            boolean hasExtra = intent.hasExtra("enable_optimize_main_not_in_stack");
            2kf.LIZ(3, (String) null, "ProcessPublish MainActivityCreate isMainNotInStackPublish:".concat(String.valueOf(hasExtra)));
            if (!EMX.LIZJ(EMX.LIZ((CuL) this), NewUserGuideAbility.class).LJIJJLI() && ((bundle == null && hasExtra) || Publish.isNeedProcessPublish || Publish.isInPublish)) {
                Publish.isNeedProcessPublish = false;
                n.LIZIZ(intent, "");
                LIZIZ(intent, true);
            }
            4U3 r4 = new 4U3();
            8Ze initTask = AVExternalServiceImpl.LIZ().initService().initTask(5);
            if (initTask == null) {
                n.LIZIZ();
            }
            r4.LIZ(initTask);
            8Ze initTask2 = AVExternalServiceImpl.LIZ().initService().initTask(6);
            if (initTask2 == null) {
                n.LIZIZ();
            }
            r4.LIZ(initTask2);
            8Ze initTask3 = AVExternalServiceImpl.LIZ().initService().initTask(7);
            if (initTask3 == null) {
                n.LIZIZ();
            }
            r4.LIZ(initTask3);
            r4.LIZ();
            2HX.LIZ.LIZIZ("main_act_tools_activity_observer_duration", false);
        }
    }

    /* JADX WARNING: type inference failed for: r1v3, types: [com.ss.android.ugc.aweme.services.IExternalService$ServiceLoadCallback, X.FEk] */
    public final void LIZ(Intent intent, boolean z) {
        1hK LIZJ = EMX.LIZJ(this);
        if (LIZJ != null && z) {
            this.LJFF = true;
            9BJ.LIZ(LIZ(LIZJ), "protect", "record_on");
            boolean booleanExtra = intent.getBooleanExtra("show_no_splash_ad", false);
            RecordConfig serializableExtra = intent.getSerializableExtra("EXTRA_AV_RECORD_CONFIG");
            if (booleanExtra) {
                LSI.LIZJ = true;
            }
            AVExternalServiceImpl.LIZ().asyncService(LIZJ, "from_3rd_platform", new C5990FEk(LIZJ, serializableExtra));
        }
    }

    private boolean LIZIZ(Intent intent, boolean z) {
        boolean z2;
        M12.LIZ(intent);
        2kf.LIZ(3, (String) null, "ProcessPublish tryProcessPublish isOnCreate:".concat(String.valueOf(z)));
        if (z) {
            Activity[] activityStack = ActivityStack.getActivityStack();
            MainBusinessAbility LIZJ = EMX.LIZJ(EMX.LIZ((CuL) this), MainBusinessAbility.class);
            for (Activity activity : activityStack) {
                if (!LIZJ.LIZ(activity)) {
                    activity.finish();
                    z2 = true;
                } else {
                    z2 = false;
                }
                2kf.LIZIZ(3, (String) null, "ProcessPublish finishActivity isFinish:" + z2 + " activity:" + activity.getClass().getName());
            }
        }
        2kf.LIZIZ(3, (String) null, "MainActivity.onNewIntent()" + LIZIZ(intent) + " isOnCreate:" + z);
        2UX r4 = new 2UX();
        StringBuilder sb = new StringBuilder("MainActivity.onNewIntent()");
        sb.append(LIZIZ(intent));
        r4.LIZ("log", sb.toString());
        r4.LIZ("isOnCreate", Boolean.valueOf(z));
        2nK.LIZ("av_video_memory", r4.LIZ);
        1hK LIZJ2 = EMX.LIZJ(this);
        if (LIZJ2 == null) {
            return true;
        }
        boolean processPublish = AVExternalServiceImpl.LIZ().publishService().processPublish(LIZJ2, intent);
        Publish.isInPublish = processPublish;
        if (!processPublish) {
            return false;
        }
        if (intent.hasExtra("com.ss.android.ugc.aweme.intent.extra.EXTRA_LIGHTENING_PUBLISH")) {
            if (intent.hasExtra("multi_publish_id")) {
                LIZ(true);
            }
            return true;
        }
        if (!intent.hasExtra("com.ss.android.ugc.aweme.intent.extra.EXTRA_AWEME_DRAFT")) {
            LIZ(false);
        }
        return true;
    }

    public final void LIZ(boolean z, boolean z2) {
        1hK LIZJ;
        FutureTask<2Pr> futureTask = this.LJII;
        if (futureTask != null) {
            futureTask.run();
        }
        if (z2 && (LIZJ = EMX.LIZJ(this)) != null && LIZJ.getIntent().getBooleanExtra("enter_record_from_other_platform", false) && !this.LJFF) {
            AVExternalServiceImpl.LIZ().publishService().tryRestorePublish(LIZJ, new C5957FDd(this, LIZJ));
        }
    }
}
