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

import X.0HH;
import X.1hK;
import X.2cN;
import X.2uR;
import X.3c7;
import X.3c9;
import X.3cC;
import X.3cI;
import X.4Dd;
import X.4ZZ;
import X.C1079Mjy;
import X.C1083Mk2;
import X.C1084Mk3;
import X.C5318OQv;
import X.C5320OQx;
import X.DLh;
import X.DM8;
import X.DM9;
import X.DUE;
import X.JJh;
import X.M12;
import X.OPA;
import X.PhE;
import X.Pkb;
import X.PlI;
import android.app.Dialog;
import android.os.Bundle;
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 java.util.concurrent.TimeUnit;
import kotlin.h.b.n;

public final class ProfileEditBioFragment extends ProfileEditInputFragment {
    public static final DUE LJIIIIZZ = new DUE((byte) 0);
    public String LIZ = "";
    public Pkb<Object> LIZIZ;
    public String LIZJ;
    public String LIZLLL;
    public EditText LJFF;
    public 4ZZ LJI;
    public TextView LJII;
    public String LJIIIZ = "";
    public C1079Mjy LJIIJ;
    public DLh LJIIJJI;
    public SparseArray LJIIL;

    static {
        Covode.recordClassIndex(99051);
    }

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

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

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

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

    public final void onDestroy() {
        ProfileEditBioFragment.super.onDestroy();
        this.LJIIJ.LIZ();
    }

    public ProfileEditBioFragment() {
        Pkb<Object> pkb = new Pkb<>();
        n.LIZIZ(pkb, "");
        this.LIZIZ = pkb;
        this.LJIIJ = new C1079Mjy();
        this.LIZJ = "";
        this.LIZLLL = "";
    }

    public final boolean dn_() {
        Dialog dialog;
        EditText editText = this.LJFF;
        if (editText == null) {
            n.LIZ("");
        }
        KeyboardUtils.LIZJ(editText);
        if (getDialog() != null && (dialog = getDialog()) != null && dialog.isShowing() && isResumed()) {
            try {
                dismiss();
            } catch (Exception e) {
                0HH.LIZ(e);
            }
        }
        return true;
    }

    public final void LJ() {
        int i;
        boolean z;
        DLh dLh = this.LJIIJJI;
        if (dLh != null) {
            EditText editText = this.LJFF;
            if (editText == null) {
                n.LIZ("");
            }
            String obj = editText.getText().toString();
            int length = obj.length() - 1;
            int i2 = 0;
            boolean z2 = false;
            while (i2 <= length) {
                if (!z2) {
                    i = i2;
                } else {
                    i = length;
                }
                if (n.LIZ(obj.charAt(i), 32) <= 0) {
                    z = true;
                } else {
                    z = false;
                }
                if (z2) {
                    if (!z) {
                        break;
                    }
                    length--;
                } else if (!z) {
                    z2 = true;
                } else {
                    i2++;
                }
            }
            dLh.LIZ(obj.subSequence(i2, length + 1).toString());
        }
    }

    public final void LIZ(DLh dLh) {
        M12.LIZ(dLh);
        this.LJIIJJI = dLh;
    }

    public final void onCreate(Bundle bundle) {
        String str;
        ProfileEditBioFragment.super.onCreate(bundle);
        if (getArguments() != null) {
            Bundle arguments = getArguments();
            if (arguments == null) {
                n.LIZIZ();
            }
            String string = arguments.getString("content_name");
            if (string == null) {
                n.LIZIZ();
            }
            this.LJIIIZ = string;
            Bundle arguments2 = getArguments();
            if (arguments2 == null) {
                n.LIZIZ();
            }
            String string2 = arguments2.getString("content_value");
            if (string2 == null) {
                n.LIZIZ();
            }
            this.LIZ = string2;
            Bundle arguments3 = getArguments();
            String str2 = null;
            if (arguments3 != null) {
                str = arguments3.getString("enter_method");
            } else {
                str = null;
            }
            this.LIZJ = str;
            Bundle arguments4 = getArguments();
            if (arguments4 != null) {
                str2 = arguments4.getString("btn_name");
            }
            this.LIZLLL = str2;
        }
    }

    public final View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        Window window;
        M12.LIZ(layoutInflater);
        View LIZ2 = 0HH.LIZ(layoutInflater, 2131560794, viewGroup, false);
        JJh jJh = JJh.LIZ;
        1hK activity = getActivity();
        Dialog dialog = getDialog();
        if (dialog != null) {
            window = dialog.getWindow();
        } else {
            window = null;
        }
        jJh.LIZ(activity, window, true);
        View findViewById = LIZ2.findViewById(2131364628);
        n.LIZIZ(findViewById, "");
        this.LJFF = (EditText) findViewById;
        4ZZ findViewById2 = LIZ2.findViewById(2131366351);
        n.LIZIZ(findViewById2, "");
        this.LJI = findViewById2;
        View findViewById3 = LIZ2.findViewById(2131371951);
        n.LIZIZ(findViewById3, "");
        LIZ((TextView) findViewById3);
        View findViewById4 = LIZ2.findViewById(2131371949);
        n.LIZIZ(findViewById4, "");
        this.LJII = (TextView) findViewById4;
        View findViewById5 = LIZ2.findViewById(2131366351);
        if (findViewById5 != null) {
            findViewById5.setOnClickListener(new C5320OQx(this));
        }
        LJI().setVisibility(0);
        4ZZ r1 = this.LJI;
        if (r1 == null) {
            n.LIZ("");
        }
        r1.setVisibility(8);
        4ZZ r12 = this.LJI;
        if (r12 == null) {
            n.LIZ("");
        }
        r12.setIconRes(2131755737);
        2cN LIZ3 = this.LIZIZ.LJI(3000, TimeUnit.MILLISECONDS).LIZIZ(PhE.LIZIZ(PlI.LIZJ)).LIZ(C1083Mk2.LIZ(C1084Mk3.LIZ)).LIZ(new DM8(LIZ2), DM9.LIZ);
        n.LIZIZ(LIZ3, "");
        4Dd.LIZ(LIZ3, this.LJIIJ);
        EditText editText = this.LJFF;
        if (editText == null) {
            n.LIZ("");
        }
        editText.addTextChangedListener(new C5318OQv(this));
        EditText editText2 = this.LJFF;
        if (editText2 == null) {
            n.LIZ("");
        }
        editText2.setText(this.LIZ);
        EditText editText3 = this.LJFF;
        if (editText3 == null) {
            n.LIZ("");
        }
        EditText editText4 = this.LJFF;
        if (editText4 == null) {
            n.LIZ("");
        }
        editText3.setSelection(editText4.getText().length());
        EditText editText5 = this.LJFF;
        if (editText5 == null) {
            n.LIZ("");
        }
        editText5.setFocusable(true);
        EditText editText6 = this.LJFF;
        if (editText6 == null) {
            n.LIZ("");
        }
        editText6.setFocusableInTouchMode(true);
        EditText editText7 = this.LJFF;
        if (editText7 == null) {
            n.LIZ("");
        }
        editText7.requestFocus();
        this.LJIILLIIL = LIZ2.findViewById(2131367895);
        3cI LJIIIZ2 = LJIIIZ();
        3cC LIZIZ2 = LIZIZ(this.LJIIIZ);
        3cI r3 = new 3c9();
        r3.LIZ("save");
        String string = getString(2131821109);
        n.LIZIZ(string, "");
        r3.LIZ(string);
        r3.LIZ(new OPA(this));
        3c7 r2 = this.LJIILLIIL;
        if (r2 != null) {
            2uR r13 = new 2uR();
            r13.LIZ(new 3cI[]{LJIIIZ2});
            r13.LIZ(LIZIZ2);
            r13.LIZIZ(new 3cI[]{r3});
            r13.LIZLLL = true;
            r2.setNavActions(r13);
        }
        LJIIIIZZ();
        return LIZ2;
    }
}
