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

import X.0AA;
import X.0Bs;
import X.0Bv;
import X.0Bx;
import X.0By;
import X.0CH;
import X.0CM;
import X.0HB;
import X.1hK;
import X.2GD;
import X.2GO;
import X.2HZ;
import X.2Rh;
import X.2c6;
import X.2cN;
import X.3F7;
import X.45p;
import X.4ZZ;
import X.B0i;
import X.C1069Rc9;
import X.C3320STs;
import X.C3334SUg;
import X.C3380SWa;
import X.C3381SWb;
import X.C3382SWc;
import X.C3385SWf;
import X.C3386SWg;
import X.C3387SWh;
import X.C3399SWt;
import X.C3829SfZ;
import X.C4459Spj;
import X.C4923SxD;
import X.HeD;
import X.ISm;
import X.M12;
import X.MJG;
import X.MJh;
import X.MKa;
import X.MLO;
import X.PgU;
import X.PhE;
import X.PlI;
import X.SV0;
import X.SV5;
import X.SW2;
import X.SWB;
import X.SWC;
import X.SWD;
import X.SWJ;
import X.SWK;
import X.SWO;
import X.SWR;
import X.SWS;
import X.SWZ;
import X.SXB;
import X.SXD;
import X.SXK;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.base.fragment.AmeBaseFragment;
import com.ss.android.ugc.aweme.base.utils.KeyboardUtils;
import com.ss.android.ugc.aweme.compliance.api.a;
import com.ss.android.ugc.aweme.discover.model.KeyboardModel;
import com.ss.android.ugc.aweme.discover.model.MaskedSearchMobData;
import com.ss.android.ugc.aweme.discover.model.SearchIntermediateViewModel;
import com.ss.android.ugc.aweme.discover.model.SearchStateData;
import com.ss.android.ugc.aweme.discover.model.SearchStateViewModel;
import com.ss.android.ugc.aweme.discover.model.suggest.Word;
import com.ss.android.ugc.aweme.discover.viewmodel.SearchEnterViewModel;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import kotlin.h.b.n;
import org.greenrobot.eventbus.ThreadMode;

public abstract class BaseDiscoverAndSearchFragment extends AmeBaseFragment implements C3382SWc, 2HZ, 2GO {
    public static long LJIL = 1000;
    public View LIZ;
    public EditText LIZIZ;
    public 4ZZ LIZJ;
    public View LIZLLL;
    public TextView LJ;
    public ImageView LJIIIZ;
    public FrameLayout LJIIJ;
    public SW2 LJIIJJI;
    public KeyboardModel LJIIL;
    public SearchStateViewModel LJIILIIL;
    public String LJIILJJIL;
    public SearchIntermediateViewModel LJIILL;
    public SearchStateData LJIIZILJ;
    public boolean LJIJ;
    public 2cN LJIJI;
    public SV0 LJIJJ;
    public long LJIJJLI;
    public Word LJJ;
    public boolean LJJI;
    public SWC LJJIFFI;
    public String LJJII;

    public abstract void LIZIZ(View view);

    public abstract void LIZIZ(String str);

    public void LIZJ(SV0 sv0) {
    }

    public void LIZJ(Bundle bundle) {
    }

    public void LIZJ(String str) {
    }

    public boolean LJ(String str) {
        return false;
    }

    public abstract int LJIIIIZZ();

    public abstract int LJIIIZ();

    public abstract void LJIIJ();

    public void LJIILJJIL() {
    }

    public abstract String LJIJI();

    public boolean LJIJJLI() {
        return true;
    }

    public boolean LJJIFFI() {
        return true;
    }

    public boolean LJJIIJ() {
        return false;
    }

    public String LJJIIJZLJL() {
        return "";
    }

    public String LJJIIZ() {
        return "";
    }

    public final boolean LJJIJIIJI() {
        return true;
    }

    public Map<Integer, Object> getSubscriberEventTypes() {
        HashMap hashMap = new HashMap();
        hashMap.put(401, new C1069Rc9(BaseDiscoverAndSearchFragment.class, "onSearchSugCompletionEvent", C3399SWt.class, ThreadMode.POSTING, 0, false));
        return hashMap;
    }

    public void onDestroy() {
        BaseDiscoverAndSearchFragment.super.onDestroy();
    }

    public void onDestroyView() {
        BaseDiscoverAndSearchFragment.super.onDestroyView();
    }

    public final boolean LIZ(String str) {
        int LJII = C3320STs.LJII();
        for (int i = 0; i < LJII; i++) {
            if (TextUtils.equals(str, MKa.LIZ.LIZ(i))) {
                return true;
            }
        }
        return false;
    }

    public final /* synthetic */ boolean LIZ(View view, MotionEvent motionEvent) {
        if (motionEvent.getAction() != 1) {
            return false;
        }
        LIZIZ(view);
        return false;
    }

    /* JADX WARNING: Removed duplicated region for block: B:48:0x00bb  */
    /* JADX WARNING: Removed duplicated region for block: B:60:0x0119  */
    /* JADX WARNING: Removed duplicated region for block: B:61:0x011e  */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final void LIZ(java.lang.String r10, boolean r11) {
        /*
            r9 = this;
            java.lang.String r4 = r10.trim()
            boolean r0 = android.text.TextUtils.isEmpty(r4)
            if (r0 == 0) goto L_0x000b
            return
        L_0x000b:
            X.1hK r3 = r9.getActivity()
            if (r3 != 0) goto L_0x0012
            return
        L_0x0012:
            long r5 = java.lang.System.currentTimeMillis()
            long r0 = r9.LJIJJLI
            long r7 = r5 - r0
            r9.LJIJJLI = r5
            long r1 = LJIL
            int r0 = (r7 > r1 ? 1 : (r7 == r1 ? 0 : -1))
            if (r0 >= 0) goto L_0x0023
            return
        L_0x0023:
            r5 = 0
            if (r11 == 0) goto L_0x00d4
            X.SV0 r0 = r9.LJIJJ
            r7 = 1
            if (r0 == 0) goto L_0x0078
            boolean r0 = r0.isOpenNewSearchContainer()
            if (r0 == 0) goto L_0x0078
            r1 = 1
        L_0x0032:
            boolean r0 = r9.LJIILLIIL()
            if (r0 == 0) goto L_0x0076
            if (r1 == 0) goto L_0x0076
            r1 = 1
        L_0x003b:
            com.ss.android.ugc.aweme.discover.model.SearchIntermediateViewModel r0 = r9.LJIILL
            if (r0 == 0) goto L_0x0074
            boolean r0 = r0.backFromSearchResult
            if (r0 == 0) goto L_0x0074
            r0 = 1
        L_0x0044:
            java.lang.String r6 = "search_bar_outer"
            if (r0 == 0) goto L_0x0072
            boolean r0 = r9.LJII()
            if (r0 != 0) goto L_0x0050
            if (r1 != 0) goto L_0x0072
        L_0x0050:
            java.lang.String r2 = "search_bar_inner"
        L_0x0052:
            X.1hK r1 = r9.requireActivity()
            X.SAJ r0 = com.ss.android.ugc.aweme.discover.viewmodel.SearchEnterViewModel.LIZJ
            com.ss.android.ugc.aweme.discover.viewmodel.SearchEnterViewModel r0 = r0.LIZ(r1)
            boolean r0 = r0.LIZ()
            r7 = r7 ^ r0
            if (r7 == 0) goto L_0x0070
        L_0x0063:
            X.1hK r1 = r9.getActivity()
            X.SAJ r0 = com.ss.android.ugc.aweme.discover.viewmodel.SearchEnterViewModel.LIZJ
            com.ss.android.ugc.aweme.discover.viewmodel.SearchEnterViewModel r0 = r0.LIZ(r1)
            X.SV5 r7 = r0.LIZ
            goto L_0x007a
        L_0x0070:
            r6 = r2
            goto L_0x0063
        L_0x0072:
            r2 = r6
            goto L_0x0052
        L_0x0074:
            r0 = 0
            goto L_0x0044
        L_0x0076:
            r1 = 0
            goto L_0x003b
        L_0x0078:
            r1 = 0
            goto L_0x0032
        L_0x007a:
            java.lang.String r0 = "hint_position"
            java.lang.Object r0 = r7.obtainLogData(r0)     // Catch:{ NumberFormatException -> 0x008b }
            if (r0 == 0) goto L_0x008b
            java.lang.String r0 = r0.toString()     // Catch:{ NumberFormatException -> 0x008b }
            int r1 = java.lang.Integer.parseInt(r0)     // Catch:{ NumberFormatException -> 0x008b }
            goto L_0x008c
        L_0x008b:
            r1 = 0
        L_0x008c:
            X.SZO r2 = new X.SZO
            r2.<init>()
            java.lang.String r0 = r7.getEnterSearchFrom()
            r2.LJJIJIIJIL(r0)
            java.lang.String r0 = r9.LJIJ()
            r2.LJJIII(r0)
            java.lang.String r0 = "tab_name"
            java.lang.Object r0 = r7.obtainLogData(r0)
            r2.LIZ(r0)
            java.lang.Integer r0 = java.lang.Integer.valueOf(r1)
            r2.LIZLLL(r0)
            r2.LJJI(r6)
            r2.LJJIFFI(r4)
            com.ss.android.ugc.aweme.discover.model.suggest.Word r0 = r9.LJJ
            java.lang.String r1 = ""
            if (r0 != 0) goto L_0x011e
            r0 = r1
        L_0x00bc:
            r2.LJIIIIZZ(r0)
            com.ss.android.ugc.aweme.discover.model.suggest.Word r0 = r9.LJJ
            if (r0 != 0) goto L_0x0119
        L_0x00c3:
            r2.LIZLLL(r1)
            r0 = -1
            java.lang.Integer r0 = java.lang.Integer.valueOf(r0)
            r2.LIZ((java.lang.Integer) r0)
            r2.LJJII(r4)
            r2.LJFF()
        L_0x00d4:
            java.util.concurrent.atomic.AtomicBoolean r2 = new java.util.concurrent.atomic.AtomicBoolean
            r2.<init>(r5)
            com.ss.android.ugc.aweme.discover.model.SearchIntermediateViewModel r0 = r9.LJIILL
            boolean r0 = r0.isLastSugShown
            if (r0 == 0) goto L_0x00e7
            X.SWv r0 = new X.SWv
            r0.<init>()
            r0.LJFF()
        L_0x00e7:
            X.SV0 r1 = new X.SV0
            r1.<init>()
            r1.setKeyword(r4)
            java.lang.String r0 = r9.LIZLLL((boolean) r11)
            r1.setSearchFrom(r0)
            boolean r0 = r2.get()
            r1.setOpenNewSearchContainer(r0)
            r9.LIZ((android.content.Context) r3, (X.SV0) r1)
            X.SWC r0 = r9.LJJIFFI
            r0.LIZ()
            X.SW2 r0 = r9.LJIIJJI
            androidx.fragment.app.Fragment r1 = r0.getFragment()
            X.Sar r1 = (X.C3537Sar) r1
            if (r1 == 0) goto L_0x0118
            X.1hK r0 = r9.getActivity()
            if (r0 == 0) goto L_0x0118
            r1.bQ_()
        L_0x0118:
            return
        L_0x0119:
            java.lang.String r1 = r0.getImplId()
            goto L_0x00c3
        L_0x011e:
            java.lang.String r0 = r0.getId()
            goto L_0x00bc
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.discover.ui.BaseDiscoverAndSearchFragment.LIZ(java.lang.String, boolean):void");
    }

    public final void LIZ(boolean z) {
        if (z) {
            LJIIZILJ();
            return;
        }
        KeyboardUtils.LIZJ(this.LIZIZ);
        this.LIZIZ.setCursorVisible(false);
    }

    /* renamed from: LJIIJJI */
    public void LJJIJIIJIL() {
        SWS.LJFF.LIZ();
    }

    public final String LJIIL() {
        return MKa.LIZ.LIZ(-1);
    }

    public final String LJIILIIL() {
        return MKa.LIZ.LIZ(0);
    }

    public void LJJ() {
        C4459Spj.LIZ.LJJII();
    }

    static {
        Covode.recordClassIndex(65367);
    }

    public void LJFF() {
        new Handler().postDelayed(new C3385SWf(this), 800);
    }

    public final void LJIIZILJ() {
        this.LIZIZ.postDelayed(new B0i(this), 200);
    }

    public void LJIL() {
        getActivity().getWindow().setSoftInputMode(50);
    }

    public final String LJIJ() {
        String LJIJI2 = LJIJI();
        SXK fetchOwnFragmentData = SXD.fetchOwnFragmentData((0CH) getActivity());
        if (fetchOwnFragmentData == null || fetchOwnFragmentData.getSearchPosition().isEmpty()) {
            return LJIJI2;
        }
        return fetchOwnFragmentData.getSearchPosition();
    }

    public final int LJJII() {
        Integer num = (Integer) this.LJIILIIL.searchState.getValue();
        if (num == null) {
            return LJIIIZ();
        }
        return num.intValue();
    }

    public final boolean LJII() {
        if ("homepage_follow".equals(LJIJI()) || "homepage_hot".equals(LJIJI()) || "homepage_friends".equals(LJIJI()) || "homepage_popular".equals(LJIJI()) || "homepage_nearby".equals(LJIJI())) {
            return true;
        }
        return false;
    }

    public final boolean LJIILLIIL() {
        if (getActivity() == null) {
            return false;
        }
        SV5 sv5 = SearchEnterViewModel.LIZJ.LIZ(requireActivity()).LIZ;
        if (sv5 == null) {
            return false;
        }
        return "1".equals(sv5.obtainLogData("is_from_video"));
    }

    public final /* synthetic */ void LJJIJIL() {
        1hK activity = getActivity();
        if (activity != null && !activity.isFinishing()) {
            LJJ();
            this.LIZIZ.setText("");
            this.LIZIZ.requestFocus();
            this.LIZIZ.setSelection(0);
        }
    }

    public void onPause() {
        BaseDiscoverAndSearchFragment.super.onPause();
        this.LJIJI = PgU.LIZ(PgU.LIZIZ(a.LJIIZILJ()), C3829SfZ.LJIJ.LJ(), SWO.LIZ).LIZIZ(PhE.LIZIZ(PlI.LIZJ)).LIZLLL(new SWD(this));
    }

    public void onResume() {
        BaseDiscoverAndSearchFragment.super.onResume();
        this.LJIJI = PgU.LIZIZ(a.LJIIZILJ()).LIZIZ(PhE.LIZIZ(PlI.LIZJ)).LIZLLL(new SWK(this));
    }

    public final void LJI() {
        if (getActivity() != null) {
            SV5 sv5 = SearchEnterViewModel.LIZJ.LIZ(getActivity()).LIZ;
            if (sv5 != null && !TextUtils.isEmpty(sv5.getSearchHint())) {
                String str = (String) sv5.obtainLogData("hint_group_id");
                if (TextUtils.isEmpty(str)) {
                    str = sv5.getSearchHintWordId();
                }
                LIZIZ(new SWJ(sv5.getSearchHint(), str, (String) sv5.obtainLogData("hint_imp_id")));
            }
        }
    }

    public final void LJJI() {
        if (LJJIFFI()) {
            C4459Spj.LIZ.LJJIII();
            String obj = this.LIZIZ.getText().toString();
            int selectionStart = this.LIZIZ.getSelectionStart();
            if (this.LJJI) {
                selectionStart = this.LIZIZ.getText().length();
            }
            SWS.LJ = selectionStart;
            this.LJJI = false;
            if (this.LJIIJJI.LIZ()) {
                this.LJIIJJI.LIZ(obj);
                return;
            }
            this.LJIIJJI.LIZ(obj);
            this.LJIIJJI.setOpenSugFromState(LJJII());
            LIZIZ(3);
        }
    }

    public final /* synthetic */ void LJJIIZI() {
        boolean z;
        if (LJJII() != 2 || MJh.LIZ(MLO.PRESS_CLEAR)) {
            z = true;
        } else {
            z = false;
        }
        LIZIZ(z);
        LJIILJJIL();
        String obj = this.LIZIZ.getText().toString();
        M12.LIZ(obj);
        SWS.LIZ = obj;
        SWS.LIZIZ = System.currentTimeMillis();
        this.LIZIZ.setText("");
        this.LIZIZ.setSelection(0);
        LIZ(z);
        LIZJ("cancel");
    }

    public void LJIILL() {
        this.LJIIIZ.setOnClickListener(new C3386SWg(this));
        this.LIZJ.setOnClickListener(new C3387SWh(this));
        this.LJ.setOnTouchListener(new C4923SxD() {
            static {
                Covode.recordClassIndex(65368);
            }

            public final void LIZ(View view) {
                if (BaseDiscoverAndSearchFragment.this.LIZIZ != null) {
                    BaseDiscoverAndSearchFragment.this.LIZLLL(BaseDiscoverAndSearchFragment.this.LIZIZ.getText().toString());
                    BaseDiscoverAndSearchFragment.this.LJFF("click_search");
                }
            }
        });
        SWC swc = this.LJJIFFI;
        EditText editText = this.LIZIZ;
        if (editText != null) {
            editText.addTextChangedListener(new SWB(swc));
        }
        new SWJ(MKa.LIZ.LIZ(-1));
        LJI();
        this.LIZIZ.setHint(MKa.LIZ.LIZ(-1));
        this.LIZIZ.setFilters(new InputFilter[]{new 2c6()});
        this.LIZIZ.addTextChangedListener(new TextWatcher() {
            static {
                Covode.recordClassIndex(65369);
            }

            public final void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            public final void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            public final void afterTextChanged(Editable editable) {
                BaseDiscoverAndSearchFragment.this.LIZ((CharSequence) editable.toString());
            }
        });
        this.LIZIZ.setOnTouchListener(new SWZ(this));
        this.LIZIZ.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            static {
                Covode.recordClassIndex(65370);
            }

            public final boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                if (i != 3) {
                    return true;
                }
                BaseDiscoverAndSearchFragment.this.LIZLLL(BaseDiscoverAndSearchFragment.this.LIZIZ.getText().toString());
                BaseDiscoverAndSearchFragment.this.LJFF("default_click_keyboard");
                return true;
            }
        });
        if (getActivity() != null) {
            KeyboardModel LIZ2 = LIZ(getActivity()).LIZ(KeyboardModel.class);
            this.LJIIL = LIZ2;
            LIZ2.getKeyboardStatus().observe(getActivity(), new 0CM<Integer>() {
                static {
                    Covode.recordClassIndex(65371);
                }

                public final /* synthetic */ void onChanged(Object obj) {
                    Integer num = (Integer) obj;
                    if (num == null) {
                        return;
                    }
                    if (num.intValue() == 1) {
                        KeyboardUtils.LIZIZ(BaseDiscoverAndSearchFragment.this.LIZIZ);
                    } else if (num.intValue() == 0) {
                        KeyboardUtils.LIZJ(BaseDiscoverAndSearchFragment.this.LIZIZ);
                    }
                }
            });
        }
    }

    /* JADX WARNING: Can't fix incorrect switch cases order */
    /* JADX WARNING: Code restructure failed: missing block: B:18:0x0073, code lost:
        if (r1.equals("homepage_hot") == false) goto L_0x0019;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:20:0x007c, code lost:
        if (r1.equals("discovery") == false) goto L_0x0019;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:22:0x0085, code lost:
        if (r1.equals("homepage_friends") == false) goto L_0x0019;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:24:0x008e, code lost:
        if (r1.equals("homepage_follow") == false) goto L_0x0019;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:25:0x0091, code lost:
        r2 = r1;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final void LJJIII() {
        /*
            r4 = this;
            android.widget.EditText r0 = r4.LIZIZ
            if (r0 == 0) goto L_0x000a
            X.1hK r0 = r4.getActivity()
            if (r0 != 0) goto L_0x000b
        L_0x000a:
            return
        L_0x000b:
            r2 = 0
            int r1 = r4.LJJII()
            r0 = 2
            if (r1 != r0) goto L_0x0039
            java.lang.String r2 = r4.LJJIIJZLJL()
            java.lang.String r3 = "search_result"
        L_0x0019:
            X.SWP r1 = new X.SWP
            r1.<init>()
            java.lang.String r0 = "cancel_position"
            r1.LIZJ(r0, r3)
            X.SWP r1 = (X.SWP) r1
            android.widget.EditText r0 = r4.LIZIZ
            android.text.Editable r0 = r0.getText()
            java.lang.String r0 = r0.toString()
            r1.LIZIZ((java.lang.String) r0)
            r1.LJFF(r2)
            r1.LJFF()
            goto L_0x000a
        L_0x0039:
            android.widget.EditText r0 = r4.LIZIZ
            android.text.Editable r0 = r0.getText()
            java.lang.String r0 = r0.toString()
            java.lang.String r0 = r0.trim()
            boolean r0 = android.text.TextUtils.isEmpty(r0)
            if (r0 == 0) goto L_0x005a
            java.lang.String r3 = "search_blankpage"
        L_0x004f:
            boolean r0 = r4.LJJIIJ()
            if (r0 == 0) goto L_0x005d
            java.lang.String r2 = r4.LJJIIZ()
            goto L_0x0019
        L_0x005a:
            java.lang.String r3 = "search_sug"
            goto L_0x004f
        L_0x005d:
            java.lang.String r1 = r4.LJIJI()
            r1.hashCode()
            r0 = -1
            int r0 = r1.hashCode()
            switch(r0) {
                case -1271119582: goto L_0x0088;
                case -667094460: goto L_0x007f;
                case -121207376: goto L_0x0076;
                case 1691937916: goto L_0x006d;
                default: goto L_0x006c;
            }
        L_0x006c:
            goto L_0x0019
        L_0x006d:
            java.lang.String r0 = "homepage_hot"
            boolean r0 = r1.equals(r0)
            if (r0 != 0) goto L_0x0091
            goto L_0x0019
        L_0x0076:
            java.lang.String r0 = "discovery"
            boolean r0 = r1.equals(r0)
            if (r0 != 0) goto L_0x0091
            goto L_0x0019
        L_0x007f:
            java.lang.String r0 = "homepage_friends"
            boolean r0 = r1.equals(r0)
            if (r0 != 0) goto L_0x0091
            goto L_0x0019
        L_0x0088:
            java.lang.String r0 = "homepage_follow"
            boolean r0 = r1.equals(r0)
            if (r0 != 0) goto L_0x0091
            goto L_0x0019
        L_0x0091:
            r2 = r1
            goto L_0x0019
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.discover.ui.BaseDiscoverAndSearchFragment.LJJIII():void");
    }

    public void LIZ(SWJ swj) {
        LIZIZ(swj);
    }

    public void LIZIZ(SV0 sv0) {
        C4459Spj.LIZ.LJJIII();
    }

    public void LIZLLL(String str) {
        LIZ(str, false);
    }

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

    private String LIZLLL(boolean z) {
        if (LJJII() != 3) {
            return "click_topright_search";
        }
        if (z) {
            return "default_search_keyword";
        }
        return "normal_search";
    }

    public final void LIZ(int i) {
        this.LIZIZ.setHint(MKa.LIZ.LIZ(i));
    }

    public final void LIZIZ(boolean z) {
        if (z) {
            this.LJIILL.keyboardVisibility = 1;
        } else {
            this.LJIILL.keyboardVisibility = 0;
        }
    }

    public final void LIZJ(boolean z) {
        SW2 sw2 = this.LJIIJJI;
        sw2.LIZLLL.LIZ(z);
        SearchIntermediateViewModel searchIntermediateViewModel = sw2.LIZ;
        if (searchIntermediateViewModel == null) {
            n.LIZ("");
        }
        searchIntermediateViewModel.hideIntermediate();
    }

    public void LIZ(SV0 sv0) {
        if (SearchStateViewModel.isSearchIntermediate(LJJII()) && !TextUtils.isEmpty(sv0.getKeyword())) {
            LIZIZ(sv0);
        }
    }

    public void LIZIZ(int i) {
        this.LJIILIIL.setSearchState(i);
        this.LJIIZILJ.getSearchState().setValue(Integer.valueOf(i));
        if (SearchStateViewModel.isSearchIntermediate(i)) {
            this.LJIIJ.setVisibility(4);
        } else {
            this.LJIIJ.setVisibility(0);
        }
    }

    public final void LJFF(String str) {
        String str2;
        EditText editText = this.LIZIZ;
        if (editText != null) {
            str2 = editText.getText().toString();
            if (TextUtils.isEmpty(str2)) {
                str2 = this.LIZIZ.getHint().toString();
            }
        } else {
            str2 = "";
        }
        SWR swr = new SWR();
        swr.LIZJ("enter_method", str);
        swr.LIZIZ(str2);
        swr.LJFF();
    }

    @ISm
    public void onSearchSugCompletionEvent(C3399SWt sWt) {
        String str;
        if (aq_() && sWt != null && (str = sWt.LIZ) != null && str.length() != 0 && this.LJIIJJI.getVisibility() == 0) {
            this.LJJI = true;
            this.LIZIZ.setText(str);
            this.LIZIZ.setSelection(str.length());
            this.LIZIZ.setCursorVisible(true);
            KeyboardUtils.LIZIZ(this.LIZIZ);
        }
    }

    public void onCreate(Bundle bundle) {
        BaseDiscoverAndSearchFragment.super.onCreate(bundle);
        this.LJIILIIL = LIZ(getActivity()).LIZ(SearchStateViewModel.class);
        this.LJJIFFI = new SWC();
        LIZJ(getArguments());
        this.LJIILL = LIZ(getActivity()).LIZ(SearchIntermediateViewModel.class);
        0Bx LIZ2 = 0By.LIZ(this, (0Bv) null);
        if (2GD.LIZ) {
            0Bs.LIZ(LIZ2, this);
        }
        this.LJIIZILJ = LIZ2.LIZ(SearchStateData.class);
        this.LJIILIIL.isLeavingSearchPage.observe(this, new C3380SWa(this));
    }

    public final /* synthetic */ void LIZ(MotionEvent motionEvent) {
        SearchIntermediateViewModel searchIntermediateViewModel;
        if (motionEvent != null && motionEvent.getActionMasked() == 0 && (searchIntermediateViewModel = this.LJIILL) != null && searchIntermediateViewModel.canDismissKeyboardOnActionDown()) {
            KeyboardUtils.LIZJ(this.LIZIZ);
            this.LIZIZ.setCursorVisible(false);
        }
    }

    public final void LIZIZ(SWJ swj) {
        String str;
        if (swj != null) {
            this.LJJ = new Word(swj.LIZIZ, swj.LIZ);
            SV5 sv5 = SearchEnterViewModel.LIZJ.LIZ(getActivity()).LIZ;
            String LIZIZ2 = SXB.LIZJ.LIZIZ();
            if (Objects.equals(sv5.getEnterSearchFrom(), "homepage_friends") || Objects.equals(sv5.getEnterSearchFrom(), "discovery")) {
                str = SXB.LIZIZ;
            } else {
                str = sv5.getGroupId();
            }
            SXB sxb = SXB.LIZJ;
            if (sxb.LIZ(LIZIZ2 + str)) {
                Map<String, MaskedSearchMobData> map = SXB.LIZ;
                map.get(LIZIZ2 + str).masked_default_keywords = swj.LIZ;
                Map<String, MaskedSearchMobData> map2 = SXB.LIZ;
                map2.get(LIZIZ2 + str).masked_default_keywords_time = System.currentTimeMillis();
            } else {
                this.LIZIZ.setHint(swj.LIZ);
            }
            if (sv5.getInboxWord() != null) {
                this.LJJ.setId(sv5.getInboxWord().getId());
                this.LJJ.setWordPosition(sv5.getInboxWord().getWordPosition());
                this.LJJ.setImplId(sv5.getInboxWord().getImplId());
            } else if (swj.LIZJ != null) {
                this.LJJ.setImplId(swj.LIZJ);
            }
        }
    }

    public void LIZ(View view) {
        this.LIZ = view.findViewById(2131365257);
        this.LIZIZ = (EditText) view.findViewById(2131364635);
        if (MJG.LIZIZ()) {
            this.LIZJ = view.findViewById(2131362964);
        } else {
            this.LIZJ = view.findViewById(2131362963);
        }
        this.LIZLLL = view.findViewById(2131369970);
        this.LJ = (TextView) view.findViewById(2131372294);
        this.LJIIIZ = (ImageView) view.findViewById(2131362573);
        this.LJIIJ = (FrameLayout) view.findViewById(2131365158);
        this.LJIIJJI = (SW2) view.findViewById(2131369934);
    }

    public final /* synthetic */ void LIZ(Boolean bool) {
        this.LJIJ = bool.booleanValue();
        if (bool.booleanValue()) {
            LJFF();
        }
    }

    public final void LIZ(CharSequence charSequence) {
        if (!TextUtils.isEmpty(charSequence) && this.LIZJ.getVisibility() == 8) {
            this.LIZJ.setVisibility(0);
            this.LIZIZ.setPadding((int) HeD.LIZIZ(getContext(), 32.5f), 0, (int) HeD.LIZIZ(getContext(), 32.5f), 0);
        } else if (TextUtils.isEmpty(charSequence) && this.LIZJ.getVisibility() == 0) {
            this.LIZJ.setVisibility(8);
            if (3F7.LIZ(getContext())) {
                this.LIZIZ.setPadding((int) HeD.LIZIZ(getContext(), 12.0f), 0, (int) HeD.LIZIZ(getContext(), 32.5f), 0);
            } else {
                this.LIZIZ.setPadding((int) HeD.LIZIZ(getContext(), 32.5f), 0, (int) HeD.LIZIZ(getContext(), 12.0f), 0);
            }
        }
        if (!TextUtils.equals(this.LJJII, charSequence)) {
            String charSequence2 = charSequence.toString();
            if (!TextUtils.isEmpty(this.LJJII) && TextUtils.isEmpty(charSequence2) && (!this.LJIJ)) {
                LIZIZ("cancel");
            }
            boolean isEmpty = TextUtils.isEmpty(this.LJJII);
            this.LJJII = charSequence2;
            if (TextUtils.isEmpty(charSequence)) {
                if (LJJII() != 1) {
                    LJJ();
                }
            } else if (LJJII() != 2) {
                C3334SUg sUg = C3334SUg.LIZ;
                M12.LIZ(charSequence2);
                sUg.LIZ(charSequence2).LIZIZ = isEmpty;
                LJJI();
            }
        }
    }

    public final void LIZ(Context context, SV0 sv0) {
        C4459Spj.LIZ.LIZ(context, sv0);
        LIZJ(sv0);
        LIZIZ(sv0);
        KeyboardUtils.LIZJ(this.LIZIZ);
    }

    public void onViewCreated(View view, Bundle bundle) {
        BaseDiscoverAndSearchFragment.super.onViewCreated(view, bundle);
        LIZIZ(LJIIIZ());
        if (LJIJJLI()) {
            2Rh.LIZIZ(this.LIZ);
        }
        SW2 sw2 = this.LJIIJJI;
        M12.LIZ(this, this);
        1hK activity = getActivity();
        if (activity == null) {
            n.LIZIZ();
        }
        n.LIZIZ(activity, "");
        sw2.LIZIZ = this;
        sw2.LJFF = C4459Spj.LIZ.LIZ((Activity) getActivity());
        0AA childFragmentManager = getChildFragmentManager();
        n.LIZIZ(childFragmentManager, "");
        sw2.LIZJ = childFragmentManager;
        0Bx LIZ2 = 0By.LIZ(activity, (0Bv) null);
        if (2GD.LIZ) {
            0Bs.LIZ(LIZ2, activity);
        }
        SearchIntermediateViewModel LIZ3 = LIZ2.LIZ(SearchIntermediateViewModel.class);
        n.LIZIZ(LIZ3, "");
        sw2.LIZ = LIZ3;
        SearchIntermediateViewModel searchIntermediateViewModel = sw2.LIZ;
        if (searchIntermediateViewModel == null) {
            n.LIZ("");
        }
        searchIntermediateViewModel.getIntermediateState().observe(this, sw2.LJII);
        SearchIntermediateViewModel searchIntermediateViewModel2 = sw2.LIZ;
        if (searchIntermediateViewModel2 == null) {
            n.LIZ("");
        }
        searchIntermediateViewModel2.getSearchTabIndex().observe(this, sw2.LJIIIIZZ);
        this.LJIIJJI.setOnDispatchTouchEventListener(new C3381SWb(this));
        LJIILL();
        LJIIJ();
        1hK activity2 = getActivity();
        if (a.LJIIZILJ().LIZ((45p) null) && activity2 != null && !activity2.isFinishing()) {
            a.LJIIZILJ().LIZ(activity2, "deeplink");
        }
        LJIL();
    }

    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View LIZ2 = 0HB.LIZ(getActivity(), LJIIIIZZ(), viewGroup, false);
        LIZ(LIZ2);
        return LIZ2;
    }
}
