package com.ss.android.ugc.aweme.choosemusic.sug;

import X.0Bs;
import X.0Bv;
import X.0Bx;
import X.0By;
import X.0CM;
import X.0EB;
import X.0HH;
import X.1hK;
import X.2GD;
import X.2GO;
import X.2HZ;
import X.2UX;
import X.2ce;
import X.2nK;
import X.9oY;
import X.C5772OdT;
import X.C5785Odg;
import X.C5797Ods;
import X.C5813Oe8;
import X.C5817OeC;
import X.C5822OeH;
import X.C5823OeI;
import X.C5827OeM;
import X.C5828OeN;
import X.C5829OeO;
import X.CDg;
import X.DZp;
import X.DaP;
import X.ISm;
import X.M12;
import X.Rc9;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.RecyclerView;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.choosemusic.SearchMusicBaseFragment;
import com.ss.android.ugc.aweme.discover.model.suggest.Word;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import kotlin.h.b.n;
import org.greenrobot.eventbus.ThreadMode;

public final class SearchMusicSugFragment extends SearchMusicBaseFragment implements C5829OeO, 2HZ, 2GO {
    public static final C5785Odg LJIIJJI = new C5785Odg((byte) 0);
    public MusicSugViewModel LIZJ;
    public final ArrayList<CDg> LIZLLL = new ArrayList<>();
    public final ArrayList<DaP> LJ = new ArrayList<>();
    public String LJIIIZ = "";
    public C5828OeN LJIIJ;
    public final 0CM<C5827OeM<C5823OeI>> LJIIL = new C5817OeC(this);
    public SparseArray LJIILIIL;

    static {
        Covode.recordClassIndex(56347);
    }

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

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

    public final boolean LJJIJIIJI() {
        return true;
    }

    public final Map<Integer, Object> getSubscriberEventTypes() {
        HashMap hashMap = new HashMap();
        hashMap.put(397, new Rc9(SearchMusicSugFragment.class, "onInputClickEvent", C5797Ods.class, ThreadMode.POSTING, 0, false));
        return hashMap;
    }

    public final void onDestroyView() {
        2ce<C5827OeM<C5823OeI>> r1;
        SearchMusicSugFragment.super.onDestroyView();
        MusicSugViewModel musicSugViewModel = this.LIZJ;
        if (!(musicSugViewModel == null || (r1 = musicSugViewModel.LIZ) == null)) {
            r1.removeObserver(this.LJIIL);
        }
        LIZ();
    }

    public final void LIZ(String str) {
        C5772OdT state;
        M12.LIZ(str);
        ChooseSearchMusicViewModel chooseSearchMusicViewModel = this.LIZIZ;
        if (chooseSearchMusicViewModel != null && (state = chooseSearchMusicViewModel.getState()) != null && state.LIZLLL) {
            LIZIZ(str);
        }
    }

    public final void LIZIZ(int i) {
        DZp LIZ = LIZ(2131368752);
        n.LIZIZ(LIZ, "");
        LIZ.getState().LIZ(i);
    }

    public final void LIZIZ(String str) {
        C5772OdT state;
        ChooseSearchMusicViewModel chooseSearchMusicViewModel = this.LIZIZ;
        if (chooseSearchMusicViewModel != null && (state = chooseSearchMusicViewModel.getState()) != null && 2 == state.LIZ && !TextUtils.isEmpty(str)) {
            new Handler().postDelayed(new C5813Oe8(this, str), 150);
        }
    }

    @ISm
    public final void onInputClickEvent(C5797Ods ods) {
        String str;
        CDg next;
        Integer num;
        String str2;
        M12.LIZ(ods);
        String str3 = this.LIZ;
        Iterator<CDg> it = this.LIZLLL.iterator();
        do {
            str = null;
            if (it.hasNext()) {
                next = it.next();
                n.LIZIZ(next, "");
            } else {
                return;
            }
        } while (!TextUtils.equals(next.LIZIZ, str3));
        M12.LIZ(next);
        C5822OeH oeH = new C5822OeH();
        oeH.LIZ("words_source", "sug");
        oeH.LIZ("search_position", "music_create");
        Word word = next.LJFF;
        if (word != null) {
            num = Integer.valueOf(word.getWordPosition());
        } else {
            num = null;
        }
        oeH.LIZ("words_position", (Object) num);
        oeH.LIZ("impr_id", this.LJIIIZ);
        oeH.LIZ("raw_query", this.LIZ);
        oeH.LIZ("words_content", this.LIZ);
        C5828OeN oeN = this.LJIIJ;
        if (oeN != null) {
            str2 = oeN.getQueryId();
        } else {
            str2 = null;
        }
        oeH.LIZ("query_id", str2);
        Word word2 = next.LJFF;
        if (word2 != null) {
            str = word2.getId();
        }
        oeH.LIZ("group_id", str);
        2nK.LIZ("sug_input_click", oeH.LIZ);
    }

    public final void LIZ(int i, String str) {
        String LIZ = 9oY.LIZ.LIZ(this.LJIIIZ);
        2UX r2 = new 2UX();
        r2.LIZ("action_type", "click");
        r2.LIZ("log_pb", LIZ);
        r2.LIZ("sug_keyword", this.LIZ);
        r2.LIZ("search_keyword", str);
        r2.LIZ("search_type", "video_music");
        r2.LIZ("order", i);
        2nK.LIZ("search_sug", r2.LIZ);
    }

    public final void onViewCreated(View view, Bundle bundle) {
        String str;
        2ce<C5827OeM<C5823OeI>> r1;
        M12.LIZ(view);
        SearchMusicSugFragment.super.onViewCreated(view, bundle);
        1hK activity = getActivity();
        if (activity != null) {
            0Bx LIZ = 0By.LIZ(activity, (0Bv) null);
            if (2GD.LIZ) {
                0Bs.LIZ(LIZ, activity);
            }
            MusicSugViewModel LIZ2 = LIZ.LIZ(MusicSugViewModel.class);
            this.LIZJ = LIZ2;
            if (!(LIZ2 == null || (r1 = LIZ2.LIZ) == null)) {
                r1.observe(activity, this.LJIIL);
            }
        }
        Bundle arguments = getArguments();
        if (arguments != null) {
            str = arguments.getString("key_word");
        } else {
            str = null;
        }
        this.LIZ = str;
        RecyclerView LIZ3 = LIZ(2131368752);
        n.LIZIZ(LIZ3, "");
        LIZ3.setNestedScrollingEnabled(true);
        RecyclerView LIZ4 = LIZ(2131368752);
        n.LIZIZ(LIZ4, "");
        LIZ4.setItemAnimator((0EB) null);
        LIZ(2131368752).LIZ(new Class[]{SearchMusicSugCell.class, SearchMusicSugHistoryCell.class});
    }

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