package com.bytedance.android.live.design.view.sheet;

import X.6Is;
import X.AnonymousClass0CB;
import X.AnonymousClass0CH;
import X.AnonymousClass0HH;
import X.AnonymousClass1MX;
import X.C019107h;
import X.C019707n;
import X.C11910e5;
import X.C39131gt;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.FrameLayout;
import androidx.core.g.t;
import com.bytedance.android.live.design.app.LifecycleAwareDialog;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;

public class LiveBottomSheetDialog extends LifecycleAwareDialog implements 6Is {
    public LiveBottomSheetBehavior<FrameLayout> LIZ;
    public FrameLayout LIZIZ;
    public boolean LIZJ;
    public boolean LIZLLL;
    public boolean LJ;
    public C39131gt LJFF;
    public FrameLayout LJI;
    public float LJII;
    public C11910e5 LJIIIIZZ;

    static {
        Covode.recordClassIndex(5820);
    }

    public void onStateChanged(AnonymousClass0CH r1, AnonymousClass0CB r2) {
        super.onStateChanged(r1, r2);
    }

    public final LiveBottomSheetBehavior<FrameLayout> LIZIZ() {
        if (this.LIZ == null) {
            LIZLLL();
        }
        return this.LIZ;
    }

    public void onStart() {
        super.onStart();
        LiveBottomSheetBehavior<FrameLayout> liveBottomSheetBehavior = this.LIZ;
        if (liveBottomSheetBehavior != null && liveBottomSheetBehavior.LJIILIIL == 5) {
            this.LIZ.LIZIZ(4);
        }
    }

    public final void LIZJ() {
        int LIZ2;
        if (getWindow() != null && (LIZ2 = this.LIZ.LJIILLIIL - this.LIZ.LIZ()) > 0) {
            getWindow().setDimAmount((((float) (this.LIZ.LJIILLIIL - this.LJI.getTop())) / ((float) LIZ2)) * this.LJII);
        }
    }

    private FrameLayout LIZLLL() {
        MethodCollector.i(9762);
        if (this.LIZIZ == null) {
            FrameLayout frameLayout = (FrameLayout) View.inflate(getContext(), 2131560548, (ViewGroup) null);
            this.LIZIZ = frameLayout;
            this.LJFF = (C39131gt) frameLayout.findViewById(2131363744);
            FrameLayout frameLayout2 = (FrameLayout) this.LIZIZ.findViewById(2131364037);
            this.LJI = frameLayout2;
            t.LIZ((View) frameLayout2, AnonymousClass1MX.LIZ);
            LiveBottomSheetBehavior<FrameLayout> LIZ2 = LiveBottomSheetBehavior.LIZ(this.LJI);
            this.LIZ = LIZ2;
            LIZ2.LIZ(this.LJIIIIZZ);
            this.LIZ.LIZIZ(this.LIZJ);
            this.LIZIZ.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
                static {
                    Covode.recordClassIndex(5821);
                }

                public final void onLayoutChange(View view, int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8) {
                    LiveBottomSheetDialog.this.LIZJ();
                    LiveBottomSheetDialog.this.LIZIZ.removeOnLayoutChangeListener(this);
                }
            });
        }
        FrameLayout frameLayout3 = this.LIZIZ;
        MethodCollector.o(9762);
        return frameLayout3;
    }

    public LiveBottomSheetDialog(Context context) {
        this(context, (byte) 0);
    }

    public void setContentView(int i) {
        super.setContentView(LIZ(i, (View) null, (ViewGroup.LayoutParams) null));
    }

    public void setCancelable(boolean z) {
        super.setCancelable(z);
        if (this.LIZJ != z) {
            this.LIZJ = z;
            LiveBottomSheetBehavior<FrameLayout> liveBottomSheetBehavior = this.LIZ;
            if (liveBottomSheetBehavior != null) {
                liveBottomSheetBehavior.LIZIZ(z);
            }
        }
    }

    public void setCanceledOnTouchOutside(boolean z) {
        super.setCanceledOnTouchOutside(z);
        if (z && !this.LIZJ) {
            this.LIZJ = true;
        }
        this.LIZLLL = z;
        this.LJ = true;
    }

    public void setContentView(View view) {
        super.setContentView(LIZ(0, view, (ViewGroup.LayoutParams) null));
    }

    public void onCreate(Bundle bundle) {
        int i;
        super.onCreate(bundle);
        Window window = getWindow();
        if (window != null) {
            window.setStatusBarColor(0);
            window.addFlags(Integer.MIN_VALUE);
            if (Build.VERSION.SDK_INT < 23) {
                window.addFlags(67108864);
            }
            window.setLayout(-1, -1);
            if (getContext().getResources().getConfiguration().orientation == 1) {
                i = 2131886088;
            } else if (getContext().getResources().getConfiguration().getLayoutDirection() == 1) {
                i = 2131886090;
            } else {
                i = 2131886089;
            }
            window.setWindowAnimations(i);
        }
        TypedValue typedValue = new TypedValue();
        getContext().getTheme().resolveAttribute(16842802, typedValue, true);
        this.LJII = typedValue.getFloat();
    }

    public LiveBottomSheetDialog(Context context, byte b) {
        this(context, 0, (byte) 0);
    }

    public LiveBottomSheetDialog(Context context, int i) {
        this(context, i, (byte) 0);
    }

    public void setContentView(View view, ViewGroup.LayoutParams layoutParams) {
        super.setContentView(LIZ(0, view, layoutParams));
    }

    /* JADX WARNING: Illegal instructions before constructor call */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public LiveBottomSheetDialog(android.content.Context r5, int r6, byte r7) {
        /*
            r4 = this;
            r3 = 1
            if (r6 != 0) goto L_0x0017
            android.util.TypedValue r2 = new android.util.TypedValue
            r2.<init>()
            android.content.res.Resources$Theme r1 = r5.getTheme()
            r0 = 2130969867(0x7f04050b, float:1.7548428E38)
            boolean r0 = r1.resolveAttribute(r0, r2, r3)
            if (r0 == 0) goto L_0x002a
            int r6 = r2.resourceId
        L_0x0017:
            r0 = 0
            r4.<init>(r5, r6, r0)
            r4.LIZJ = r3
            r4.LIZLLL = r3
            com.bytedance.android.live.design.view.sheet.LiveBottomSheetDialog$5 r0 = new com.bytedance.android.live.design.view.sheet.LiveBottomSheetDialog$5
            r0.<init>()
            r4.LJIIIIZZ = r0
            r4.dA_()
            return
        L_0x002a:
            r6 = 2131886559(0x7f1201df, float:1.94077E38)
            goto L_0x0017
        */
        throw new UnsupportedOperationException("Method not decompiled: com.bytedance.android.live.design.view.sheet.LiveBottomSheetDialog.<init>(android.content.Context, int, byte):void");
    }

    private View LIZ(int i, View view, ViewGroup.LayoutParams layoutParams) {
        MethodCollector.i(9765);
        LIZLLL();
        C39131gt r2 = (C39131gt) this.LIZIZ.findViewById(2131363744);
        if (i != 0 && view == null) {
            view = AnonymousClass0HH.LIZ(getLayoutInflater(), i, r2, false);
        }
        this.LJI.removeAllViews();
        if (layoutParams == null) {
            this.LJI.addView(view, -1, -1);
        } else {
            this.LJI.addView(view, layoutParams);
        }
        r2.findViewById(2131371474).setOnClickListener(new View.OnClickListener() {
            static {
                Covode.recordClassIndex(5822);
            }

            public final void onClick(View view) {
                if (LiveBottomSheetDialog.this.LIZJ && LiveBottomSheetDialog.this.isShowing()) {
                    LiveBottomSheetDialog liveBottomSheetDialog = LiveBottomSheetDialog.this;
                    if (!liveBottomSheetDialog.LJ) {
                        TypedArray obtainStyledAttributes = liveBottomSheetDialog.getContext().obtainStyledAttributes(new int[]{16843611});
                        liveBottomSheetDialog.LIZLLL = obtainStyledAttributes.getBoolean(0, true);
                        obtainStyledAttributes.recycle();
                        liveBottomSheetDialog.LJ = true;
                    }
                    if (liveBottomSheetDialog.LIZLLL) {
                        LiveBottomSheetDialog.this.cancel();
                    }
                }
            }
        });
        t.LIZ((View) this.LJI, (C019707n) new C019707n() {
            static {
                Covode.recordClassIndex(5823);
            }

            public final void LIZ(View view, C019107h r3) {
                super.LIZ(view, r3);
                if (LiveBottomSheetDialog.this.LIZJ) {
                    r3.LIZ(1048576);
                    r3.LJFF(true);
                    return;
                }
                r3.LJFF(false);
            }

            public final boolean LIZ(View view, int i, Bundle bundle) {
                if (i != 1048576 || !LiveBottomSheetDialog.this.LIZJ) {
                    return super.LIZ(view, i, bundle);
                }
                LiveBottomSheetDialog.this.cancel();
                return true;
            }
        });
        this.LJI.setOnTouchListener(new View.OnTouchListener() {
            static {
                Covode.recordClassIndex(5824);
            }

            public final boolean onTouch(View view, MotionEvent motionEvent) {
                return true;
            }
        });
        FrameLayout frameLayout = this.LIZIZ;
        MethodCollector.o(9765);
        return frameLayout;
    }
}
