package com.bytedance.android.livesdk.lynx.ui;

import X.0HH;
import X.0ZY;
import X.0aP;
import X.0b0;
import X.0b2;
import X.0bM;
import X.0bV;
import X.0cm;
import X.1hK;
import X.1jk;
import X.2Pr;
import X.7lW;
import X.C1313Fz8;
import X.C1639GAm;
import X.C1751GEu;
import X.C5142Heh;
import X.C5228Hg5;
import X.C5230Hg7;
import X.C5237HgE;
import X.C5244HgL;
import X.C5266Hgh;
import X.C5270Hgl;
import X.C5311HhQ;
import X.C5316HhV;
import X.C5323Hhc;
import X.C5329Hhi;
import X.C5336Hhp;
import X.C5402Hit;
import X.C5467Hjw;
import X.Juq;
import X.JvF;
import X.KMV;
import X.M12;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.FrameLayout;
import com.bytedance.android.live.actionhandler.IActionHandlerService;
import com.bytedance.android.livesdk.livesetting.hybrid.EnableLynxDebugBadgeSetting;
import com.bytedance.android.livesdk.lynx.ILiveLynxService;
import com.bytedance.android.livesdkapi.host.IHostContext;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import java.util.HashMap;
import kotlin.h.b.n;
import org.json.JSONObject;

public final class TTLiveLynxFragment extends AbsHybridFragment implements C5467Hjw {
    public static final C5316HhV LJIILL = new C5316HhV((byte) 0);
    public boolean LIZ;
    public boolean LIZIZ;
    public boolean LIZJ = true;
    public C5329Hhi LIZLLL;
    public View LJ;
    public ILiveLynxService LJFF;
    public String LJI = "";
    public int LJII;
    public Integer LJIIIIZZ;
    public String LJIIIZ;
    public boolean LJIIJ;
    public String LJIIJJI = "";
    public boolean LJIIL;
    public boolean LJIILIIL;
    public C5402Hit LJIILJJIL;
    public HashMap LJIILLIIL;

    static {
        Covode.recordClassIndex(18656);
    }

    public final void LJIIIIZZ() {
        HashMap hashMap = this.LJIILLIIL;
        if (hashMap != null) {
            hashMap.clear();
        }
    }

    public final /* synthetic */ void onDestroyView() {
        super.onDestroyView();
        LJIIIIZZ();
    }

    public final View LJFF() {
        C5329Hhi hhi = this.LIZLLL;
        if (hhi != null) {
            return hhi.LIZLLL();
        }
        return null;
    }

    public final void onDestroy() {
        super.onDestroy();
        0bV.LIZ(new C5244HgL(this));
    }

    public final void onDetach() {
        TTLiveLynxFragment.super.onDetach();
        0aP.LIZ(4, "LiveLynx.LiveLynxFragment", "onDetach()");
    }

    public TTLiveLynxFragment() {
        boolean z = true;
        IHostContext LIZ2 = 0cm.LIZ(IHostContext.class);
        this.LIZ = (LIZ2 == null || !LIZ2.isLocalTest() || !EnableLynxDebugBadgeSetting.INSTANCE.getValue()) ? false : z;
        this.LJFF = 0cm.LIZ(ILiveLynxService.class);
        this.LJJIJLIJ = C5142Heh.LIZIZ();
    }

    public final void onPause() {
        super.onPause();
        try {
            LIZ("container_disappear", new JSONObject());
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("type", "app");
            jSONObject.put("args", new JSONObject().put("foreground", false));
            LIZ("H5_appStateChange", jSONObject);
        } catch (Exception e) {
            0HH.LIZ(e);
        }
    }

    public final void onResume() {
        super.onResume();
        0aP.LIZ(4, "LiveLynx.LiveLynxFragment", "onResume()");
        try {
            LIZ("container_appear", new JSONObject());
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("type", "app");
            jSONObject.put("args", new JSONObject().put("foreground", true));
            LIZ("H5_appStateChange", jSONObject);
        } catch (Exception e) {
            0HH.LIZ(e);
        }
    }

    public final void LIZ() {
        String string;
        2Pr valueOf;
        Bundle arguments = getArguments();
        if (!(arguments == null || (string = arguments.getString("fallback_url")) == null)) {
            n.LIZIZ(string, "");
            if (string.length() > 0) {
                Context context = null;
                if (1 != 0) {
                    C5323Hhc hhc = this.LJJIJIIJIL;
                    if (hhc != null) {
                        hhc.LIZIZ();
                    }
                    if (this.LJIILIIL) {
                        1hK activity = getActivity();
                        if (activity != null) {
                            activity.finish();
                        }
                        if (this.LJJIJIL != null) {
                            0ZY r0 = this.LJJIJIL;
                            if (r0 != null) {
                                r0.LIZ(string);
                                valueOf = 2Pr.LIZ;
                            }
                        } else {
                            IActionHandlerService LIZ2 = 0cm.LIZ(IActionHandlerService.class);
                            Context context2 = getContext();
                            if (context2 != null) {
                                context = context2.getApplicationContext();
                                if (7lW.LIZJ && context == null) {
                                    context = 7lW.LIZ;
                                }
                            }
                            valueOf = Boolean.valueOf(LIZ2.handle(context, string));
                        }
                    } else if (this.LJJIJIL != null) {
                        0ZY r02 = this.LJJIJIL;
                        if (r02 != null) {
                            r02.LIZ(string);
                            valueOf = 2Pr.LIZ;
                        }
                    } else {
                        valueOf = Boolean.valueOf(0cm.LIZ(IActionHandlerService.class).handle(getContext(), string));
                    }
                    if (valueOf != null) {
                        return;
                    }
                }
            }
        }
        if (this.LIZ) {
            C1313Fz8.LIZ(0b0.LJ(), "Lynx fallback with no fallback_url!!", 0);
        }
    }

    public final void LIZ(View view) {
        M12.LIZ(view);
        View view2 = this.LJ;
        if (view2 != null) {
            view2.setVisibility(8);
        }
    }

    public final void onAttach(Context context) {
        TTLiveLynxFragment.super.onAttach(context);
        0aP.LIZ(4, "LiveLynx.LiveLynxFragment", "onAttach()");
    }

    public final boolean LIZ(String str) {
        M12.LIZ(str);
        super.LIZ(str);
        C5336Hhp hhp = this.LJJIZ;
        if (hhp != null) {
            return hhp.LIZ();
        }
        return false;
    }

    public final void onCreate(Bundle bundle) {
        boolean z;
        String str;
        String queryParameter;
        super.onCreate(bundle);
        Bundle arguments = getArguments();
        if (arguments != null) {
            String string = arguments.getString("url", "");
            n.LIZIZ(string, "");
            this.LJI = string;
            if (!TextUtils.isEmpty(string)) {
                Uri parse = Uri.parse(this.LJI);
                this.LJIIL = arguments.getBoolean("hide_status_bar", false);
                this.LJIIJ = arguments.getBoolean("is_fullscreen", false);
                this.LJIIJJI = arguments.getString("title");
                this.LJIIIIZZ = Integer.valueOf(arguments.getInt("bundle_preset_width"));
                this.LJIIIZ = arguments.getString("original_scheme", "");
                this.LJIILIIL = arguments.getBoolean("is_dummy_host", false);
                String string2 = arguments.getString("soft_input_mode", "");
                n.LIZIZ(string2, "");
                this.LJJIL = string2;
                String str2 = null;
                if (parse != null) {
                    try {
                        str = parse.getQueryParameter("web_bg_color");
                    } catch (Exception e) {
                        0HH.LIZ(e);
                    }
                } else {
                    str = null;
                }
                if (!TextUtils.isEmpty(str) && (queryParameter = parse.getQueryParameter("web_bg_color")) != null) {
                    this.LJII = Color.parseColor(C1639GAm.LIZ(queryParameter));
                }
                if (parse != null) {
                    try {
                        boolean z2 = true;
                        if (parse.getQueryParameter("hide_loading") != null) {
                            if (C1751GEu.LIZIZ(parse.getQueryParameter("hide_loading")) == 1) {
                                z = true;
                            } else {
                                z = false;
                            }
                            this.LIZIZ = z;
                        } else if (parse != null) {
                        }
                        if (parse.getQueryParameter("hide_status_bar") != null) {
                            String queryParameter2 = parse.getQueryParameter("hide_status_bar");
                            if (queryParameter2 == null) {
                                n.LIZIZ();
                            }
                            n.LIZIZ(queryParameter2, "");
                            if (Integer.parseInt(queryParameter2) != 1) {
                                z2 = false;
                            }
                            this.LJIIL = z2;
                        } else if (parse != null) {
                        }
                        str2 = parse.getQueryParameter("title");
                    } catch (Exception e2) {
                        0HH.LIZ(e2);
                    }
                }
                if (!TextUtils.isEmpty(str2)) {
                    this.LJIIJJI = parse.getQueryParameter("title");
                }
            }
        }
        if (this.LJIIL && this.LJIIJ) {
            if (0bM.LIZ(getActivity())) {
                1hK activity = getActivity();
                if (activity != null) {
                    Window window = activity.getWindow();
                    window.clearFlags(67108864);
                    window.getDecorView().setSystemUiVisibility(1280);
                    window.addFlags(Integer.MIN_VALUE);
                    window.setStatusBarColor(0);
                    return;
                }
                return;
            }
            0b2.LIZ(getActivity());
        }
    }

    public final <T> void LIZ(String str, T t) {
        C5329Hhi hhi = this.LIZLLL;
        if (hhi != null) {
            hhi.LIZ(str, t);
        }
    }

    public final void onActivityResult(int i, int i2, Intent intent) {
        TTLiveLynxFragment.super.onActivityResult(i, i2, intent);
        C5402Hit hit = this.LJIILJJIL;
        if (hit != null) {
            hit.LIZ(i, i2, intent);
        }
    }

    public final View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        MethodCollector.i(7235);
        LayoutInflater layoutInflater2 = layoutInflater;
        M12.LIZ(layoutInflater2);
        View LIZ2 = 0HH.LIZ(layoutInflater2, 2131561961, viewGroup, false);
        if (LIZ2 != null) {
            FrameLayout frameLayout = (FrameLayout) LIZ2;
            View findViewById = frameLayout.findViewById(2131367203);
            this.LJ = findViewById;
            if (this.LIZIZ) {
                if (findViewById != null) {
                    findViewById.setVisibility(8);
                }
            } else if (findViewById != null) {
                findViewById.setVisibility(0);
            }
            ILiveLynxService iLiveLynxService = this.LJFF;
            if (iLiveLynxService == null) {
                n.LIZIZ();
            }
            1hK activity = getActivity();
            if (activity == null) {
                n.LIZIZ();
            }
            n.LIZIZ(activity, "");
            C5329Hhi createAndLoad = iLiveLynxService.createAndLoad(activity, this.LJI, this.LJIIIIZZ, this.LJIIIZ, this.LJJIJLIJ, this);
            if (createAndLoad != null) {
                JvF.LIZJ.LIZ(this.LJJJ, new Juq(createAndLoad.LIZLLL(), "lynx"));
                View LIZLLL2 = createAndLoad.LIZLLL();
                LIZLLL2.setScrollBarStyle(0);
                LIZLLL2.setBackgroundColor(this.LJII);
                frameLayout.addView(LIZLLL2, 0, new FrameLayout.LayoutParams(-1, -1));
                C5311HhQ hhQ = this.LJJIJIIJI;
                if (hhQ != null) {
                    hhQ.LIZ(createAndLoad.LIZIZ());
                }
                C5266Hgh LIZIZ2 = createAndLoad.LIZIZ();
                C5228Hg5 hg5 = new C5228Hg5();
                this.LJJIZ = hg5;
                KMV LIZ3 = LIZIZ2.LIZ();
                if (LIZ3 != null) {
                    LIZ3.LIZ("viewController", hg5);
                }
                KMV LIZ4 = LIZIZ2.LIZ();
                if (LIZ4 != null) {
                    LIZ4.LIZ("chooseImage", new C5237HgE(this));
                }
                this.LIZLLL = createAndLoad;
                if (this.LIZ) {
                    C5230Hg7 hg7 = new C5230Hg7(this);
                    1jk r3 = new 1jk(getContext());
                    r3.setText("Lynx");
                    r3.setTextSize(14.0f);
                    r3.setTextColor(Color.parseColor("#FFFFFF"));
                    r3.setBackgroundColor(Color.parseColor("#88008800"));
                    r3.setOnClickListener(new C5270Hgl(hg7));
                    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-2, -2);
                    layoutParams.gravity = 8388661;
                    frameLayout.addView(r3, layoutParams);
                }
                MethodCollector.o(7235);
                return frameLayout;
            }
            LIZ();
            MethodCollector.o(7235);
            return frameLayout;
        }
        NullPointerException nullPointerException = new NullPointerException("null cannot be cast to non-null type android.widget.FrameLayout");
        MethodCollector.o(7235);
        throw nullPointerException;
    }
}
