package com.bytedance.android.livesdk;

import X.0AA;
import X.0AP;
import X.0HH;
import X.0aP;
import X.3Ww;
import X.C1044Fun;
import X.C1344Fzd;
import X.C2122GTb;
import X.C2306Ga3;
import X.C2307Ga4;
import X.C2308Ga5;
import X.C2310Ga7;
import X.C2311Ga8;
import X.C2670Gfv;
import X.GSF;
import X.M12;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import com.bytedance.android.livesdk.livesetting.other.LiveDialogFragmentOptSetting;
import com.bytedance.android.livesdk.livesetting.performance.PanelOpenCostTimesSetting;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.sdk.datachannel.DataChannel;
import java.util.HashMap;
import java.util.Objects;
import kotlin.h.b.n;

public abstract class LiveDialogFragment extends DialogFragment {
    public static final C2310Ga7 LJIILLIIL = new C2310Ga7((byte) 0);
    public final C2307Ga4 LIZ = C2307Ga4.DEFAULT;
    public HashMap LIZIZ;
    public boolean LJIIL;
    public DataChannel LJIILIIL;
    public C1044Fun LJIILJJIL;
    public DialogInterface.OnDismissListener LJIILL;

    static {
        Covode.recordClassIndex(11217);
    }

    public abstract C1044Fun LIZ();

    public Dialog LIZ(Bundle bundle) {
        return null;
    }

    public View LIZ(int i) {
        if (this.LIZIZ == null) {
            this.LIZIZ = new HashMap();
        }
        View view = (View) this.LIZIZ.get(Integer.valueOf(i));
        if (view != null) {
            return view;
        }
        View view2 = getView();
        if (view2 == null) {
            return null;
        }
        View findViewById = view2.findViewById(i);
        this.LIZIZ.put(Integer.valueOf(i), findViewById);
        return findViewById;
    }

    public boolean LJIIIIZZ() {
        return false;
    }

    public void z_() {
        HashMap hashMap = this.LIZIZ;
        if (hashMap != null) {
            hashMap.clear();
        }
    }

    public C2307Ga4 b_() {
        return this.LIZ;
    }

    public final C1044Fun LJIIIZ() {
        C1044Fun fun = this.LJIILJJIL;
        if (fun == null) {
            n.LIZ("");
        }
        return fun;
    }

    public final boolean LJIIJ() {
        Dialog dialog = getDialog();
        if (dialog == null || !dialog.isShowing()) {
            return false;
        }
        return true;
    }

    public void onDestroyView() {
        this.LJIIL = false;
        LiveDialogFragment.super.onDestroyView();
        z_();
    }

    private final void LIZLLL() {
        C2311Ga8.LIZ().LIZIZ();
        C1344Fzd.LIZ().LIZIZ();
        3Ww.LIZ(this, "mDismissed", false);
        3Ww.LIZ(this, "mShownByMe", true);
    }

    public void dismiss() {
        if (getFragmentManager() == null) {
            0aP.LIZ(3, "LiveDialogFragment", "dismiss:" + this + " not associate with a fragment manager");
            return;
        }
        LiveDialogFragment.super.dismissAllowingStateLoss();
    }

    public void dismissAllowingStateLoss() {
        if (getFragmentManager() == null) {
            0aP.LIZ(3, "LiveDialogFragment", "dismissAllowingStateLoss:" + this + " not associate with a fragment manager");
            return;
        }
        LiveDialogFragment.super.dismissAllowingStateLoss();
    }

    public void onStart() {
        int i;
        LiveDialogFragment.super.onStart();
        Dialog dialog = getDialog();
        if (dialog != null) {
            C1044Fun fun = this.LJIILJJIL;
            if (fun == null) {
                n.LIZ("");
            }
            dialog.setCanceledOnTouchOutside(fun.LJ);
            Window window = dialog.getWindow();
            if (window != null) {
                C1044Fun fun2 = this.LJIILJJIL;
                if (fun2 == null) {
                    n.LIZ("");
                }
                window.setBackgroundDrawable(fun2.LJIIJ);
                WindowManager.LayoutParams attributes = window.getAttributes();
                C1044Fun fun3 = this.LJIILJJIL;
                if (fun3 == null) {
                    n.LIZ("");
                }
                attributes.dimAmount = fun3.LJFF;
                C1044Fun fun4 = this.LJIILJJIL;
                if (fun4 == null) {
                    n.LIZ("");
                }
                attributes.width = fun4.LJII;
                C1044Fun fun5 = this.LJIILJJIL;
                if (fun5 == null) {
                    n.LIZ("");
                }
                if (fun5.LJIIIIZZ == Integer.MIN_VALUE) {
                    Resources resources = getResources();
                    n.LIZIZ(resources, "");
                    int i2 = resources.getDisplayMetrics().heightPixels;
                    C1044Fun fun6 = this.LJIILJJIL;
                    if (fun6 == null) {
                        n.LIZ("");
                    }
                    i = (i2 * fun6.LJIIIZ) / 100;
                } else {
                    C1044Fun fun7 = this.LJIILJJIL;
                    if (fun7 == null) {
                        n.LIZ("");
                    }
                    i = fun7.LJIIIIZZ;
                }
                attributes.height = i;
                C1044Fun fun8 = this.LJIILJJIL;
                if (fun8 == null) {
                    n.LIZ("");
                }
                attributes.gravity = fun8.LJI;
                C1044Fun fun9 = this.LJIILJJIL;
                if (fun9 == null) {
                    n.LIZ("");
                }
                attributes.softInputMode = fun9.LJIIJJI;
                window.setAttributes(attributes);
            }
        }
    }

    public void onCancel(DialogInterface dialogInterface) {
        if (this.LJIIL) {
            dismissAllowingStateLoss();
        }
    }

    public final void LIZ(DialogInterface.OnDismissListener onDismissListener) {
        this.LJIILL = onDismissListener;
    }

    public final Dialog onCreateDialog(Bundle bundle) {
        Dialog LIZ2 = LIZ(bundle);
        if (LIZ2 == null) {
            LIZ2 = LiveDialogFragment.super.onCreateDialog(bundle);
            n.LIZIZ(LIZ2, "");
        }
        C1044Fun fun = this.LJIILJJIL;
        if (fun == null) {
            n.LIZ("");
        }
        LIZ2.requestWindowFeature(fun.LIZJ);
        M12.LIZ(LIZ2);
        return LIZ2;
    }

    public void onDismiss(DialogInterface dialogInterface) {
        C2311Ga8.LIZ().LIZJ();
        C1344Fzd.LIZ().LIZJ();
        LiveDialogFragment.super.onDismiss(dialogInterface);
        DialogInterface.OnDismissListener onDismissListener = this.LJIILL;
        if (onDismissListener != null) {
            onDismissListener.onDismiss(dialogInterface);
        }
    }

    public void onCreate(Bundle bundle) {
        int i;
        LiveDialogFragment.super.onCreate(bundle);
        this.LJIIL = false;
        this.LJIILIIL = GSF.LIZ((Fragment) this);
        C1044Fun LIZ2 = LIZ();
        if (LIZ2.LIZLLL) {
            i = 2131887233;
        } else {
            i = 2131887236;
        }
        int i2 = LIZ2.LIZ;
        if (LIZ2.LIZIZ != -1) {
            i = LIZ2.LIZIZ;
        }
        setStyle(i2, i);
        this.LJIILJJIL = LIZ2;
    }

    public void showNow(0AA r3, String str) {
        M12.LIZ(r3, str);
        C2306Ga3.LIZ(b_());
        LIZLLL();
        0AP LIZ2 = r3.LIZ();
        LIZ2.LIZ(this, str);
        LIZ2.LJ();
    }

    public void onViewCreated(View view, Bundle bundle) {
        M12.LIZ(view);
        LiveDialogFragment.super.onViewCreated(view, bundle);
        this.LJIIL = true;
        Dialog dialog = getDialog();
        if (dialog != null) {
            dialog.setOnKeyListener(new C2308Ga5(this));
        }
        if (view instanceof C2670Gfv) {
            ((C2670Gfv) view).setTraversalCallBack(new C2122GTb(this));
        }
    }

    public int show(0AP r4, String str) {
        M12.LIZ(r4, str);
        C2306Ga3.LIZ(b_());
        LIZLLL();
        r4.LIZ(this, str);
        3Ww.LIZ(this, "mViewDestroyed", false);
        int LIZJ = r4.LIZJ();
        3Ww.LIZ(this, "mBackStackId", Integer.valueOf(LIZJ));
        return LIZJ;
    }

    public void show(0AA r3, String str) {
        M12.LIZ(r3, str);
        C2306Ga3.LIZ(b_());
        LIZLLL();
        if (LiveDialogFragmentOptSetting.INSTANCE.enable()) {
            0AP LIZ2 = r3.LIZ();
            LIZ2.LIZ(this);
            LIZ2.LIZ(this, str);
            LIZ2.LIZJ();
            return;
        }
        0AP LIZ3 = r3.LIZ();
        LIZ3.LIZ(this, str);
        LIZ3.LIZJ();
    }

    public final View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        M12.LIZ(layoutInflater);
        if (!PanelOpenCostTimesSetting.INSTANCE.getValue().LIZ) {
            C1044Fun fun = this.LJIILJJIL;
            if (fun == null) {
                n.LIZ("");
            }
            return 0HH.LIZ(layoutInflater, fun.LJIIL, viewGroup, false);
        }
        View LIZ2 = 0HH.LIZ(layoutInflater, 2131562242, viewGroup, false);
        C1044Fun fun2 = this.LJIILJJIL;
        if (fun2 == null) {
            n.LIZ("");
        }
        int i = fun2.LJIIL;
        Objects.requireNonNull(LIZ2, "null cannot be cast to non-null type com.bytedance.android.livesdk.ui.LiveFrameLayout");
        C2670Gfv gfv = (C2670Gfv) LIZ2;
        0HH.LIZ(layoutInflater, i, gfv, true);
        View childAt = gfv.getChildAt(0);
        n.LIZIZ(childAt, "");
        ViewGroup.LayoutParams layoutParams = childAt.getLayoutParams();
        layoutParams.height = -1;
        layoutParams.width = -1;
        return LIZ2;
    }
}
