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

import X.0HH;
import X.0bM;
import X.2M2;
import X.C5090Szu;
import X.C5091Szv;
import X.C5092Szw;
import X.C5094Szy;
import X.Gg0;
import X.T0N;
import X.Tib;
import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.InputFilter;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.EditText;
import androidx.fragment.app.DialogFragment;
import com.bytedance.covode.number.Covode;

public class SimpleInputDialogFragment extends DialogFragment {
    public boolean LIZ = false;
    public C5094Szy LIZIZ = null;
    public EditText LIZJ;
    public View LIZLLL;
    public View LJ;
    public String LJFF = null;
    public int LJI = 0;
    public boolean LJII = false;
    public final View.OnLayoutChangeListener LJIIIIZZ = new View.OnLayoutChangeListener() {
        public float LIZIZ = -1.0f;

        static {
            Covode.recordClassIndex(14075);
        }

        public final void onLayoutChange(View view, int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8) {
            if (SimpleInputDialogFragment.this.LJ != null) {
                if (this.LIZIZ < 0.0f) {
                    this.LIZIZ = ((float) SimpleInputDialogFragment.this.getResources().getDisplayMetrics().heightPixels) * 0.75f;
                }
                if (((float) i4) < this.LIZIZ) {
                    if (!SimpleInputDialogFragment.this.LIZ) {
                        SimpleInputDialogFragment.this.LIZ = true;
                        SimpleInputDialogFragment.this.LJ.setVisibility(0);
                        SimpleInputDialogFragment.this.LIZ(true, i8 - i4);
                    }
                } else if (SimpleInputDialogFragment.this.LIZ) {
                    SimpleInputDialogFragment.this.LIZ = false;
                    SimpleInputDialogFragment.this.LJ.setVisibility(4);
                    try {
                        SimpleInputDialogFragment.this.dismiss();
                    } catch (IllegalStateException unused) {
                    }
                    SimpleInputDialogFragment.this.LIZ(false, 0);
                }
            }
        }
    };
    public boolean LJIIIZ = false;
    public boolean LJIIJ;

    static {
        Covode.recordClassIndex(14074);
    }

    public void onDestroyView() {
        SimpleInputDialogFragment.super.onDestroyView();
        this.LJ.removeOnLayoutChangeListener(this.LJIIIIZZ);
    }

    public final /* synthetic */ void LIZ() {
        if (isAdded()) {
            2M2.LIZ(getContext(), this.LIZJ);
        }
    }

    public void onResume() {
        SimpleInputDialogFragment.super.onResume();
        if (this.LJIIIZ) {
            this.LJIIIZ = false;
            LIZIZ(200, 1, 5);
            return;
        }
        this.LIZJ.postDelayed(new C5092Szw(this), 50);
    }

    public final /* synthetic */ void LIZIZ() {
        if (this.LIZIZ != null && this.LIZJ.getText() != null) {
            this.LIZJ.getText().toString().trim();
        }
    }

    public void onSaveInstanceState(Bundle bundle) {
        SimpleInputDialogFragment.super.onSaveInstanceState(bundle);
        this.LJIIIZ = this.LIZ;
    }

    public void onActivityCreated(Bundle bundle) {
        Window window;
        SimpleInputDialogFragment.super.onActivityCreated(bundle);
        Dialog dialog = getDialog();
        if (dialog != null && (window = dialog.getWindow()) != null) {
            window.setLayout(-1, -1);
        }
    }

    public void onCreate(Bundle bundle) {
        SimpleInputDialogFragment.super.onCreate(bundle);
        if (getArguments() != null) {
            this.LJFF = getArguments().getString("live.intent.extra.HINT", (String) null);
            this.LJI = getArguments().getInt("live.intent.extra.MAX_LENGTH", 0);
            this.LJII = getArguments().getBoolean("live.intent.extra.TOUCH_MODAL", false);
            this.LJIIJ = getArguments().getBoolean("live.intent.extra.IS_BROADCASTER", false);
        }
    }

    public Dialog onCreateDialog(Bundle bundle) {
        Dialog onCreateDialog = SimpleInputDialogFragment.super.onCreateDialog(bundle);
        onCreateDialog.setCanceledOnTouchOutside(false);
        Window window = onCreateDialog.getWindow();
        if (window != null) {
            window.setGravity(80);
            window.setBackgroundDrawable(new ColorDrawable(0));
            window.setSoftInputMode(3);
            if (!this.LJIIJ && !0bM.LIZ(getActivity())) {
                window.addFlags(1024);
            }
            if (!this.LJII) {
                window.addFlags(32);
                window.clearFlags(2);
            }
        }
        return onCreateDialog;
    }

    public void onDismiss(DialogInterface dialogInterface) {
        SimpleInputDialogFragment.super.onDismiss(dialogInterface);
        if (this.LIZIZ != null) {
            if (this.LIZJ.getText() != null) {
                this.LIZJ.getText().toString().trim();
            }
            this.LIZIZ = null;
            this.LIZ = false;
        }
    }

    public final /* synthetic */ boolean LIZ(int i) {
        if (i != 6) {
            return false;
        }
        if (!this.LIZLLL.isEnabled()) {
            return true;
        }
        this.LIZLLL.performClick();
        return true;
    }

    public final void LIZ(boolean z, int i) {
        Gg0.LIZ().LIZ(new Tib(i, z));
    }

    public void onViewCreated(View view, Bundle bundle) {
        SimpleInputDialogFragment.super.onViewCreated(view, bundle);
        if (getArguments() != null) {
            String string = getArguments().getString("live.intent.extra.INPUT");
            if (isAdded() && !TextUtils.isEmpty(string)) {
                this.LIZJ.setText(string);
                EditText editText = this.LIZJ;
                editText.setSelection(editText.getText().length());
            }
        }
        this.LIZJ.setOnEditorActionListener(new C5090Szu(this));
        this.LIZLLL.setOnClickListener(new C5091Szv(this));
    }

    /*  JADX ERROR: JadxRuntimeException in pass: CodeShrinkVisitor
        jadx.core.utils.exceptions.JadxRuntimeException: Don't wrap MOVE or CONST insns: 0x0005: MOVE  (r6v0 int) = (r11v0 int)
        	at jadx.core.dex.instructions.args.InsnArg.wrapArg(InsnArg.java:164)
        	at jadx.core.dex.visitors.shrink.CodeShrinkVisitor.assignInline(CodeShrinkVisitor.java:133)
        	at jadx.core.dex.visitors.shrink.CodeShrinkVisitor.checkInline(CodeShrinkVisitor.java:118)
        	at jadx.core.dex.visitors.shrink.CodeShrinkVisitor.shrinkBlock(CodeShrinkVisitor.java:65)
        	at jadx.core.dex.visitors.shrink.CodeShrinkVisitor.shrinkMethod(CodeShrinkVisitor.java:43)
        	at jadx.core.dex.visitors.shrink.CodeShrinkVisitor.visit(CodeShrinkVisitor.java:35)
        */
    private void LIZIZ(long r8, int r10, int r11) {
        /*
            r7 = this;
            android.widget.EditText r0 = r7.LIZJ
            if (r0 == 0) goto L_0x0008
            r5 = r10
            r6 = r11
            if (r5 <= r6) goto L_0x0009
        L_0x0008:
            return
        L_0x0009:
            X.Szx r1 = new X.Szx
            r2 = r7
            r3 = r8
            r1.<init>(r2, r3, r5, r6)
            r0.postDelayed(r1, r3)
            goto L_0x0008
        */
        throw new UnsupportedOperationException("Method not decompiled: com.bytedance.android.livesdk.chatroom.ui.SimpleInputDialogFragment.LIZIZ(long, int, int):void");
    }

    public final /* synthetic */ void LIZ(long j, int i, int i2) {
        if (isResumed() && this.LIZ) {
            2M2.LIZ(getContext(), this.LIZJ);
            LIZIZ(j, i + 1, i2);
        }
    }

    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        InputFilter[] inputFilterArr;
        View LIZ2 = 0HH.LIZ(LayoutInflater.from(getContext()), 2131561781, viewGroup, false);
        this.LJ = LIZ2;
        LIZ2.addOnLayoutChangeListener(this.LJIIIIZZ);
        this.LIZJ = (EditText) this.LJ.findViewById(2131363937);
        this.LIZLLL = this.LJ.findViewById(2131370094);
        ((T0N) this.LJ.findViewById(2131372956)).setActivity(getActivity());
        this.LIZJ.setHint(this.LJFF);
        if (this.LJI > 0) {
            InputFilter[] filters = this.LIZJ.getFilters();
            if (filters == null || filters.length == 0) {
                inputFilterArr = new InputFilter[1];
            } else {
                inputFilterArr = new InputFilter[(filters.length + 1)];
                for (int i = 0; i < filters.length; i++) {
                    inputFilterArr[i] = filters[i];
                }
            }
            inputFilterArr[inputFilterArr.length - 1] = new InputFilter.LengthFilter(this.LJI);
            this.LIZJ.setFilters(inputFilterArr);
        }
        this.LJ.findViewById(2131363938).getLayoutParams().width = getResources().getDisplayMetrics().widthPixels;
        return this.LJ;
    }
}
