package com.ss.android.ugc.aweme.profile.ui;

import X.070;
import X.0HH;
import X.1hK;
import X.2uR;
import X.3BB;
import X.3c7;
import X.3c9;
import X.3cC;
import X.3cI;
import X.3qP;
import X.4FQ;
import X.4ZZ;
import X.4vl;
import X.9EH;
import X.C5303OQg;
import X.C5319OQw;
import X.CqM;
import X.FNz;
import X.FO0;
import X.FOA;
import X.FOh;
import X.JJh;
import X.JMC;
import X.M12;
import X.OP9;
import X.OR0;
import X.OR1;
import X.OR2;
import android.app.Dialog;
import android.content.DialogInterface;
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.view.Window;
import android.widget.EditText;
import android.widget.TextView;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.base.utils.KeyboardUtils;
import com.ss.android.ugc.aweme.profile.model.User;
import kotlin.h.b.n;

public final class ProfileEditBioUrlFragment extends ProfileEditInputFragment implements FO0 {
    public static final FOA LJIILL = new FOA((byte) 0);
    public String LIZ = "";
    public boolean LIZIZ;
    public int LIZJ;
    public boolean LIZLLL;
    public FOh LJFF;
    public FNz LJI;
    public OR2 LJII;
    public C5303OQg LJIIIIZZ;
    public TextView LJIIIZ;
    public EditText LJIIJ;
    public 4ZZ LJIIJJI;
    public TextView LJIIL;
    public View LJIILIIL;
    public int LJIILJJIL;
    public String LJIJI = "";
    public SparseArray LJIJJ;

    static {
        Covode.recordClassIndex(99064);
    }

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

    public final void LJFF() {
        SparseArray sparseArray = this.LJIJJ;
        if (sparseArray != null) {
            sparseArray.clear();
        }
    }

    public final C5303OQg LIZ() {
        C5303OQg oQg = this.LJIIIIZZ;
        if (oQg == null) {
            n.LIZ("");
        }
        return oQg;
    }

    public final EditText LIZJ() {
        EditText editText = this.LJIIJ;
        if (editText == null) {
            n.LIZ("");
        }
        return editText;
    }

    public final 4ZZ LIZLLL() {
        4ZZ r1 = this.LJIIJJI;
        if (r1 == null) {
            n.LIZ("");
        }
        return r1;
    }

    public final void LJ() {
        FOh fOh = this.LJFF;
        if (fOh != null) {
            EditText editText = this.LJIIJ;
            if (editText == null) {
                n.LIZ("");
            }
            fOh.LIZ(editText.getText().toString());
        }
    }

    public final void onDestroyView() {
        ProfileEditBioUrlFragment.super.onDestroyView();
        FNz fNz = this.LJI;
        if (fNz != null) {
            fNz.LIZLLL = null;
        }
        C5303OQg oQg = this.LJIIIIZZ;
        if (oQg == null) {
            n.LIZ("");
        }
        oQg.setVisibility(8);
        LJFF();
    }

    public final boolean dn_() {
        Dialog dialog;
        EditText editText = this.LJIIJ;
        if (editText == null) {
            n.LIZ("");
        }
        KeyboardUtils.LIZJ(editText);
        if (getActivity() instanceof ProfileEditBioUrlActivity) {
            1hK activity = getActivity();
            if (activity == null) {
                n.LIZIZ();
            }
            activity.finish();
        } else if (getDialog() != null && (dialog = getDialog()) != null && dialog.isShowing() && isResumed()) {
            try {
                dismiss();
            } catch (Exception e) {
                0HH.LIZ(e);
            }
        }
        return true;
    }

    public final void LIZ(boolean z) {
        if (z) {
            3BB r1 = new 3BB(9EH.LJJIFFI.LIZ());
            r1.LIZIZ(2131821267);
            r1.LIZIZ();
            CqM.LIZ(new 3qP());
        }
    }

    public final void onCreate(Bundle bundle) {
        ProfileEditBioUrlFragment.super.onCreate(bundle);
        if (getArguments() != null) {
            Bundle arguments = getArguments();
            if (arguments == null) {
                n.LIZIZ();
            }
            String string = arguments.getString("content_value");
            if (string == null) {
                n.LIZIZ();
            }
            this.LIZ = string;
            Bundle arguments2 = getArguments();
            if (arguments2 == null) {
                n.LIZIZ();
            }
            this.LIZIZ = arguments2.getBoolean("is_edit_enabled");
            Bundle arguments3 = getArguments();
            if (arguments3 == null) {
                n.LIZIZ();
            }
            String string2 = arguments3.getString("edit_hint");
            if (string2 == null) {
                n.LIZIZ();
            }
            this.LJIJI = string2;
            Bundle arguments4 = getArguments();
            if (arguments4 == null) {
                n.LIZIZ();
            }
            this.LIZJ = arguments4.getInt("content_max_length");
            Bundle arguments5 = getArguments();
            if (arguments5 == null) {
                n.LIZIZ();
            }
            this.LIZLLL = arguments5.getBoolean("is_enable_null");
        }
    }

    public final void LIZ(int i, String str) {
        M12.LIZ(str);
        if (this.LJIILJJIL != i) {
            if (i == 0) {
                TextView textView = this.LJIIL;
                if (textView == null) {
                    n.LIZ("");
                }
                textView.setTextColor(070.LIZJ(textView.getContext(), 2131099758));
                textView.setVisibility(8);
                View view = this.LJIILIIL;
                if (view == null) {
                    n.LIZ("");
                }
                view.setBackgroundColor(070.LIZJ(textView.getContext(), 2131099719));
            } else {
                TextView textView2 = this.LJIIL;
                if (textView2 == null) {
                    n.LIZ("");
                }
                textView2.setText(str);
                textView2.setTextColor(070.LIZJ(textView2.getContext(), 2131100043));
                textView2.setVisibility(0);
                View view2 = this.LJIILIIL;
                if (view2 == null) {
                    n.LIZ("");
                }
                view2.setBackgroundColor(070.LIZJ(textView2.getContext(), 2131100043));
            }
            this.LJIILJJIL = i;
        }
    }

    public final void LIZ(User user, int i) {
        C5303OQg oQg = this.LJIIIIZZ;
        if (oQg == null) {
            n.LIZ("");
        }
        oQg.setVisibility(8);
        if (getActivity() instanceof ProfileEditBioUrlActivity) {
            1hK activity = getActivity();
            if (activity == null) {
                n.LIZIZ();
            }
            activity.finish();
            return;
        }
        LJ();
        dismiss();
    }

    public final void LIZ(Exception exc, int i) {
        C5303OQg oQg = this.LJIIIIZZ;
        if (oQg == null) {
            n.LIZ("");
        }
        oQg.setVisibility(8);
        if (exc instanceof JMC) {
            JMC jmc = (JMC) exc;
            int errorCode = jmc.getErrorCode();
            if (errorCode == 2097) {
                1hK activity = getActivity();
                if (activity != null) {
                    n.LIZIZ(activity, "");
                    4vl r2 = new 4vl(activity);
                    r2.LIZJ(2131826629);
                    r2.LIZLLL(2131826627);
                    r2.LIZIZ(2131826628, (DialogInterface.OnClickListener) null);
                    4FQ.LIZ(r2.LIZ().LIZJ());
                }
            } else if (errorCode == 2123) {
                String errorMsg = jmc.getErrorMsg();
                n.LIZIZ(errorMsg, "");
                LIZ(1, errorMsg);
            }
        }
    }

    public final void LIZ(String str, boolean z) {
        C5303OQg oQg = this.LJIIIIZZ;
        if (oQg == null) {
            n.LIZ("");
        }
        oQg.setVisibility(8);
        if (str != null && !TextUtils.isEmpty(str)) {
            3BB r1 = new 3BB(9EH.LJJIFFI.LIZ());
            r1.LIZ(str);
            r1.LIZIZ();
            if (z && getActivity() != null) {
                1hK activity = getActivity();
                if (activity == null) {
                    n.LIZIZ();
                }
                activity.finish();
            }
        }
    }

    public final View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        Window window;
        int intValue;
        M12.LIZ(layoutInflater);
        View LIZ2 = 0HH.LIZ(layoutInflater, 2131560795, viewGroup, false);
        View findViewById = LIZ2.findViewById(2131370625);
        n.LIZIZ(findViewById, "");
        this.LJIIIIZZ = (C5303OQg) findViewById;
        View findViewById2 = LIZ2.findViewById(2131371877);
        n.LIZIZ(findViewById2, "");
        this.LJIIIZ = (TextView) findViewById2;
        View findViewById3 = LIZ2.findViewById(2131364628);
        n.LIZIZ(findViewById3, "");
        this.LJIIJ = (EditText) findViewById3;
        4ZZ findViewById4 = LIZ2.findViewById(2131366351);
        n.LIZIZ(findViewById4, "");
        this.LJIIJJI = findViewById4;
        View findViewById5 = LIZ2.findViewById(2131371951);
        n.LIZIZ(findViewById5, "");
        LIZ((TextView) findViewById5);
        View findViewById6 = LIZ2.findViewById(2131371949);
        n.LIZIZ(findViewById6, "");
        this.LJIIL = (TextView) findViewById6;
        View findViewById7 = LIZ2.findViewById(2131372871);
        n.LIZIZ(findViewById7, "");
        this.LJIILIIL = findViewById7;
        View findViewById8 = LIZ2.findViewById(2131366351);
        if (findViewById8 != null) {
            findViewById8.setOnClickListener(new OR0(this));
        }
        JJh jJh = JJh.LIZ;
        1hK activity = getActivity();
        Dialog dialog = getDialog();
        Integer num = null;
        if (dialog != null) {
            window = dialog.getWindow();
        } else {
            window = null;
        }
        jJh.LIZ(activity, window, true);
        FNz fNz = new FNz();
        this.LJI = fNz;
        fNz.LIZLLL = this;
        this.LJII = new OR2();
        TextView textView = this.LJIIIZ;
        if (textView == null) {
            n.LIZ("");
        }
        textView.setText(getString(2131824465));
        EditText editText = this.LJIIJ;
        if (editText == null) {
            n.LIZ("");
        }
        editText.addTextChangedListener(new C5319OQw(this));
        EditText editText2 = this.LJIIJ;
        if (editText2 == null) {
            n.LIZ("");
        }
        editText2.setText(this.LIZ);
        EditText editText3 = this.LJIIJ;
        if (editText3 == null) {
            n.LIZ("");
        }
        EditText editText4 = this.LJIIJ;
        if (editText4 == null) {
            n.LIZ("");
        }
        editText3.setSelection(editText4.getText().length());
        EditText editText5 = this.LJIIJ;
        if (editText5 == null) {
            n.LIZ("");
        }
        editText5.setFocusable(true);
        EditText editText6 = this.LJIIJ;
        if (editText6 == null) {
            n.LIZ("");
        }
        editText6.setFocusableInTouchMode(true);
        EditText editText7 = this.LJIIJ;
        if (editText7 == null) {
            n.LIZ("");
        }
        editText7.requestFocus();
        this.LJIILLIIL = LIZ2.findViewById(2131367895);
        3cI LJIIIZ2 = LJIIIZ();
        String string = getString(2131824465);
        n.LIZIZ(string, "");
        3cC LIZIZ2 = LIZIZ(string);
        3cI r7 = new 3c9();
        r7.LIZ("save");
        String string2 = getString(2131824457);
        n.LIZIZ(string2, "");
        r7.LIZ(string2);
        r7.LIZ(new OP9(this));
        3c7 r6 = this.LJIILLIIL;
        if (r6 != null) {
            2uR r1 = new 2uR();
            r1.LIZ(new 3cI[]{LJIIIZ2});
            r1.LIZ(LIZIZ2);
            r1.LIZIZ(new 3cI[]{r7});
            r1.LIZLLL = true;
            r6.setNavActions(r1);
        }
        if (!this.LIZIZ) {
            EditText editText8 = this.LJIIJ;
            if (editText8 == null) {
                n.LIZ("");
            }
            editText8.setEnabled(false);
            EditText editText9 = this.LJIIJ;
            if (editText9 == null) {
                n.LIZ("");
            }
            editText9.setFocusable(false);
            EditText editText10 = this.LJIIJ;
            if (editText10 == null) {
                n.LIZ("");
            }
            editText10.setFocusableInTouchMode(false);
            4ZZ r0 = this.LJIIJJI;
            if (r0 == null) {
                n.LIZ("");
            }
            r0.setVisibility(8);
        }
        LJIIIIZZ();
        if (TextUtils.isEmpty(this.LJIJI)) {
            TextView textView2 = this.LJIIL;
            if (textView2 == null) {
                n.LIZ("");
            }
            textView2.setVisibility(8);
        } else {
            TextView textView3 = this.LJIIL;
            if (textView3 == null) {
                n.LIZ("");
            }
            textView3.setVisibility(0);
            TextView textView4 = this.LJIIL;
            if (textView4 == null) {
                n.LIZ("");
            }
            textView4.setText(this.LJIJI);
        }
        if (this.LIZJ > 0) {
            LJI().setVisibility(0);
            TextView LJI2 = LJI();
            Object[] objArr = new Object[2];
            if (TextUtils.isEmpty(this.LIZ)) {
                intValue = 0;
            } else {
                String str = this.LIZ;
                if (str != null) {
                    num = Integer.valueOf(str.length());
                }
                intValue = num.intValue();
            }
            objArr[0] = Integer.valueOf(intValue);
            objArr[1] = Integer.valueOf(this.LIZJ);
            LJI2.setText(getString(2131822477, objArr));
        }
        EditText editText11 = this.LJIIJ;
        if (editText11 == null) {
            n.LIZ("");
        }
        editText11.setOnEditorActionListener(OR1.LIZ);
        return LIZ2;
    }
}
