package com.ss.android.ugc.aweme.commercialize.widget;

import X.0CB;
import X.0CH;
import X.1hK;
import X.4CM;
import X.6Is;
import X.AiA;
import X.C2496Ktj;
import X.C2560Kul;
import X.C2640Kw3;
import X.C2643Kw6;
import X.C2646Kw9;
import X.C2649KwC;
import X.C2661KwO;
import X.C2684Kwl;
import X.D4I;
import X.M12;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.widget.FrameLayout;
import androidx.fragment.app.Fragment;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.ss.android.ugc.aweme.commercialize.profile.AbsAdProfileWidget;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import com.ss.android.ugc.aweme.feed.model.AwemeRawAd;
import kotlin.h.b.n;

public final class AdFakePopUpWebPageWidget extends AbsAdProfileWidget implements 6Is {
    public static final C2646Kw9 LJIILJJIL = new C2646Kw9((byte) 0);
    public C2640Kw3 LJIIIZ;
    public String LJIIJ;
    public long LJIIJJI;
    public Handler LJIIL = new Handler(Looper.getMainLooper());
    public boolean LJIILIIL;
    public final C2684Kwl LJIILL = new C2684Kwl(this);
    public final C2649KwC LJIILLIIL = new C2649KwC(this);
    public final C2643Kw6 LJIIZILJ = new C2643Kw6(this);

    static {
        Covode.recordClassIndex(60129);
    }

    public final void onStateChanged(0CH r1, 0CB r2) {
        super.onStateChanged(r1, r2);
    }

    public final void LIZ(boolean z) {
        1hK r10;
        1hK r1;
        Context context;
        AwemeRawAd awemeRawAd;
        int i;
        String aid;
        AwemeRawAd awemeRawAd2;
        AiA fakeAuthor;
        String str;
        String str2;
        AwemeRawAd awemeRawAd3;
        String str3;
        AwemeRawAd awemeRawAd4;
        Context context2;
        AwemeRawAd awemeRawAd5;
        AwemeRawAd awemeRawAd6;
        AwemeRawAd awemeRawAd7;
        MethodCollector.i(481);
        Boolean bool = null;
        if (z) {
            Fragment fragment = this.LJII;
            if (fragment != null) {
                r10 = fragment.getActivity();
            } else {
                r10 = null;
            }
            String str4 = "";
            if (r10 != null) {
                Aweme aweme = this.LIZ;
                if (aweme == null || (awemeRawAd7 = aweme.getAwemeRawAd()) == null) {
                    str = null;
                } else {
                    str = awemeRawAd7.getSource();
                }
                if (!TextUtils.isEmpty(str)) {
                    Aweme aweme2 = this.LIZ;
                    if (aweme2 == null || (awemeRawAd6 = aweme2.getAwemeRawAd()) == null) {
                        str2 = null;
                    } else {
                        str2 = awemeRawAd6.getSource();
                    }
                } else {
                    Aweme aweme3 = this.LIZ;
                    if (aweme3 == null || (awemeRawAd3 = aweme3.getAwemeRawAd()) == null || (str2 = awemeRawAd3.getWebTitle()) == null) {
                        str2 = str4;
                    }
                }
                C2646Kw9 kw9 = LJIILJJIL;
                D4I d4i = new D4I();
                Aweme aweme4 = this.LIZ;
                if (aweme4 == null || (awemeRawAd5 = aweme4.getAwemeRawAd()) == null || (str3 = awemeRawAd5.getWebUrl()) == null) {
                    str3 = str4;
                }
                d4i.LIZ(str3);
                d4i.LIZ(this.LJII);
                d4i.LIZ(4CM.LIZ());
                if (str2 == null) {
                    str2 = str4;
                }
                d4i.LIZIZ(str2);
                Aweme aweme5 = this.LIZ;
                Bundle bundle = new Bundle();
                Fragment fragment2 = this.LJII;
                if (!(fragment2 == null || (context2 = fragment2.getContext()) == null)) {
                    n.LIZIZ(context2, str4);
                    if (!(aweme5 == null || aweme5.getAwemeRawAd() == null)) {
                        C2496Ktj.LIZ(bundle, aweme5, context2);
                        C2496Ktj.LIZIZ(bundle, aweme5, context2);
                        C2496Ktj.LIZJ(bundle, aweme5, context2);
                        C2496Ktj.LIZ(bundle, context2);
                    }
                }
                d4i.LIZ(bundle);
                Aweme aweme6 = this.LIZ;
                if (aweme6 != null) {
                    awemeRawAd4 = aweme6.getAwemeRawAd();
                } else {
                    awemeRawAd4 = null;
                }
                d4i.LIZ(awemeRawAd4);
                C2661KwO LIZ = d4i.LIZ();
                C2643Kw6 kw6 = this.LJIIZILJ;
                C2684Kwl kwl = this.LJIILL;
                M12.LIZ((Object) r10, (Object) LIZ);
                C2640Kw3 LIZIZ = kw9.LIZIZ(r10);
                if (LIZIZ == null) {
                    LIZIZ = new C2640Kw3(r10, (byte) 0);
                    LIZIZ.setId(2131362022);
                    LIZIZ.setParams(LIZ);
                    LIZIZ.setMBehaviorCallback(kw6);
                    LIZIZ.setKeyDownCallBack(kwl);
                    FrameLayout LIZ2 = kw9.LIZ(r10);
                    if (LIZ2 != null) {
                        LIZ2.addView(LIZIZ);
                    }
                }
                this.LJIIIZ = LIZIZ;
                LIZIZ.setTitleBarCallback(this.LJIILLIIL);
            }
            this.LJIILIIL = false;
            this.LJIIJJI = 0;
            C2646Kw9 kw92 = LJIILJJIL;
            Fragment fragment3 = this.LJII;
            if (fragment3 != null) {
                r1 = fragment3.getActivity();
            } else {
                r1 = null;
            }
            C2560Kul kul = new C2560Kul();
            Fragment fragment4 = this.LJII;
            if (fragment4 != null) {
                context = fragment4.getContext();
            } else {
                context = null;
            }
            kul.LIZ(context);
            kul.LIZ(this.LIZ);
            Aweme aweme7 = this.LIZ;
            if (aweme7 != null) {
                awemeRawAd = aweme7.getAwemeRawAd();
            } else {
                awemeRawAd = null;
            }
            kul.LIZ(awemeRawAd);
            kul.LIZIZ(8);
            Aweme aweme8 = this.LIZ;
            if (!(aweme8 == null || (awemeRawAd2 = aweme8.getAwemeRawAd()) == null || (fakeAuthor = awemeRawAd2.getFakeAuthor()) == null)) {
                bool = fakeAuthor.getAutoShowWebview();
            }
            if (n.LIZ(bool, true)) {
                i = 5;
            } else {
                i = 4;
            }
            kul.LIZ(i);
            Aweme aweme9 = this.LIZ;
            if (!(aweme9 == null || (aid = aweme9.getAid()) == null)) {
                str4 = aid;
            }
            kul.LIZJ(str4);
            kw92.LIZ(r1, kul.LIZ());
            MethodCollector.o(481);
            return;
        }
        C2646Kw9 kw93 = LJIILJJIL;
        Fragment fragment5 = this.LJII;
        if (fragment5 != null) {
            bool = fragment5.getActivity();
        }
        C2640Kw3 LIZIZ2 = kw93.LIZIZ(bool);
        if (LIZIZ2 != null) {
            if (LIZIZ2.LJII()) {
                LIZIZ2.LIZ(true);
                FrameLayout LIZ3 = kw93.LIZ(bool);
                if (LIZ3 != null) {
                    LIZ3.setVisibility(8);
                    MethodCollector.o(481);
                    return;
                }
            }
            MethodCollector.o(481);
            return;
        }
        MethodCollector.o(481);
    }
}
