package com.ss.android.ugc.aweme.commercialize.views.cards;

import X.0CH;
import X.0HH;
import X.1hK;
import X.2ha;
import X.3F7;
import X.6iy;
import X.7Xz;
import X.7he;
import X.9EH;
import X.9Fh;
import X.Bi2;
import X.C1022KQj;
import X.C1281Ka8;
import X.C1282Ka9;
import X.C1311Kac;
import X.C1603KfK;
import X.C1989KlY;
import X.C2007Klq;
import X.C2051KmY;
import X.C2080Kn1;
import X.C2126Knl;
import X.C2189Kom;
import X.C2214KpB;
import X.C2218KpF;
import X.C2226KpN;
import X.C2227KpO;
import X.C2228KpP;
import X.C2229KpQ;
import X.C2230KpR;
import X.C2231KpS;
import X.C2232KpT;
import X.C2233KpU;
import X.C2333Kr6;
import X.Crj;
import X.KQA;
import X.LJ0;
import X.LRV;
import X.M12;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.widget.ImageView;
import androidx.fragment.app.Fragment;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.bullet.ui.common.BulletActivityWrapper;
import com.bytedance.ies.uikit.base.AbsFragment;
import com.ss.android.ugc.aweme.commercialize.abtest.CommerceAdLandpageBulletConfig;
import com.ss.android.ugc.aweme.commercialize.utils.CommercializeWebViewHelper;
import com.ss.android.ugc.aweme.crossplatform.platform.webview.SingleWebChromeClient;
import com.ss.android.ugc.aweme.legoImp.inflate.X2CBaseInflate;
import java.util.Map;
import java.util.Objects;
import kotlin.h.b.n;
import kotlin.o.z;

public final class AdHalfWebPageFragmentV2 extends AbsFragment implements LJ0 {
    public static final C2226KpN LIZJ = new C2226KpN((byte) 0);
    public int LIZ;
    public C2233KpU LIZIZ;
    public boolean LIZLLL;
    public final Crj LJ;
    public final Crj LJIIIZ;
    public final Crj LJIIJ;
    public final Crj LJIIJJI;
    public String LJIIL;
    public final C1282Ka9 LJIILIIL;
    public final C1281Ka8 LJIILJJIL;
    public SparseArray LJIILL;

    static {
        Covode.recordClassIndex(59973);
    }

    private final C2080Kn1 LJFF() {
        return (C2080Kn1) this.LJ.getValue();
    }

    private final View LJI() {
        return (View) this.LJIIJ.getValue();
    }

    private final ImageView LJII() {
        return (ImageView) this.LJIIJJI.getValue();
    }

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

    public final View LIZIZ(int i) {
        if (this.LJIILL == null) {
            this.LJIILL = new SparseArray();
        }
        View view = (View) this.LJIILL.get(i);
        if (view != null) {
            return view;
        }
        View view2 = getView();
        if (view2 == null) {
            return null;
        }
        View findViewById = view2.findViewById(i);
        this.LJIILL.put(i, findViewById);
        return findViewById;
    }

    public final 0CH LIZIZ() {
        return this;
    }

    public final Fragment LIZJ() {
        return this;
    }

    public final /* synthetic */ void onDestroyView() {
        super.onDestroyView();
        SparseArray sparseArray = this.LJIILL;
        if (sparseArray != null) {
            sparseArray.clear();
        }
    }

    /* JADX WARNING: type inference failed for: r0v2, types: [android.view.View, X.KmY] */
    /* JADX WARNING: type inference failed for: r0v4, types: [X.Kac, android.view.View] */
    public final View LIZLLL() {
        if (this.LIZLLL) {
            return LIZ().getWebView();
        }
        return LIZ(LJFF());
    }

    public final boolean LJ() {
        if (this.LIZLLL) {
            C1281Ka8 ka8 = this.LJIILJJIL;
            if (!ka8.LIZ || ka8.LIZIZ) {
                return false;
            }
            return true;
        }
        C1282Ka9 ka9 = this.LJIILIIL;
        if (!ka9.LIZ || ka9.LIZIZ) {
            return false;
        }
        return true;
    }

    public AdHalfWebPageFragmentV2() {
        CommerceAdLandpageBulletConfig LIZJ2 = C2218KpF.LIZIZ.LIZJ();
        boolean z = false;
        if (LIZJ2 != null && LIZJ2.getTotalEnable()) {
            z = LIZJ2.getAdLandpageCardEnable();
        }
        this.LIZLLL = z;
        this.LJ = 7he.LIZ(new C2232KpT(this));
        this.LJIIIZ = 7he.LIZ(new C2230KpR(this));
        this.LJIIJ = 7he.LIZ(new C2227KpO(this));
        this.LJIIJJI = 7he.LIZ(new C2231KpS(this));
        this.LIZ = 2131232742;
        this.LJIIL = "";
        this.LJIILIIL = new C1282Ka9();
        this.LJIILJJIL = new C1281Ka8();
    }

    public final void LIZ(int i) {
        if (i != 0) {
            this.LIZ = i;
        }
    }

    private final C2051KmY LIZ(C2080Kn1 kn1) {
        C2051KmY LIZ2 = kn1.LIZ(C2333Kr6.class).LIZ();
        n.LIZIZ(LIZ2, "");
        return LIZ2;
    }

    public final void LIZIZ(boolean z) {
        if (aq_()) {
            if (this.LIZLLL) {
                LIZ().setCanScrollVertically(z);
            } else {
                LIZ(LJFF()).setCanScrollVertically(z);
            }
        }
    }

    public final void LIZ(C2233KpU kpU) {
        M12.LIZ((Object) kpU);
        this.LIZIZ = kpU;
    }

    public final void onCreate(Bundle bundle) {
        String string;
        super.onCreate(bundle);
        Bundle arguments = getArguments();
        String str = "";
        if (!(arguments == null || (string = arguments.getString("url", str)) == null)) {
            Objects.requireNonNull(string, "null cannot be cast to non-null type kotlin.CharSequence");
            String obj = z.LIZIZ(string).toString();
            if (obj != null) {
                str = obj;
            }
        }
        this.LJIIL = str;
    }

    public final void LIZ(String str) {
        if (TextUtils.isEmpty(str) || str == null) {
            return;
        }
        if (this.LIZLLL) {
            C1311Kac webView = LIZ().getWebView();
            if (webView != null) {
                webView.loadUrl(str);
                return;
            }
            return;
        }
        LIZ(LJFF()).loadUrl(str);
    }

    public final void LIZ(boolean z) {
        if (aq_()) {
            if (z) {
                LJI().setVisibility(8);
            } else {
                LJI().setVisibility(0);
            }
        }
    }

    public final void onViewCreated(View view, Bundle bundle) {
        C2126Knl knl;
        M12.LIZ((Object) view);
        super.onViewCreated(view, bundle);
        if (this.LIZLLL) {
            1hK activity = getActivity();
            if (activity != null) {
                C1989KlY LIZ2 = LIZ();
                KQA LIZ3 = Bi2.LIZ().LIZ();
                C1281Ka8 ka8 = this.LJIILJJIL;
                n.LIZIZ(activity, "");
                LIZ2.LIZ(LIZ3, ka8, new BulletActivityWrapper(activity), this, "ad_commerce");
            }
            C2214KpB rootContainer = LIZ().getRootContainer();
            if (!(rootContainer == null || (knl = rootContainer.LJJI) == null)) {
                knl.LIZLLL();
            }
        } else {
            1hK activity2 = getActivity();
            if (activity2 != null) {
                CommercializeWebViewHelper.LIZ(LJFF(), this.LJIILIIL, this, activity2, getArguments());
            }
            LIZ(LJFF()).setEnableScrollControl(true);
            LIZ(LJFF()).setCanScrollVertically(false);
            WebSettings settings = LIZ(LJFF()).getSettings();
            n.LIZIZ(settings, "");
            settings.setTextZoom(100);
            SingleWebChromeClient singleWebChromeClient = LIZ(LJFF()).getSingleWebChromeClient();
            if (singleWebChromeClient != null) {
                singleWebChromeClient.LIZJ = false;
            }
        }
        LJI().setOnClickListener(new C2228KpP(this));
        LJII().setImageResource(this.LIZ);
        int i = this.LIZ;
        if (i == 2131231882) {
            LJII().setPadding(2ha.LIZ(12.0d), 2ha.LIZ(4.0d), 2ha.LIZ(4.0d), 2ha.LIZ(7.0d));
        } else if (i == 2131232743) {
            ViewGroup.LayoutParams layoutParams = LJII().getLayoutParams();
            layoutParams.width = 2ha.LIZ(28.0d);
            layoutParams.height = 2ha.LIZ(28.0d);
            LJII().setLayoutParams(layoutParams);
            LJII().setPadding(2ha.LIZ(8.0d), 2ha.LIZ(10.0d), 2ha.LIZ(8.0d), 2ha.LIZ(6.0d));
        } else if (i == 2131232745) {
            Drawable drawable = getResources().getDrawable(i);
            if (drawable != null) {
                drawable.setAutoMirrored(true);
            }
            n.LIZIZ(drawable, "");
            if (drawable != null && 3F7.LIZ(getContext())) {
                LJII().setImageDrawable(drawable);
            }
            ViewGroup.LayoutParams layoutParams2 = LJII().getLayoutParams();
            int LIZ4 = 2ha.LIZ(40.0d);
            layoutParams2.width = LIZ4;
            layoutParams2.height = LIZ4;
            LJII().setPadding(0, 0, 0, 0);
        } else if (i == 2131232744) {
            ImageView LJII = LJII();
            LJII.getLayoutParams().width = 2ha.LIZ(36.0d);
            LJII.getLayoutParams().height = 2ha.LIZ(36.0d);
            int LIZ5 = 2ha.LIZ(12.0d);
            LJII.setPadding(LIZ5, LIZ5, LIZ5, LIZ5);
        }
        LJII().setOnClickListener(new C2229KpQ(this));
        LRV.LIZ(LJII());
        if (this.LIZLLL) {
            LIZ().setVisibility(0);
            LJFF().setVisibility(8);
            LIZ().LIZ(C1022KQj.LIZ(this.LJIIL, 6iy.LIZ("ad_commerce"), getArguments(), new C2189Kom(9EH.LJJIFFI.LIZ())), getArguments(), (C1603KfK) new C2007Klq(this));
            LIZ().setEnableScrollControl(true);
            LIZ().setCanScrollVertically(false);
            return;
        }
        C2080Kn1.LIZ(LJFF(), this.LJIIL, false, (Map) null, false, 14);
    }

    public final View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        M12.LIZ((Object) layoutInflater);
        if (!7Xz.LIZIZ || this.LIZLLL) {
            return 0HH.LIZ(layoutInflater, 2131559720, viewGroup, false);
        }
        return ((X2CBaseInflate) 9Fh.LJIILIIL.LIZIZ(X2CAdWebPage.class)).LIZ(getContext());
    }
}
