package com.ss.android.ugc.aweme.specact.touchpoints.pendant;

import X.0CB;
import X.0CD;
import X.0CH;
import X.0CN;
import X.2UX;
import X.2nK;
import X.2rI;
import X.6Is;
import X.7he;
import X.8bz;
import X.9EH;
import X.C2797S9p;
import X.C2990SHa;
import X.C2999SHj;
import X.C3001SHl;
import X.C3002SHm;
import X.C3009SHt;
import X.Crj;
import X.M12;
import X.SGS;
import X.SH6;
import X.SHE;
import X.SHG;
import X.SHK;
import X.SIP;
import X.SIS;
import android.app.Activity;
import android.content.Context;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import com.ss.android.ugc.aweme.local_test.LocalTestApi;
import java.util.Objects;
import kotlin.h.b.n;

public abstract class BasePendantManager implements 6Is, SGS, SIP {
    public static final C3009SHt LJII = new C3009SHt((byte) 0);
    public C2990SHa LIZ;
    public boolean LIZIZ;
    public boolean LIZJ;
    public ViewGroup LIZLLL;
    public 0CH LJ;
    public Aweme LJFF;
    public String LJI = "ForYou";
    public boolean LJIIIIZZ;
    public final Crj LJIIIZ = 7he.LIZ(new C3001SHl(this));
    public final Crj LJIIJ = 7he.LIZ(new C2999SHj(this));

    static {
        Covode.recordClassIndex(115237);
    }

    public final SHE LIZ() {
        return (SHE) this.LJIIIZ.getValue();
    }

    public final C3002SHm LIZIZ() {
        return (C3002SHm) this.LJIIJ.getValue();
    }

    public boolean LJ() {
        return true;
    }

    public abstract SHE LJIIJJI();

    public abstract C3002SHm LJIIL();

    public abstract void LJIILIIL();

    public abstract void LJIILJJIL();

    public void onStateChanged(0CH r2, 0CB r3) {
        if (r3 == 0CB.ON_DESTROY) {
            onDestory();
        }
    }

    public void LJII() {
        LJFF();
    }

    private boolean LJIJ() {
        return LIZ().LIZ();
    }

    public final boolean LIZLLL() {
        if (this.LJ == null || this.LIZLLL == null) {
            return false;
        }
        return true;
    }

    public final void LJFF() {
        if (LJIJ()) {
            LIZ().LIZIZ();
        }
    }

    public final void LJI() {
        if (this.LIZ != null) {
            LJII();
            this.LIZ = null;
        }
    }

    public final void LJIIIIZZ() {
        if (!LJIJ()) {
            LIZJ();
        }
    }

    @0CN(LIZ = 0CB.ON_DESTROY)
    public void onDestory() {
        LJIIJ();
        LJFF();
        this.LIZLLL = null;
    }

    private boolean LJIILL() {
        if (this.LIZ == null) {
            return false;
        }
        SIS sis = SIS.LIZ;
        C2990SHa sHa = this.LIZ;
        if (sHa == null) {
            n.LIZIZ();
        }
        if (sis.LIZ(sHa)) {
            return false;
        }
        return true;
    }

    private void LJIIZILJ() {
        if (LJIILL()) {
            C3002SHm LIZIZ2 = LIZIZ();
            Context LJIIIZ2 = LJIIIZ();
            C2990SHa sHa = this.LIZ;
            if (sHa == null) {
                n.LIZIZ();
            }
            LIZIZ2.LIZ(LJIIIZ2, sHa);
        }
    }

    public final void LJIIJ() {
        0CD lifecycle;
        0CH r0 = this.LJ;
        if (!(r0 == null || (lifecycle = r0.getLifecycle()) == null)) {
            lifecycle.LIZIZ(this);
        }
        this.LJ = null;
    }

    private boolean LJIILLIIL() {
        String str;
        SHK shk;
        if (!LJIILL()) {
            return false;
        }
        if (!LJ()) {
            return true;
        }
        C3002SHm LIZIZ2 = LIZIZ();
        C2990SHa sHa = this.LIZ;
        if (sHa == null || (shk = sHa.LIZIZ) == null || (str = shk.LJ) == null) {
            str = "";
        }
        return LIZIZ2.LIZ(str);
    }

    public final Context LJIIIZ() {
        Context LIZ2;
        Fragment fragment = this.LJ;
        if (fragment instanceof Activity) {
            Objects.requireNonNull(fragment, "null cannot be cast to non-null type android.content.Context");
            LIZ2 = (Context) fragment;
        } else if (fragment instanceof Fragment) {
            Objects.requireNonNull(fragment, "null cannot be cast to non-null type androidx.fragment.app.Fragment");
            LIZ2 = fragment.getContext();
        } else {
            LIZ2 = 9EH.LJJIFFI.LIZ();
        }
        if (LIZ2 == null) {
            return 9EH.LJJIFFI.LIZ();
        }
        return LIZ2;
    }

    public final void LIZJ() {
        if (!LJIILL()) {
            LocalTestApi localTestApi = 2rI.LIZ.LIZ;
            n.LIZIZ(localTestApi, "");
            localTestApi.getSpecActDebugService().LIZ("SpecPendant", "init pendant error: setting is not ready");
        } else if (!LIZLLL()) {
            LocalTestApi localTestApi2 = 2rI.LIZ.LIZ;
            n.LIZIZ(localTestApi2, "");
            localTestApi2.getSpecActDebugService().LIZ("SpecPendant", "init pendant error: page is not ready");
        } else {
            C2990SHa sHa = this.LIZ;
            SHG shg = null;
            if (sHa != null) {
                shg = sHa.LIZ;
            }
            if (shg != null) {
                this.LJIIIIZZ = true;
            }
            C2990SHa sHa2 = this.LIZ;
            if (!(sHa2 == null || sHa2.LIZIZ == null)) {
                this.LIZIZ = true;
            }
            if (!LJIILLIIL()) {
                LocalTestApi localTestApi3 = 2rI.LIZ.LIZ;
                n.LIZIZ(localTestApi3, "");
                localTestApi3.getSpecActDebugService().LIZ("SpecPendant", "init pendant error: resource is not ready");
                LJIIZILJ();
                return;
            }
            ViewGroup viewGroup = this.LIZLLL;
            if (viewGroup == null) {
                n.LIZIZ();
            }
            LIZ(viewGroup);
            C2797S9p.LIZ.LIZ(6);
            LIZ(this.LIZ);
            LJIILJJIL();
        }
    }

    private void LIZ(ViewGroup viewGroup) {
        M12.LIZ(viewGroup);
        if (!LJIJ()) {
            LIZ().LIZ(viewGroup);
            LIZ().LIZ(this.LIZ);
            LIZ().LIZLLL(this.LJI);
            LJIILIIL();
        }
    }

    public final void LIZ(C2990SHa sHa, boolean z) {
        this.LIZJ = z;
        SH6 sh6 = SH6.LIZ;
        if (sHa != null && (!(sHa.LIZ == null && sHa.LIZIZ == null) && sh6.LJIIIZ(sHa) && sh6.LJIIIIZZ(sHa))) {
            2UX r2 = new 2UX();
            r2.LIZ("is_login", 8bz.LIZ.LIZ() ? 1 : 0);
            2nK.LIZ("efficient_pendant_data_distribute", r2.LIZ);
            C2797S9p.LIZ.LIZ(5);
        }
        if (LJIILL()) {
            LJI();
        }
        this.LIZ = sHa;
        LIZJ();
    }
}
