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

import X.0Bs;
import X.0Bv;
import X.0Bx;
import X.0By;
import X.0E3;
import X.0Gf;
import X.0Gp;
import X.0HH;
import X.1hK;
import X.2GD;
import X.2Kx;
import X.2UX;
import X.3BB;
import X.4q6;
import X.7vm;
import X.8Yz;
import X.9oY;
import X.BCt;
import X.BCu;
import X.BSx;
import X.C3328SUa;
import X.C3329SUb;
import X.C3332SUe;
import X.C3341SUn;
import X.C3346SUs;
import X.C3352SUy;
import X.C3383SWd;
import X.C3401SWv;
import X.C3420SXo;
import X.C3442SYk;
import X.C3455SYx;
import X.C3456SYy;
import X.C3459SZb;
import X.C3525Saf;
import X.C3535Sap;
import X.C3537Sar;
import X.C3549Sb3;
import X.C4459Spj;
import X.C4462Spm;
import X.C4592Srs;
import X.CDf;
import X.CDg;
import X.CEA;
import X.Cg1;
import X.Crj;
import X.Js0;
import X.Ldl;
import X.LeS;
import X.Lea;
import X.M12;
import X.MGq;
import X.MH5;
import X.MJC;
import X.MKU;
import X.MKv;
import X.MKw;
import X.MWv;
import X.OfH;
import X.SV0;
import X.SV5;
import X.SV6;
import X.SW5;
import X.SW6;
import X.SWS;
import X.SWV;
import X.SX1;
import X.SX7;
import X.SX8;
import X.SXD;
import X.SXI;
import X.SXK;
import X.SYQ;
import X.SYX;
import X.SYY;
import X.SZ1;
import X.SZ5;
import X.SZ6;
import X.SZC;
import X.SZF;
import X.SZR;
import X.SZY;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
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 androidx.recyclerview.widget.RecyclerView;
import com.bytedance.covode.number.Covode;
import com.bytedance.router.SmartRoute;
import com.bytedance.router.SmartRouter;
import com.ss.android.ugc.aweme.base.fragment.AmeBaseFragment;
import com.ss.android.ugc.aweme.discover.mob.helpers.SearchSugMobHelper;
import com.ss.android.ugc.aweme.discover.model.ISearchHistoryManager;
import com.ss.android.ugc.aweme.discover.model.SearchHistory;
import com.ss.android.ugc.aweme.discover.model.SearchIntermediateViewModel;
import com.ss.android.ugc.aweme.discover.model.SearchStateViewModel;
import com.ss.android.ugc.aweme.discover.model.SearchSugResponse;
import com.ss.android.ugc.aweme.discover.model.suggest.RecommendWordMob;
import com.ss.android.ugc.aweme.discover.model.suggest.Word;
import com.ss.android.ugc.aweme.discover.viewmodel.SearchEnterViewModel;
import com.ss.android.ugc.aweme.feed.model.LogPbBean;
import com.ss.android.ugc.aweme.keyword.SearchKeywordPresenter;
import com.ss.android.ugc.aweme.search.keyword.SugKeywordPresenter;
import com.ss.android.ugc.aweme.views.WrapLinearLayoutManager;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CopyOnWriteArrayList;
import kotlin.h.b.n;
import org.greenrobot.eventbus.EventBus;

public abstract class AbstractSearchIntermediateFragment extends AmeBaseFragment implements C3537Sar, C3383SWd, C4592Srs {
    public static final C3549Sb3 LJIILIIL = new C3549Sb3((byte) 0);
    public OfH LIZ;
    public RecyclerView LIZIZ;
    public ViewGroup LIZJ;
    public SearchIntermediateViewModel LIZLLL;
    public SearchStateViewModel LJ;
    public int LJIIIZ;
    public String LJIIJ = "";
    public SearchSugMobHelper LJIIJJI;
    public int LJIIL;
    public final Crj LJIILJJIL = 7vm.LIZ(new SZF(this));
    public SWV LJIILL;
    public SearchKeywordPresenter LJIIZILJ;
    public SugKeywordPresenter LJIJ;
    public final Crj LJIJI = 7vm.LIZ(new SZC(this));
    public final Crj LJIJJ = 7vm.LIZ(SZ1.LIZ);
    public Integer LJIJJLI;
    public boolean LJIL;
    public SparseArray LJJ;

    static {
        Covode.recordClassIndex(65346);
    }

    public final C3459SZb LJFF() {
        return (C3459SZb) this.LJIILJJIL.getValue();
    }

    public final ISearchHistoryManager LJIIIIZZ() {
        return (ISearchHistoryManager) this.LJIJI.getValue();
    }

    public final CopyOnWriteArrayList<SearchHistory> LJIIIZ() {
        return (CopyOnWriteArrayList) this.LJIJJ.getValue();
    }

    public void LJJI() {
        SparseArray sparseArray = this.LJJ;
        if (sparseArray != null) {
            sparseArray.clear();
        }
    }

    public boolean LJJIJIIJI() {
        return true;
    }

    public /* synthetic */ void onDestroyView() {
        AbstractSearchIntermediateFragment.super.onDestroyView();
        LJJI();
    }

    public final void LIZ(String str, String str2, String str3) {
        SmartRoute buildRoute = SmartRouter.buildRoute(getContext(), "aweme://user/profile/");
        buildRoute.withParam("sec_user_id", str);
        buildRoute.withParam("uid", str2);
        buildRoute.withParam("enter_from", "search_most_visited");
        buildRoute.withCallback(new SZ5(this, str3));
        buildRoute.open(1, new SZY(this));
    }

    public final void LIZ(SearchSugResponse searchSugResponse, boolean z) {
        M12.LIZ(searchSugResponse);
        if (!z) {
            long longValue = searchSugResponse.requestOrder.longValue();
            Long l = SWV.LIZJ;
            n.LIZIZ(l, "");
            if (longValue < l.longValue() && MGq.LIZ.LIZ() == 1) {
                C3442SYk sYk = new C3442SYk();
                sYk.LJIJJ("sug_order_failed");
                sYk.LJFF();
                return;
            }
        }
        SWV.LIZJ = searchSugResponse.requestOrder;
        if (aq_()) {
            RecyclerView recyclerView = this.LIZIZ;
            if (recyclerView == null) {
                n.LIZ("");
            }
            if (recyclerView.getAdapter() instanceof C3459SZb) {
                LJFF().LIZJ = searchSugResponse.requestSource;
                LJFF().LIZIZ = searchSugResponse.requestId;
                LJFF().LJII = searchSugResponse.keyword;
                SearchSugMobHelper searchSugMobHelper = this.LJIIJJI;
                if (searchSugMobHelper != null) {
                    searchSugMobHelper.LIZ = searchSugResponse.logPb;
                }
                SearchSugMobHelper searchSugMobHelper2 = this.LJIIJJI;
                if (searchSugMobHelper2 != null) {
                    searchSugMobHelper2.LIZLLL = searchSugResponse.recommendWordMob;
                }
                0Gp.LIZ(new SX1(this, searchSugResponse)).LIZ(new SXI(this, z, searchSugResponse), 0Gp.LIZIZ, (0Gf) null);
            }
        }
    }

    public int LIZ() {
        return SearchHistory.toHistoryType(Integer.MIN_VALUE);
    }

    public void onPause() {
        AbstractSearchIntermediateFragment.super.onPause();
        C4462Spm.LJFF();
    }

    private final String LJJIFFI() {
        String LIZ2;
        SugKeywordPresenter sugKeywordPresenter = this.LJIJ;
        if (sugKeywordPresenter == null || (LIZ2 = sugKeywordPresenter.LIZ()) == null) {
            return "";
        }
        return LIZ2;
    }

    public final RecyclerView LIZLLL() {
        RecyclerView recyclerView = this.LIZIZ;
        if (recyclerView == null) {
            n.LIZ("");
        }
        return recyclerView;
    }

    public final ViewGroup LJ() {
        ViewGroup viewGroup = this.LIZJ;
        if (viewGroup == null) {
            n.LIZ("");
        }
        return viewGroup;
    }

    public final SearchIntermediateViewModel LJI() {
        SearchIntermediateViewModel searchIntermediateViewModel = this.LIZLLL;
        if (searchIntermediateViewModel == null) {
            n.LIZ("");
        }
        return searchIntermediateViewModel;
    }

    public final SearchStateViewModel LJII() {
        SearchStateViewModel searchStateViewModel = this.LJ;
        if (searchStateViewModel == null) {
            n.LIZ("");
        }
        return searchStateViewModel;
    }

    public void LJIILIIL() {
        SWV swv = new SWV();
        this.LJIILL = swv;
        swv.a_(this);
    }

    public final String LJIJI() {
        return C3352SUy.LIZIZ(LJIJJLI());
    }

    public void LJIIL() {
        LJFF().LJ = this;
        LJFF().LIZLLL = LJIIZILJ();
    }

    public final List<SearchHistory> LJIJ() {
        List<SearchHistory> searchHistoryByType = LJIIIIZZ().getSearchHistoryByType(SearchHistory.toHistoryType(Integer.MIN_VALUE));
        n.LIZIZ(searchHistoryByType, "");
        return searchHistoryByType;
    }

    public final int LJIJJLI() {
        SearchIntermediateViewModel searchIntermediateViewModel = this.LIZLLL;
        if (searchIntermediateViewModel == null) {
            n.LIZ("");
        }
        Integer num = (Integer) searchIntermediateViewModel.getSearchTabIndex().getValue();
        if (num != null) {
            return num.intValue();
        }
        return -1;
    }

    public void onStart() {
        AbstractSearchIntermediateFragment.super.onStart();
        if (LJJIJIIJI()) {
            EventBus LIZ2 = EventBus.LIZ();
            if (!LIZ2.LIZ((Object) this)) {
                EventBus.LIZ(LIZ2, (Object) this);
            }
        }
    }

    public final String LJIIZILJ() {
        String enterSearchFrom;
        SV5 sv5 = SearchEnterViewModel.LIZJ.LIZ(getActivity()).LIZ;
        if (sv5 == null || TextUtils.isEmpty(sv5.getEnterSearchFrom()) || (enterSearchFrom = sv5.getEnterSearchFrom()) == null) {
            return "";
        }
        return enterSearchFrom;
    }

    public final void LJIL() {
        String LIZ2 = 9oY.LIZ.LIZ(LJFF().LIZIZ);
        SYX syx = new SYX();
        syx.LJIJI("show");
        syx.LJIJJ(LJJIFFI());
        syx.LIZJ(LIZ2);
        syx.LJFF(C3352SUy.LIZIZ(LJIJJLI()));
        syx.LJFF();
    }

    public final String LJJ() {
        Object obtainLogData = SearchEnterViewModel.LIZJ.LIZ(getActivity()).LIZIZ().obtainLogData("search_position");
        if (obtainLogData != null) {
            return obtainLogData.toString();
        }
        String LIZ2 = C3352SUy.LIZ(LJIJJLI());
        if (TextUtils.isEmpty(LIZ2)) {
            return LJIIZILJ();
        }
        return LIZ2;
    }

    public final void bP_() {
        if (getActivity() != null) {
            1hK activity = getActivity();
            if (activity == null) {
                n.LIZIZ();
            }
            n.LIZIZ(activity, "");
            if (!activity.isFinishing()) {
                C3442SYk sYk = new C3442SYk();
                sYk.LJIJJ("no_data");
                sYk.LJFF();
                3BB r1 = new 3BB(getContext());
                r1.LIZIZ(2131827469);
                r1.LIZIZ();
            }
        }
    }

    public void onResume() {
        AbstractSearchIntermediateFragment.super.onResume();
        if (this.LJIIIZ != 0) {
            RecyclerView recyclerView = this.LIZIZ;
            if (recyclerView == null) {
                n.LIZ("");
            }
            if (recyclerView.getAdapter() instanceof C3459SZb) {
                RecyclerView recyclerView2 = this.LIZIZ;
                if (recyclerView2 == null) {
                    n.LIZ("");
                }
                0E3 adapter = recyclerView2.getAdapter();
                Objects.requireNonNull(adapter, "null cannot be cast to non-null type com.ss.android.ugc.aweme.discover.adapter.sug.SearchSugAdapter");
                if (adapter.getItemCount() > 0) {
                    LJIL();
                }
            }
        }
    }

    public void onStop() {
        AbstractSearchIntermediateFragment.super.onStop();
        if (LJJIJIIJI()) {
            EventBus LIZ2 = EventBus.LIZ();
            if (LIZ2.LIZ((Object) this)) {
                LIZ2.LIZIZ((Object) this);
            }
        }
        SearchStateViewModel searchStateViewModel = this.LJ;
        if (searchStateViewModel == null) {
            n.LIZ("");
        }
        searchStateViewModel.setSearchPageVisible(false);
        SearchStateViewModel searchStateViewModel2 = this.LJ;
        if (searchStateViewModel2 == null) {
            n.LIZ("");
        }
        searchStateViewModel2.setIsLeavingSearch(false);
    }

    public final boolean LJIIJ() {
        boolean z;
        if (MJC.LIZ.LIZIZ() == 0) {
            z = true;
        } else {
            z = false;
        }
        if (!z) {
            SearchIntermediateViewModel searchIntermediateViewModel = this.LIZLLL;
            if (searchIntermediateViewModel == null) {
                n.LIZ("");
            }
            if (searchIntermediateViewModel.backFromSearchResult) {
                int LIZIZ2 = MJC.LIZ.LIZIZ();
                if (LIZIZ2 == 2 || LIZIZ2 == 3) {
                    return false;
                }
                return true;
            }
        }
        if (getActivity() == null) {
            return false;
        }
        if (MKw.LIZ || MKv.LIZ) {
            1hK requireActivity = requireActivity();
            n.LIZIZ(requireActivity, "");
            if (SW5.LIZIZ(requireActivity)) {
                return true;
            }
        }
        if (SearchEnterViewModel.LIZJ.LIZ(requireActivity()).LIZ()) {
            return true;
        }
        return false;
    }

    public final boolean LJIIJJI() {
        SW6 searchCommonModel;
        SV6 LIZJ2 = SXD.Companion.LIZJ();
        if (LIZJ2 == null || (searchCommonModel = LIZJ2.getSearchCommonModel()) == null || searchCommonModel.isFromComment() || searchCommonModel.isFromVideo() || !Js0.LIZ || !Lea.LIZ(LeS.LIZIZ(new String[]{"homepage_hot", "homepage_follow", "homepage_friends", "discovery", "homepage_nearby"}), searchCommonModel.getEnterFrom())) {
            return false;
        }
        SearchIntermediateViewModel searchIntermediateViewModel = this.LIZLLL;
        if (searchIntermediateViewModel == null) {
            n.LIZ("");
        }
        searchIntermediateViewModel.getDefaultHintEvent().setValue("setDefault");
        return true;
    }

    public boolean LJIILJJIL() {
        if (!aq_() || !getUserVisibleHint()) {
            return false;
        }
        SearchIntermediateViewModel searchIntermediateViewModel = this.LIZLLL;
        if (searchIntermediateViewModel == null) {
            n.LIZ("");
        }
        Integer num = (Integer) searchIntermediateViewModel.getIntermediateState().getValue();
        if (num == null) {
            return false;
        }
        if (num.intValue() == 1) {
            Ldl.LIZ.LIZ(getContext(), 1, (SV0) null);
            LJIILL();
        } else if (num.intValue() == 2) {
            Ldl.LIZ.LIZ(getContext(), 2, (SV0) null);
            LJIILLIIL();
        } else if (num.intValue() == 0) {
            this.LJIIIZ = 0;
        }
        return true;
    }

    public void LJIILL() {
        this.LJIIIZ = 1;
        this.LJIIJ = "";
        LJIIIZ().clear();
        LJFF().LIZ();
        LJIIIZ().addAll(LJIJ());
        C4462Spm.LJFF();
        if (MH5.LIZ.LIZ() && (getContext() instanceof BCt)) {
            BCt context = getContext();
            Objects.requireNonNull(context, "null cannot be cast to non-null type com.ss.android.ugc.aweme.ainflate.AsyncInflaterOwner");
            BCt bCt = context;
            M12.LIZ(bCt);
            BCu inflater = bCt.getInflater();
            if (inflater == null) {
                return;
            }
            if (!inflater.LIZIZ(2131561151) || !inflater.LIZIZ(2131561150) || !inflater.LIZIZ(2131561152)) {
                8Yz.LIZ.post(new Cg1(bCt));
            }
        }
    }

    public final void bQ_() {
        String str;
        Integer num;
        String str2;
        String str3;
        C3459SZb LJFF = LJFF();
        String LJJIFFI = LJJIFFI();
        String str4 = null;
        if (LJFF.LIZ != null && LJJIFFI.equals(LJFF.LJII)) {
            for (CDg next : LJFF.LIZ) {
                CDf cDf = next.LJI;
                if (cDf != null && cDf.matchQuery()) {
                    SearchSugMobHelper searchSugMobHelper = this.LJIIJJI;
                    if (searchSugMobHelper != null) {
                        M12.LIZ(this, next);
                        if (C4459Spj.LIZ.LIZ((Activity) getActivity())) {
                            str = C3352SUy.LIZ(LJIJJLI());
                        } else {
                            str = "discovery";
                        }
                        C3525Saf saf = new C3525Saf();
                        Word word = next.LJFF;
                        if (word != null) {
                            num = Integer.valueOf(word.getWordPosition());
                        } else {
                            num = null;
                        }
                        saf.LIZLLL(num);
                        saf.LJJI("sug");
                        saf.LJJII(searchSugMobHelper.LIZIZ);
                        saf.LJJIFFI(next.LIZIZ);
                        LogPbBean logPbBean = searchSugMobHelper.LIZ;
                        if (logPbBean != null) {
                            str2 = logPbBean.getImprId();
                        } else {
                            str2 = null;
                        }
                        saf.LIZLLL(str2);
                        RecommendWordMob recommendWordMob = searchSugMobHelper.LIZLLL;
                        if (recommendWordMob != null) {
                            str3 = recommendWordMob.getQueryId();
                        } else {
                            str3 = null;
                        }
                        saf.LJJIIJ(str3);
                        Word word2 = next.LJFF;
                        if (word2 != null) {
                            str4 = word2.getId();
                        }
                        saf.LJIIIIZZ(str4);
                        saf.LJJIII(str);
                        saf.LJFF();
                        return;
                    }
                    return;
                }
            }
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:70:0x0173, code lost:
        if ((r1.getAdapter() instanceof X.C3459SZb) == false) goto L_0x0175;
     */
    /* JADX WARNING: Removed duplicated region for block: B:37:0x00f3  */
    /* JADX WARNING: Removed duplicated region for block: B:40:0x00f8  */
    /* JADX WARNING: Removed duplicated region for block: B:43:0x0104  */
    /* JADX WARNING: Removed duplicated region for block: B:54:0x011f  */
    /* JADX WARNING: Removed duplicated region for block: B:57:0x0135  */
    /* JADX WARNING: Removed duplicated region for block: B:62:0x0155  */
    /* JADX WARNING: Removed duplicated region for block: B:77:0x0187  */
    /* JADX WARNING: Removed duplicated region for block: B:78:0x0191  */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public void LJIILLIIL() {
        /*
            r17 = this;
            r0 = r17
            com.ss.android.ugc.aweme.discover.model.SearchIntermediateViewModel r1 = r0.LIZLLL
            java.lang.String r7 = ""
            if (r1 != 0) goto L_0x000b
            kotlin.h.b.n.LIZ(r7)
        L_0x000b:
            r2 = 0
            r1.isLastSugShown = r2
            java.lang.String r1 = r17.LJJIFFI()
            r0.LJIIJ = r1
            java.util.concurrent.CopyOnWriteArrayList r1 = r17.LJIIIZ()
            r1.clear()
            java.util.concurrent.CopyOnWriteArrayList r3 = r17.LJIIIZ()
            java.util.List r1 = r17.LJIJ()
            r3.addAll(r1)
            X.SYg r1 = X.C3420SXo.LIZJ
            X.SXo r3 = r1.LIZ()
            java.util.List r1 = r17.LJIJ()
            r3.LIZ(r1)
            boolean r3 = X.C4462Spm.LIZ
            r1 = 1
            if (r3 != 0) goto L_0x004c
            X.C4462Spm.LIZ = r1
            X.2on r4 = X.2om.LIZIZ
            java.lang.String r3 = "search_sug"
            X.3eh r3 = r4.LIZ(r3)
            r3.LIZ()
            java.lang.Runnable r5 = X.C4462Spm.LIZIZ
            r3 = 5000(0x1388, double:2.4703E-320)
            X.3QA.LIZ(r5, r3)
        L_0x004c:
            X.SYk r4 = new X.SYk
            r4.<init>()
            java.lang.String r3 = "sug_begin"
            r4.LJIJJ(r3)
            r4.LJFF()
            X.ST4 r3 = X.ST4.LIZIZ
            X.STu r3 = r3.LIZ()
            boolean r3 = r3.LJII
            if (r3 != 0) goto L_0x015e
            java.lang.String r6 = r17.LJIIZILJ()
            int r4 = r17.LJIJJLI()
            r3 = -1
            if (r4 != r3) goto L_0x0219
            r3 = 1
        L_0x006f:
            java.lang.String r5 = "general"
            java.lang.String r10 = "shop"
            if (r3 == 0) goto L_0x01c1
            java.lang.String r3 = "mall"
            boolean r3 = kotlin.h.b.n.LIZ(r3, r6)
            if (r3 == 0) goto L_0x01c1
        L_0x007d:
            boolean r3 = X.MKY.LIZ(r10)
            if (r3 == 0) goto L_0x0197
            X.SWW r8 = new X.SWW
            java.lang.String r9 = r17.LJJIFFI()
            X.SXF r4 = X.SXD.Companion
            X.1hK r3 = r17.getActivity()
            X.SV6 r3 = r4.LJ(r3)
            if (r3 == 0) goto L_0x00a1
            X.MWv r3 = r3.getSearchVideoModel()
            if (r3 == 0) goto L_0x00a1
            java.lang.String r11 = r3.getGroupId()
            if (r11 != 0) goto L_0x00a2
        L_0x00a1:
            r11 = r7
        L_0x00a2:
            r12 = 0
            X.MKX r3 = X.MKX.LIZ
            int r4 = r3.LIZ()
            X.MKX r3 = X.MKX.LIZ
            int r3 = r3.LIZIZ()
            int r4 = r4 + r3
            java.lang.Integer r13 = java.lang.Integer.valueOf(r4)
            X.MKX r3 = X.MKX.LIZ
            int r3 = r3.LIZIZ()
            java.lang.Integer r14 = java.lang.Integer.valueOf(r3)
            java.lang.String r15 = r17.LJIIZILJ()
            r16 = 680(0x2a8, float:9.53E-43)
            r8.<init>(r9, r10, r11, r12, r13, r14, r15, r16)
        L_0x00c7:
            java.lang.String r5 = r8.LIZ
            int r3 = r5.length()
            if (r3 <= 0) goto L_0x0194
            com.ss.android.ugc.aweme.discover.model.SearchIntermediateViewModel r3 = r0.LIZLLL
            if (r3 != 0) goto L_0x00d6
            kotlin.h.b.n.LIZ(r7)
        L_0x00d6:
            X.2ce r3 = r3.getSugRequestKeyword()
            java.lang.Object r3 = r3.getValue()
            java.lang.CharSequence r3 = (java.lang.CharSequence) r3
            boolean r3 = android.text.TextUtils.equals(r5, r3)
            if (r3 != 0) goto L_0x0194
            r6 = 1
        L_0x00e7:
            java.lang.Integer r3 = r0.LJIJJLI
            if (r3 == 0) goto L_0x0191
            int r4 = r0.LJIIL
            int r3 = r3.intValue()
            if (r4 == r3) goto L_0x0191
            r4 = 1
        L_0x00f4:
            com.ss.android.ugc.aweme.discover.model.SearchIntermediateViewModel r3 = r0.LIZLLL
            if (r3 != 0) goto L_0x00fb
            kotlin.h.b.n.LIZ(r7)
        L_0x00fb:
            X.2ce r3 = r3.getSugRequestKeyword()
            r3.getValue()
            if (r4 == 0) goto L_0x010b
            X.SZb r3 = r17.LJFF()
            r3.LIZ()
        L_0x010b:
            if (r6 != 0) goto L_0x011b
            java.lang.Integer r3 = r0.LJIJJLI
            if (r3 == 0) goto L_0x011b
            if (r4 != 0) goto L_0x011b
            boolean r3 = r0.LJIL
            if (r3 != 0) goto L_0x011b
            boolean r3 = X.SWS.LIZJ
            if (r3 == 0) goto L_0x015e
        L_0x011b:
            com.ss.android.ugc.aweme.discover.model.SearchIntermediateViewModel r3 = r0.LIZLLL
            if (r3 != 0) goto L_0x0122
            kotlin.h.b.n.LIZ(r7)
        L_0x0122:
            X.2ce r3 = r3.getSugRequestKeyword()
            r3.setValue(r5)
            int r3 = r0.LJIIL
            java.lang.Integer r3 = java.lang.Integer.valueOf(r3)
            r0.LJIJJLI = r3
            X.SWV r6 = r0.LJIILL
            if (r6 != 0) goto L_0x0138
            kotlin.h.b.n.LIZ(r7)
        L_0x0138:
            r6.LJFF = r8
            android.os.Handler r4 = r6.LIZLLL
            java.lang.Runnable r3 = r6.LJIIJJI
            r4.removeCallbacks(r3)
            java.util.concurrent.ConcurrentHashMap<java.lang.String, com.ss.android.ugc.aweme.discover.model.SearchSugResponse> r4 = r6.LJIIJ
            java.lang.String r3 = r8.LIZ
            java.lang.Object r4 = r4.get(r3)
            com.ss.android.ugc.aweme.discover.model.SearchSugResponse r4 = (com.ss.android.ugc.aweme.discover.model.SearchSugResponse) r4
            if (r4 == 0) goto L_0x0187
            X.MJZ r3 = X.MJZ.LIZ
            boolean r3 = r3.LIZ()
            if (r3 == 0) goto L_0x0187
            X.2GI r3 = r6.LJIIIIZZ
            X.SWd r3 = (X.C3383SWd) r3
            r3.LIZ(r4, r1)
        L_0x015c:
            r0.LJIL = r2
        L_0x015e:
            X.MH3 r1 = X.MH3.LIZ
            boolean r1 = r1.LIZ()
            if (r1 == 0) goto L_0x0175
            androidx.recyclerview.widget.RecyclerView r1 = r0.LIZIZ
            if (r1 != 0) goto L_0x016d
            kotlin.h.b.n.LIZ(r7)
        L_0x016d:
            X.0E3 r1 = r1.getAdapter()
            boolean r1 = r1 instanceof X.C3459SZb
            if (r1 != 0) goto L_0x0183
        L_0x0175:
            androidx.recyclerview.widget.RecyclerView r2 = r0.LIZIZ
            if (r2 != 0) goto L_0x017c
            kotlin.h.b.n.LIZ(r7)
        L_0x017c:
            X.SZb r1 = r17.LJFF()
            r2.setAdapter(r1)
        L_0x0183:
            r1 = 2
            r0.LJIIIZ = r1
            return
        L_0x0187:
            android.os.Handler r5 = r6.LIZLLL
            java.lang.Runnable r1 = r6.LJIIJJI
            r3 = 0
            r5.postDelayed(r1, r3)
            goto L_0x015c
        L_0x0191:
            r4 = 0
            goto L_0x00f4
        L_0x0194:
            r6 = 0
            goto L_0x00e7
        L_0x0197:
            X.SWW r8 = new X.SWW
            java.lang.String r9 = r17.LJJIFFI()
            X.SXF r4 = X.SXD.Companion
            X.1hK r3 = r17.getActivity()
            X.SV6 r3 = r4.LJ(r3)
            if (r3 == 0) goto L_0x01b5
            X.MWv r3 = r3.getSearchVideoModel()
            if (r3 == 0) goto L_0x01b5
            java.lang.String r11 = r3.getGroupId()
            if (r11 != 0) goto L_0x01b6
        L_0x01b5:
            r11 = r7
        L_0x01b6:
            r12 = 0
            r13 = 0
            r14 = 0
            r15 = 0
            r16 = 1016(0x3f8, float:1.424E-42)
            r8.<init>(r9, r10, r11, r12, r13, r14, r15, r16)
            goto L_0x00c7
        L_0x01c1:
            int r4 = r17.LJIJJLI()
            if (r4 < 0) goto L_0x0216
            int r3 = X.C3320STs.LIZ()
            if (r4 != r3) goto L_0x01d0
            r10 = r5
            goto L_0x007d
        L_0x01d0:
            X.STs r3 = X.C3320STs.LIZIZ
            int r3 = r3.LIZJ()
            if (r4 != r3) goto L_0x01dc
            java.lang.String r10 = "aweme_video"
            goto L_0x007d
        L_0x01dc:
            X.STs r3 = X.C3320STs.LIZIZ
            int r3 = r3.LIZIZ()
            if (r4 != r3) goto L_0x01e8
            java.lang.String r10 = "discover"
            goto L_0x007d
        L_0x01e8:
            X.STs r3 = X.C3320STs.LIZIZ
            int r3 = r3.LIZLLL()
            if (r4 != r3) goto L_0x01f4
            java.lang.String r10 = "music"
            goto L_0x007d
        L_0x01f4:
            X.STs r3 = X.C3320STs.LIZIZ
            int r3 = r3.LJ()
            if (r4 != r3) goto L_0x01fe
            goto L_0x007d
        L_0x01fe:
            X.STs r3 = X.C3320STs.LIZIZ
            int r3 = r3.LJFF()
            if (r4 != r3) goto L_0x020a
            java.lang.String r10 = "challenge"
            goto L_0x007d
        L_0x020a:
            X.STs r3 = X.C3320STs.LIZIZ
            int r3 = r3.LJI()
            if (r4 != r3) goto L_0x0216
            java.lang.String r10 = "live"
            goto L_0x007d
        L_0x0216:
            r10 = r5
            goto L_0x007d
        L_0x0219:
            r3 = 0
            goto L_0x006f
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.discover.ui.AbstractSearchIntermediateFragment.LJIILLIIL():void");
    }

    public static 0Bx LIZ(1hK r2) {
        0Bx LIZ2 = 0By.LIZ(r2, (0Bv) null);
        if (2GD.LIZ) {
            0Bs.LIZ(LIZ2, r2);
        }
        return LIZ2;
    }

    public void setUserVisibleHint(boolean z) {
        AbstractSearchIntermediateFragment.super.setUserVisibleHint(z);
        if (z) {
            LJIILJJIL();
        }
    }

    public final void LIZ(2Kx r3) {
        M12.LIZ(r3);
        SWV swv = this.LJIILL;
        if (swv == null) {
            n.LIZ("");
        }
        swv.LJIIJ.clear();
    }

    public final int LIZ(List<CDg> list) {
        ArrayList arrayList = new ArrayList();
        for (T next : list) {
            if (!((CDg) next).LIZIZ()) {
                arrayList.add(next);
            }
        }
        return arrayList.size();
    }

    public final Map<String, String> LIZ(SearchSugResponse searchSugResponse) {
        String str;
        String str2;
        String LIZ2 = 9oY.LIZ.LIZ(LJFF().LIZIZ);
        2UX r4 = new 2UX();
        r4.LIZ("raw_query", searchSugResponse.keyword);
        RecommendWordMob recommendWordMob = searchSugResponse.recommendWordMob;
        String str3 = null;
        if (recommendWordMob != null) {
            str = recommendWordMob.getInfo();
        } else {
            str = null;
        }
        r4.LIZ("info", str);
        r4.LIZ("sug_session_id", "");
        LogPbBean logPbBean = searchSugResponse.logPb;
        if (logPbBean != null) {
            str3 = logPbBean.getImprId();
        }
        r4.LIZ("impr_id", str3);
        r4.LIZ("log_pb", LIZ2);
        M12.LIZ(this);
        if (C4459Spj.LIZ.LIZ((Activity) getActivity())) {
            str2 = C3352SUy.LIZ(LJIJJLI());
        } else {
            str2 = "discovery";
        }
        r4.LIZ("search_position", str2);
        Map<String, String> map = r4.LIZ;
        n.LIZIZ(map, "");
        return map;
    }

    public final void LIZ(int i) {
        if (getParentFragment() != null && (getParentFragment() instanceof BaseDiscoverAndSearchFragment)) {
            BaseDiscoverAndSearchFragment parentFragment = getParentFragment();
            Objects.requireNonNull(parentFragment, "null cannot be cast to non-null type com.ss.android.ugc.aweme.discover.ui.BaseDiscoverAndSearchFragment");
            BaseDiscoverAndSearchFragment baseDiscoverAndSearchFragment = parentFragment;
            if (i == 1 && baseDiscoverAndSearchFragment.LJJII() == 3 && baseDiscoverAndSearchFragment.LJIIJJI.LIZIZ()) {
                SYQ syq = new SYQ();
                syq.LJIILL("cancel");
                syq.LJIILJJIL("personal_detail");
                syq.LJFF();
            }
        }
    }

    public void onCreate(Bundle bundle) {
        String str;
        String str2;
        AbstractSearchIntermediateFragment.super.onCreate(bundle);
        1hK activity = getActivity();
        if (activity == null) {
            n.LIZIZ();
        }
        SearchIntermediateViewModel LIZ2 = LIZ(activity).LIZ(SearchIntermediateViewModel.class);
        n.LIZIZ(LIZ2, "");
        this.LIZLLL = LIZ2;
        1hK activity2 = getActivity();
        if (activity2 == null) {
            n.LIZIZ();
        }
        SearchStateViewModel LIZ3 = LIZ(activity2).LIZ(SearchStateViewModel.class);
        n.LIZIZ(LIZ3, "");
        this.LJ = LIZ3;
        1hK activity3 = getActivity();
        if (activity3 == null) {
            n.LIZIZ();
        }
        n.LIZIZ(activity3, "");
        this.LJIIZILJ = new SearchKeywordPresenter(activity3);
        1hK activity4 = getActivity();
        if (activity4 == null) {
            n.LIZIZ();
        }
        n.LIZIZ(activity4, "");
        SugKeywordPresenter sugKeywordPresenter = new SugKeywordPresenter(activity4);
        this.LJIJ = sugKeywordPresenter;
        SearchKeywordPresenter searchKeywordPresenter = this.LJIIZILJ;
        if (searchKeywordPresenter == null || (str = searchKeywordPresenter.LIZIZ()) == null) {
            str = "";
        }
        sugKeywordPresenter.LIZ(str);
        SugKeywordPresenter sugKeywordPresenter2 = this.LJIJ;
        if (sugKeywordPresenter2 != null) {
            C3456SYy sYy = new C3456SYy(this);
            sugKeywordPresenter2.LIZIZ().LIZ().observe(sugKeywordPresenter2.LIZIZ, sYy);
            sugKeywordPresenter2.LIZ = sYy;
        }
        SearchIntermediateViewModel searchIntermediateViewModel = this.LIZLLL;
        if (searchIntermediateViewModel == null) {
            n.LIZ("");
        }
        searchIntermediateViewModel.keywordPresenter = this.LJIIZILJ;
        SearchIntermediateViewModel searchIntermediateViewModel2 = this.LIZLLL;
        if (searchIntermediateViewModel2 == null) {
            n.LIZ("");
        }
        searchIntermediateViewModel2.sugKeywordPresenter = this.LJIJ;
        SearchIntermediateViewModel searchIntermediateViewModel3 = this.LIZLLL;
        if (searchIntermediateViewModel3 == null) {
            n.LIZ("");
        }
        searchIntermediateViewModel3.getIntermediateState().observe(this, new C3455SYx(this));
        SearchIntermediateViewModel searchIntermediateViewModel4 = this.LIZLLL;
        if (searchIntermediateViewModel4 == null) {
            n.LIZ("");
        }
        searchIntermediateViewModel4.getSearchTabIndex().LIZ(this, new SYY(this), true);
        1hK activity5 = getActivity();
        if (activity5 != null) {
            this.LJIIJJI = LIZ(activity5).LIZ(SearchSugMobHelper.class);
        }
        SearchSugMobHelper searchSugMobHelper = this.LJIIJJI;
        if (searchSugMobHelper != null) {
            searchSugMobHelper.LIZIZ = LJJIFFI();
            SV5 sv5 = SearchEnterViewModel.LIZJ.LIZ(getActivity()).LIZ;
            if (sv5 != null) {
                str2 = sv5.getEnterSearchFrom();
            } else {
                str2 = null;
            }
            searchSugMobHelper.LIZJ = str2;
            searchSugMobHelper.LJ = new SZR(this);
        }
        C3420SXo.LIZJ.LIZ().LIZ(LJIJ());
    }

    public void LIZ(View view) {
        M12.LIZ(view);
        RecyclerView findViewById = view.findViewById(2131369397);
        n.LIZIZ(findViewById, "");
        RecyclerView recyclerView = findViewById;
        this.LIZIZ = recyclerView;
        if (recyclerView == null) {
            n.LIZ("");
        }
        getContext();
        WrapLinearLayoutManager wrapLinearLayoutManager = new WrapLinearLayoutManager(1);
        wrapLinearLayoutManager.LJI = new C3332SUe(this);
        recyclerView.setLayoutManager(wrapLinearLayoutManager);
        RecyclerView recyclerView2 = this.LIZIZ;
        if (recyclerView2 == null) {
            n.LIZ("");
        }
        Drawable drawable = getResources().getDrawable(2131233736);
        n.LIZIZ(drawable, "");
        recyclerView2.LIZ(new BSx(drawable));
        RecyclerView recyclerView3 = this.LIZIZ;
        if (recyclerView3 == null) {
            n.LIZ("");
        }
        recyclerView3.LIZ(new C3346SUs());
    }

    public void onViewCreated(View view, Bundle bundle) {
        M12.LIZ(view);
        AbstractSearchIntermediateFragment.super.onViewCreated(view, bundle);
        LIZ(view);
        LJIIL();
        LJIILIIL();
        LJIILJJIL();
    }

    public void LIZ(Context context, SV0 sv0) {
        M12.LIZ(sv0);
        if (this.LJ == null) {
            n.LIZ("");
        }
        SWV.LIZIZ = 0L;
        SWV.LIZJ = 0L;
        SearchStateViewModel searchStateViewModel = this.LJ;
        if (searchStateViewModel == null) {
            n.LIZ("");
        }
        searchStateViewModel.setIsRefreshingData(true);
        SearchIntermediateViewModel searchIntermediateViewModel = this.LIZLLL;
        if (searchIntermediateViewModel == null) {
            n.LIZ("");
        }
        searchIntermediateViewModel.openSearch(context, sv0);
    }

    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        M12.LIZ(layoutInflater);
        View LIZ2 = 0HH.LIZ(layoutInflater, 2131561109, viewGroup, false);
        View findViewById = LIZ2.findViewById(2131369693);
        n.LIZIZ(findViewById, "");
        this.LIZJ = (ViewGroup) findViewById;
        return LIZ2;
    }

    private final void LIZIZ(CDg cDg, String str, int i) {
        String str2;
        String LIZ2 = 9oY.LIZ.LIZ(str);
        if (cDg.LJII == 4) {
            str2 = "user_enrich_sug";
        } else if (CEA.LIZ(cDg)) {
            str2 = "enrich_sug";
        } else {
            str2 = "normal_sug";
        }
        SYX syx = new SYX();
        syx.LJIJI("click");
        syx.LIZIZ(Integer.valueOf(i));
        syx.LJIJJ(LJJIFFI());
        syx.LIZJ(LIZ2);
        syx.LJFF(C3352SUy.LIZIZ(LJIJJLI()));
        syx.LIZIZ(cDg.LIZIZ);
        syx.LJIJJLI(str2);
        syx.LJFF();
    }

    public final void LIZ(CDg cDg, String str, int i) {
        String str2;
        String str3;
        String str4;
        String LJIIZILJ2;
        MWv searchVideoModel;
        AbstractSearchIntermediateFragment abstractSearchIntermediateFragment = this;
        CDg cDg2 = cDg;
        String str5 = str;
        M12.LIZ(cDg2, str5);
        abstractSearchIntermediateFragment.LJIL = true;
        int i2 = i;
        if (cDg2.LJII == 4) {
            CDf cDf = cDg2.LJI;
            if (cDf != null) {
                String str6 = null;
                if (4q6.LIZ(cDf.getSecUserId())) {
                    if (4q6.LIZ(cDf.getUsername()) && MKU.LIZ) {
                        abstractSearchIntermediateFragment.LJIIIIZZ().recordSearchHistory(new SearchHistory(cDf.getUsername(), 0));
                    }
                    Map map = cDg2.LJIIJ;
                    if (map != null) {
                        map.put("sug_user_id", cDf.getUserId());
                        map.put("user_tag", cDf.getUserRelationType());
                    }
                    SXK LIZJ2 = SXD.Companion.LIZJ(abstractSearchIntermediateFragment.getActivity());
                    if (LIZJ2 == null || (LJIIZILJ2 = LIZJ2.getSearchPosition()) == null || LJIIZILJ2.length() <= 0) {
                        LJIIZILJ2 = abstractSearchIntermediateFragment.LJIIZILJ();
                    }
                    SX8.LIZIZ(LJIIZILJ2, cDg2.LJIIIIZZ, cDg2, "user_enrich_sug", abstractSearchIntermediateFragment.LJIIZILJ());
                    abstractSearchIntermediateFragment.LIZIZ(cDg2, str5, cDg2.LJIIIIZZ);
                    String username = cDf.getUsername();
                    String userId = cDf.getUserId();
                    String userRelationType = cDf.getUserRelationType();
                    SV6 LIZJ3 = SXD.Companion.LIZJ();
                    if (!(LIZJ3 == null || (searchVideoModel = LIZJ3.getSearchVideoModel()) == null)) {
                        str6 = searchVideoModel.getGroupId();
                    }
                    SX7.LIZ((View) null, i2, username, 6, str5, userId, "click_enrich_sug", userRelationType, (Map<String, String>) null, str6);
                    SmartRoute buildRoute = SmartRouter.buildRoute(abstractSearchIntermediateFragment.getContext(), "aweme://user/profile/");
                    buildRoute.withParam("sec_user_id", cDf.getSecUserId());
                    buildRoute.withParam("uid", cDf.getUserId());
                    buildRoute.withParam("enter_from", "search_sug");
                    buildRoute.withParam("previous_page", "search_sug");
                    buildRoute.withParam("extra_from_pre_page", "search_sug");
                    buildRoute.withParam("extra_from_event_enter_from", "search_sug");
                    buildRoute.withParam("extra_previous_page_position", "main_head");
                    buildRoute.withParam("enter_from_request_id", str5);
                    buildRoute.withParam("search_request_id", str5);
                    buildRoute.withCallback(new SZ6(abstractSearchIntermediateFragment));
                    buildRoute.open(1, new C3535Sap(abstractSearchIntermediateFragment));
                    SX8.LIZ(0);
                    SWS.LJFF.LIZ();
                    return;
                }
                return;
            }
            return;
        }
        SV0 sv0 = new SV0();
        sv0.setKeyword(cDg2.LIZIZ);
        sv0.setSearchFrom("search_sug");
        if (CEA.LIZ(cDg2)) {
            str2 = "enrich_sug";
        } else {
            str2 = "normal_sug";
        }
        sv0.setSugType(str2);
        sv0.setOpenNewSearchContainer(false);
        CDf cDf2 = cDg2.LJI;
        if (cDf2 == null || (str3 = cDf2.getUserId()) == null) {
            str3 = "";
        }
        sv0.setSugUserId(str3);
        CDf cDf3 = cDg2.LJI;
        if (cDf3 == null || (str4 = cDf3.isRichSugValue()) == null) {
            str4 = "";
        }
        sv0.setIsRichSug(str4);
        C3328SUa sUa = C3328SUa.LIZJ;
        n.LIZIZ(sv0, "");
        sUa.LIZ(1, sv0);
        C3329SUb.LIZJ.LIZ(1, sv0);
        new C3401SWv().LJFF();
        C3341SUn.LJFF.onEventStart(sv0);
        abstractSearchIntermediateFragment.LIZ(abstractSearchIntermediateFragment.getContext(), sv0);
        abstractSearchIntermediateFragment.LIZIZ(cDg2, str5, i2);
    }
}
