package com.ss.android.ugc.aweme;

import X.0HH;
import X.2QX;
import X.BbC;
import X.C0438Ffw;
import X.C0550Fke;
import X.C0568Fkw;
import X.C0569Fkx;
import X.C0570Fky;
import X.C0571Fkz;
import X.C5l;
import X.C5m;
import X.EXa;
import X.EkW;
import X.FkB;
import X.FkL;
import X.FkX;
import X.Fl0;
import X.Fl1;
import X.Fl2;
import X.Fl3;
import X.Fl4;
import X.FlB;
import X.LeY;
import X.Lea;
import X.Led;
import X.M12;
import X.Oev;
import X.Qeg;
import android.content.Context;
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.widget.EditText;
import android.widget.ImageView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.api.model.AnchorCell;
import java.util.List;
import java.util.Objects;
import kotlin.h.b.n;
import kotlin.o.z;

public final class AnchorSearchFragment extends AnchorBaseFragment implements BbC<AnchorCell>, C5m {
    public static final Fl4 LJFF = new Fl4((byte) 0);
    public Fl0 LIZLLL;
    public FkL LJ;
    public EXa<FlB> LJI;
    public FlB LJII;
    public FkL LJIIIIZZ;
    public Oev<RecyclerView.ViewHolder> LJIIIZ;
    public SparseArray LJIIJ;

    static {
        Covode.recordClassIndex(50302);
    }

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

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

    public final void LIZ(Exception exc) {
    }

    public final void LIZJ(List<AnchorCell> list, boolean z) {
    }

    public final void cn_() {
    }

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

    public final boolean LJII() {
        Oev<RecyclerView.ViewHolder> oev = this.LJIIIZ;
        if (oev == null || oev.LIZ != 0) {
            return true;
        }
        return false;
    }

    public final void bw_() {
        Oev<RecyclerView.ViewHolder> oev = this.LJIIIZ;
        if (oev != null) {
            oev.LIZ(1);
        }
    }

    public final void onDestroy() {
        EXa<FlB> eXa = this.LJI;
        if (eXa != null) {
            eXa.do_();
            eXa.LJIIIIZZ();
        }
        AnchorSearchFragment.super.onDestroy();
    }

    public final void LIZIZ() {
        EkW LIZ = LIZ(2131367423);
        n.LIZIZ(LIZ, "");
        LIZ.setVisibility(0);
    }

    public final void LIZJ() {
        String[] LIZ;
        Fl0 fl0 = this.LIZLLL;
        if (fl0 != null && (LIZ = fl0.LIZ()) != null) {
            List LJIIJJI = LeY.LJIIJJI(LIZ);
            FkL fkL = this.LJ;
            if (fkL == null) {
                n.LIZ("");
            } else {
                fkL.LIZ((List<?>) LJIIJJI);
            }
            FkL fkL2 = this.LJ;
            if (fkL2 == null) {
                n.LIZ("");
            } else {
                fkL2.notifyDataSetChanged();
            }
            if (LJIIJJI.size() > 2) {
                Qeg LIZ2 = LIZ(2131363365);
                n.LIZIZ(LIZ2, "");
                LIZ2.setVisibility(0);
            }
        }
    }

    public final void bN_() {
        EditText editText = (EditText) LIZ(2131369902);
        n.LIZIZ(editText, "");
        String obj = editText.getText().toString();
        Objects.requireNonNull(obj, "null cannot be cast to non-null type kotlin.CharSequence");
        String obj2 = z.LIZIZ(obj).toString();
        EXa<FlB> eXa = this.LJI;
        if (eXa != null) {
            eXa.LIZ(new Object[]{4, obj2});
        }
    }

    public final void LJFF() {
        Qeg LIZ = LIZ(2131372532);
        n.LIZIZ(LIZ, "");
        LIZ.setVisibility(0);
        Qeg LIZ2 = LIZ(2131372531);
        n.LIZIZ(LIZ2, "");
        LIZ2.setVisibility(0);
        EkW LIZ3 = LIZ(2131367423);
        n.LIZIZ(LIZ3, "");
        LIZ3.setVisibility(8);
        RecyclerView LIZ4 = LIZ(2131369394);
        n.LIZIZ(LIZ4, "");
        LIZ4.setVisibility(8);
        Oev<RecyclerView.ViewHolder> oev = this.LJIIIZ;
        if (oev != null) {
            oev.LIZ(0);
        }
    }

    public final void LIZLLL() {
        EXa<FlB> eXa = this.LJI;
        if (eXa != null) {
            EditText editText = (EditText) LIZ(2131369902);
            n.LIZIZ(editText, "");
            String obj = editText.getText().toString();
            Objects.requireNonNull(obj, "null cannot be cast to non-null type kotlin.CharSequence");
            String obj2 = z.LIZIZ(obj).toString();
            if (!TextUtils.isEmpty(obj2)) {
                eXa.LIZ(new Object[]{1, obj2});
                RecyclerView LIZ = LIZ(2131369393);
                n.LIZIZ(LIZ, "");
                LIZ.setVisibility(8);
                Qeg LIZ2 = LIZ(2131363365);
                n.LIZIZ(LIZ2, "");
                LIZ2.setVisibility(8);
                2QX.LIZIZ(getContext(), LIZ(2131369902));
                Fl0 fl0 = this.LIZLLL;
                if (fl0 != null) {
                    M12.LIZ(obj2);
                    String[] stringArray = fl0.LIZ.getStringArray(fl0.LIZIZ, new String[0]);
                    n.LIZIZ(stringArray, "");
                    Object[] array = Lea.LIZLLL(LeY.LJIILIIL(Led.LIZ(new String[]{obj2}, stringArray)), 10).toArray(new String[0]);
                    Objects.requireNonNull(array, "null cannot be cast to non-null type kotlin.Array<T>");
                    fl0.LIZ.storeStringArray(fl0.LIZIZ, (String[]) array);
                }
            }
        }
    }

    public static final /* synthetic */ FkL LIZ(AnchorSearchFragment anchorSearchFragment) {
        FkL fkL = anchorSearchFragment.LJ;
        if (fkL == null) {
            n.LIZ("");
        }
        return fkL;
    }

    public final void LIZIZ(Exception exc) {
        Oev<RecyclerView.ViewHolder> oev = this.LJIIIZ;
        if (oev != null) {
            oev.LIZ(0);
        }
    }

    public final void LIZJ(Exception exc) {
        Oev<RecyclerView.ViewHolder> oev = this.LJIIIZ;
        if (oev != null) {
            oev.LIZ(2);
        }
    }

    public final void LIZ(boolean z) {
        Oev<RecyclerView.ViewHolder> oev = this.LJIIIZ;
        if (oev != null) {
            oev.LIZ(z ? 1 : 0);
        }
    }

    public final void onHiddenChanged(boolean z) {
        AnchorSearchFragment.super.onHiddenChanged(z);
        if (z) {
            EditText editText = (EditText) LIZ(2131369902);
            n.LIZIZ(editText, "");
            editText.getText().clear();
            2QX.LIZIZ(getContext(), LIZ(2131369902));
        }
    }

    public final void onActivityCreated(Bundle bundle) {
        String str;
        super.onActivityCreated(bundle);
        FkL fkL = new FkL();
        C0438Ffw activity = getActivity();
        Objects.requireNonNull(activity, "null cannot be cast to non-null type com.ss.android.ugc.aweme.IFragmentNavigation");
        FkX fkX = new FkX(activity);
        fkX.LIZ = new C0571Fkz(fkL, this);
        fkX.LIZLLL = new C0568Fkw(fkL, this);
        fkL.LIZ(String.class, fkX);
        this.LJ = fkL;
        FkB LIZ = C0550Fke.LIZ.LIZ(getActivity(), AnchorBaseFragment.LIZIZ);
        FkL fkL2 = new FkL();
        LIZ.LIZ(fkL2, LIZ.LIZ, "search_result");
        this.LJIIIIZZ = fkL2;
        this.LJI = new EXa<>();
        this.LIZLLL = new Fl0(this, "anchor_search_history" + AnchorBaseFragment.LIZIZ.name());
        this.LJII = new FlB(AnchorBaseFragment.LIZIZ.getTYPE());
        EXa<FlB> eXa = this.LJI;
        if (eXa != null) {
            eXa.a_(this);
        }
        EXa<FlB> eXa2 = this.LJI;
        if (eXa2 != null) {
            eXa2.LIZ(this.LJII);
        }
        LIZ(2131363133).setOnClickListener(new Fl3(this));
        EditText editText = (EditText) LIZ(2131369902);
        n.LIZIZ(editText, "");
        Context context = getContext();
        if (context != null) {
            C0550Fke.LIZ.LIZ(AnchorBaseFragment.LIZIZ);
            str = context.getString(2131822955);
        } else {
            str = null;
        }
        editText.setHint(str);
        EditText editText2 = (EditText) LIZ(2131369902);
        n.LIZIZ(editText2, "");
        editText2.setImeOptions(3);
        EditText editText3 = (EditText) LIZ(2131369902);
        n.LIZIZ(editText3, "");
        editText3.setInputType(1);
        ((EditText) LIZ(2131369902)).setOnEditorActionListener(new Fl1(this));
        ((EditText) LIZ(2131369902)).addTextChangedListener(new C0569Fkx(this));
        EditText editText4 = (EditText) LIZ(2131369902);
        n.LIZIZ(editText4, "");
        editText4.setFocusable(true);
        EditText editText5 = (EditText) LIZ(2131369902);
        n.LIZIZ(editText5, "");
        editText5.setFocusableInTouchMode(true);
        ((EditText) LIZ(2131369902)).requestFocus();
        2QX.LIZ(getContext(), LIZ(2131369902));
        ((ImageView) LIZ(2131369901)).setOnClickListener(new Fl2(this));
        LIZ(2131363365).setOnClickListener(new C0570Fky(this));
        this.LJIIIZ = Oev.LIZ(this.LJIIIIZZ);
        RecyclerView LIZ2 = LIZ(2131369394);
        n.LIZIZ(LIZ2, "");
        getContext();
        LIZ2.setLayoutManager(new LinearLayoutManager());
        RecyclerView LIZ3 = LIZ(2131369394);
        n.LIZIZ(LIZ3, "");
        LIZ3.setAdapter(this.LJIIIZ);
        RecyclerView LIZ4 = LIZ(2131369394);
        n.LIZIZ(LIZ4, "");
        LIZ4.setOnFlingListener(new C5l(LIZ(2131369394), this));
        RecyclerView LIZ5 = LIZ(2131369393);
        n.LIZIZ(LIZ5, "");
        getContext();
        LIZ5.setLayoutManager(new LinearLayoutManager());
        RecyclerView LIZ6 = LIZ(2131369393);
        n.LIZIZ(LIZ6, "");
        FkL fkL3 = this.LJ;
        if (fkL3 == null) {
            n.LIZ("");
        }
        LIZ6.setAdapter(fkL3);
        LIZJ();
    }

    public final void LIZIZ(List<AnchorCell> list, boolean z) {
        FkL fkL;
        if (!(list == null || list.isEmpty() || (fkL = this.LJIIIIZZ) == null)) {
            fkL.LIZ((List<?>) list);
        }
        Oev<RecyclerView.ViewHolder> oev = this.LJIIIZ;
        if (oev != null) {
            oev.LIZ(z ? 1 : 0);
        }
        FkL fkL2 = this.LJIIIIZZ;
        if (fkL2 != null) {
            fkL2.notifyDataSetChanged();
        }
        C0550Fke.LIZ.LIZIZ(AnchorBaseFragment.LIZIZ);
    }

    public final void LIZ(List<AnchorCell> list, boolean z) {
        Qeg LIZ = LIZ(2131372532);
        n.LIZIZ(LIZ, "");
        LIZ.setVisibility(8);
        Qeg LIZ2 = LIZ(2131372531);
        n.LIZIZ(LIZ2, "");
        LIZ2.setVisibility(8);
        EkW LIZ3 = LIZ(2131367423);
        n.LIZIZ(LIZ3, "");
        LIZ3.setVisibility(8);
        RecyclerView LIZ4 = LIZ(2131369394);
        n.LIZIZ(LIZ4, "");
        LIZ4.setVisibility(0);
        if (list != null && !list.isEmpty()) {
            FkL fkL = this.LJIIIIZZ;
            if (fkL != null) {
                fkL.LIZ((List<?>) list);
            }
            Oev<RecyclerView.ViewHolder> oev = this.LJIIIZ;
            if (oev != null) {
                oev.LIZ(z ? 1 : 0);
            }
            FkL fkL2 = this.LJIIIIZZ;
            if (fkL2 != null) {
                fkL2.notifyDataSetChanged();
            }
            C0550Fke.LIZ.LIZIZ(AnchorBaseFragment.LIZIZ);
        }
    }

    public final View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        M12.LIZ(layoutInflater);
        return 0HH.LIZ(layoutInflater, 2131558467, viewGroup, false);
    }
}
