package com.ss.android.ugc.aweme.homepage.msadapt;

import X.0CC;
import X.0CD;
import X.1hK;
import X.3er;
import X.8Ze;
import X.C4566Ej4;
import X.F7N;
import X.F7P;
import X.Lnj;
import X.M12;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.router.SmartRouter;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import com.ss.android.ugc.aweme.homepage.api.msadapt.IMSAdaptionService;
import com.ss.android.ugc.aweme.login.LoginUtilsServiceImpl;
import com.ss.android.ugc.aweme.main.TabChangeManager;
import com.ss.android.ugc.aweme.main.page.AwemeChangeCallBack;
import com.ss.android.ugc.aweme.requesttask.idle.ReportActivityStatusTask;
import java.lang.ref.WeakReference;
import kotlin.h.b.n;

public final class MSAdaptionService implements IMSAdaptionService {
    public WeakReference<Fragment> LIZIZ;
    public Aweme LIZJ;

    static {
        Covode.recordClassIndex(83109);
    }

    public final Aweme LIZIZ() {
        return this.LIZJ;
    }

    public final Fragment LIZ() {
        WeakReference<Fragment> weakReference = this.LIZIZ;
        if (weakReference != null) {
            return (Fragment) weakReference.get();
        }
        return null;
    }

    public static IMSAdaptionService LIZJ() {
        MethodCollector.i(3486);
        IMSAdaptionService iMSAdaptionService = (IMSAdaptionService) Lnj.LIZ(IMSAdaptionService.class, false);
        if (iMSAdaptionService != null) {
            MethodCollector.o(3486);
            return iMSAdaptionService;
        }
        Object LIZIZ2 = Lnj.LIZIZ(IMSAdaptionService.class, false);
        if (LIZIZ2 != null) {
            IMSAdaptionService iMSAdaptionService2 = (IMSAdaptionService) LIZIZ2;
            MethodCollector.o(3486);
            return iMSAdaptionService2;
        }
        if (Lnj.LLLIIII == null) {
            synchronized (IMSAdaptionService.class) {
                try {
                    if (Lnj.LLLIIII == null) {
                        Lnj.LLLIIII = new MSAdaptionService();
                    }
                } catch (Throwable th) {
                    MethodCollector.o(3486);
                    throw th;
                }
            }
        }
        MSAdaptionService mSAdaptionService = (MSAdaptionService) Lnj.LLLIIII;
        MethodCollector.o(3486);
        return mSAdaptionService;
    }

    public final void LIZ(Aweme aweme) {
        M12.LIZ(aweme);
        this.LIZJ = aweme;
    }

    public final C4566Ej4 LIZ(Activity activity) {
        C4566Ej4 ej4 = null;
        if (activity == null) {
            return null;
        }
        3er r1 = TabChangeManager.LJII;
        if (!(activity instanceof 1hK)) {
            activity = null;
        }
        C4566Ej4 LIZ = r1.LIZ((1hK) activity).LIZ();
        if (LIZ instanceof C4566Ej4) {
            ej4 = LIZ;
        }
        return ej4;
    }

    public final void LIZIZ(1hK r2) {
        M12.LIZ(r2);
        if (LIZJ((Context) r2)) {
            SmartRouter.buildRoute(r2, "//duo").open();
            r2.finish();
        }
    }

    public final boolean LIZIZ(Context context) {
        if (context != null && LIZ(context)) {
            return F7N.LIZIZ.LIZLLL(context);
        }
        return false;
    }

    public final void LIZJ(1hK r3) {
        M12.LIZ(r3);
        0CD lifecycle = r3.getLifecycle();
        n.LIZIZ(lifecycle, "");
        if (lifecycle.LIZ().isAtLeast(0CC.RESUMED)) {
            LIZIZ(r3);
            int LJ = F7N.LIZIZ.LJ(r3);
            if (!LIZIZ((Context) r3)) {
                return;
            }
            if (LJ == 3 || LJ == 1) {
                LoginUtilsServiceImpl.LIZ().LIZ(new Bundle());
            }
        }
    }

    public final void LIZ(1hK r2) {
        M12.LIZ(r2);
        if (LIZ((Context) r2)) {
            AwemeChangeCallBack.LIZ(r2, r2, new F7P(this));
            r2.setRequestedOrientation(-1);
        }
    }

    public final void LIZ(Fragment fragment) {
        if (fragment != null) {
            this.LIZIZ = new WeakReference<>(fragment);
        }
    }

    public final boolean LIZJ(Context context) {
        boolean z;
        if (context == null) {
            return false;
        }
        boolean LIZIZ2 = LIZIZ(context);
        Resources resources = context.getResources();
        n.LIZIZ(resources, "");
        if (resources.getConfiguration().orientation == 2) {
            z = true;
        } else {
            z = false;
        }
        if (!LIZIZ2 || !z) {
            return false;
        }
        return true;
    }

    public final boolean LIZ(Context context) {
        if (context == null) {
            return false;
        }
        return F7N.LIZIZ.LIZIZ(context);
    }

    public final 8Ze LIZ(String str, Bundle bundle) {
        M12.LIZ(str);
        return new ReportActivityStatusTask(str, bundle);
    }
}
