导航菜单

页面标题

页面副标题

哔哩哔哩 v1.6.6 - SearchActivity.java 源代码

正在查看: 哔哩哔哩 v1.6.6 应用的 SearchActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.bilibili.tv.ui.search;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.provider.SearchRecentSuggestions;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import bl.adl;
import bl.afh;
import bl.afi;
import bl.agb;
import bl.baf;
import bl.bbg;
import bl.bbi;
import bl.lk;
import bl.lr;
import bl.ok;
import bl.wf;
import bl.wg;
import com.bilibili.tv.api.category.CategoryManager;
import com.bilibili.tv.api.category.CategoryMeta;
import com.bilibili.tv.ui.base.BaseActivity;
import com.bilibili.tv.ui.search.SearchKeyboardView;
import com.bilibili.tv.ui.video.VideoDetailActivity;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.ListIterator;
import kotlin.TypeCastException;
import kotlin.text.Regex;
import tv.danmaku.android.log.BLog;

public final class SearchActivity extends BaseActivity implements View.OnLongClickListener, wf {
    private static final String j = "SearchActivity";
    private static final String k = "com.bilibili.tv.ui.search.SearchActivity.EXTRA_TID";
    public View a;
    private SearchKeyboardView b;
    private boolean c;
    private boolean d;
    private int e;
    private afh f;
    private afi g;
    private int h;
    private String i;
    public static final a Companion = new a(null);
    private static final String[] l = {"totalrank", "click", "pubdate", "dm"};
    private static final String[] m = {"totalrank", "fans", "fansasc", "lv", "lvasc"};
    public static final String[] live_orders = {"online", "live_time"};

    @Override
    public String a() {
        return "ott-search.search.0.0.pv";
    }

    @Override
    public boolean a_() {
        return wg.a(this);
    }

    @Override
    public Bundle b() {
        return null;
    }

    @Override
    public int g() {
        return 2131361827;
    }

    public final SearchKeyboardView h() {
        return this.b;
    }

    public final View i() {
        View view = this.a;
        if (view == null) {
            bbi.b("focusHolder");
        }
        return view;
    }

    public final void setFocusHolder(View view) {
        bbi.b(view, "<set-?>");
        this.a = view;
    }

    public final void a(boolean z) {
        this.c = z;
    }

    public final boolean j() {
        return this.c;
    }

    public final void b(boolean z) {
        this.d = z;
    }

    public final boolean k() {
        return this.d;
    }

    public static final class a {
        private a() {
        }

        public a(bbg bbgVar) {
            this();
        }

        public final String a() {
            return SearchActivity.j;
        }

        public final String b() {
            return SearchActivity.k;
        }

        public final String[] c() {
            return SearchActivity.l;
        }

        public final String[] d() {
            return SearchActivity.m;
        }

        public final void a(Context context, Integer num) {
            Intent intent = new Intent(context, (Class<?>) SearchActivity.class);
            intent.putExtra(b(), num);
            if (context != null) {
                context.startActivity(intent);
            }
        }
    }

    @Override
    public void a(Bundle bundle) {
        if (getIntent() != null) {
            this.e = getIntent().getIntExtra(k, 0);
            BLog.i(j, "search tid is " + this.e);
        }
        this.b = (SearchKeyboardView) d(2131230890);
        this.a = d(2131230863);
        SearchKeyboardView searchKeyboardView = this.b;
        if (searchKeyboardView == null) {
            bbi.a();
        }
        searchKeyboardView.setSearchCallback(new b());
        String str = "首页";
        CategoryMeta primaryCategoryBy = CategoryManager.getPrimaryCategoryBy(getApplicationContext(), this.e);
        if (this.e != 0 && primaryCategoryBy != null) {
            str = primaryCategoryBy.mTypeName;
            bbi.a((Object) str, "categoryMeta.mTypeName");
        }
        ok.a("tv_search_pageview", "from", str);
        SearchKeyboardView searchKeyboardView2 = this.b;
        if (searchKeyboardView2 == null) {
            bbi.a();
        }
        searchKeyboardView2.requestFocus();
    }

    public final class b implements SearchKeyboardView.f {
        b() {
        }

        @Override
        public void a() {
            if (!SearchActivity.this.q()) {
                SearchActivity.this.t();
            }
            afh afhVar = SearchActivity.this.f;
            if (afhVar == null) {
                bbi.a();
            }
            afhVar.b();
            SearchActivity.this.i = "";
        }

        @Override
        public void a(String str) {
            bbi.b(str, "text");
            BLog.d(SearchActivity.Companion.a(), "get suggestion for " + str);
            if (!TextUtils.isEmpty(str) && str.length() > 0) {
                if (!SearchActivity.this.q()) {
                    SearchActivity.this.t();
                }
                afh afhVar = SearchActivity.this.f;
                if (afhVar == null) {
                    bbi.a();
                }
                afhVar.a(str);
            }
        }

        @Override
        public void b(String str) {
            bbi.b(str, "searchText");
            if (TextUtils.isEmpty(str)) {
                lr.b(SearchActivity.this, SearchActivity.this.getString(2131493123));
            } else {
                SearchActivity.this.a(str);
            }
        }
    }

    @Override
    public void onPostCreate(Bundle bundle) {
        super.onPostCreate(bundle);
        t();
    }

    public final void a(String str) {
        long j2;
        bbi.b(str, "text");
        BLog.i(j, "search " + str);
        if (!TextUtils.isEmpty(str)) {
            this.i = str;
            View view = this.a;
            if (view == null) {
                bbi.b("focusHolder");
            }
            view.setFocusable(true);
            View view2 = this.a;
            if (view2 == null) {
                bbi.b("focusHolder");
            }
            view2.requestFocus();
            this.c = true;
            SearchKeyboardView searchKeyboardView = this.b;
            if (searchKeyboardView == null) {
                bbi.a();
            }
            searchKeyboardView.getSearchText().setFocusable(false);
            SearchKeyboardView searchKeyboardView2 = this.b;
            if (searchKeyboardView2 == null) {
                bbi.a();
            }
            searchKeyboardView2.setSearchText(str);
            View currentFocus = getCurrentFocus();
            if (currentFocus instanceof EditText) {
                currentFocus.clearFocus();
                lk.a(this);
            }
            u();
            afi afiVar = this.g;
            if (afiVar == null) {
                bbi.a();
            }
            afiVar.a(str);
            b(str);
            List<String> a2 = new Regex("AVAV").a(str, 0);
            if (!a2.isEmpty()) {
                ListIterator<String> listIterator = a2.listIterator(a2.size());
                while (true) {
                    if (!listIterator.hasPrevious()) {
                        break;
                    } else if (listIterator.previous().length() != 0) {
                        baf.b(a2, listIterator.nextIndex() + 1);
                        break;
                    }
                }
            }
            List a3 = baf.a();
            if (a3 == null) {
                throw new TypeCastException("null cannot be cast to non-null type java.util.Collection<T>");
            }
            Object[] array = a3.toArray(new String[0]);
            if (array == null) {
                throw new TypeCastException("null cannot be cast to non-null type kotlin.Array<T>");
            }
            String[] strArr = (String[]) array;
            if (strArr.length > 1) {
                String str2 = strArr[0];
                if (TextUtils.equals(str2, strArr[1])) {
                    try {
                        Long valueOf = Long.valueOf(str2);
                        if (valueOf == null) {
                            bbi.a();
                        }
                        j2 = valueOf.longValue();
                    } catch (NumberFormatException e2) {
                        j2 = 0;
                    }
                    if (j2 != 0) {
                        startActivity(VideoDetailActivity.Companion.a(this, j2));
                    }
                }
            }
        }
    }

    private final void b(String str) {
        new SearchRecentSuggestions(this, "com.bilibili.tv.provider.TvSearchSuggestionProvider", 1).saveRecentQuery(str, null);
    }

    public final boolean q() {
        if (this.f != null) {
            afh afhVar = this.f;
            if (afhVar == null) {
                bbi.a();
            }
            if (afhVar.isVisible()) {
                return true;
            }
        }
        return false;
    }

    private final boolean r() {
        if (this.g != null) {
            afi afiVar = this.g;
            if (afiVar == null) {
                bbi.a();
            }
            if (afiVar.isVisible()) {
                return true;
            }
        }
        return false;
    }

    public final View l() {
        SearchKeyboardView searchKeyboardView = this.b;
        if (searchKeyboardView == null) {
            bbi.a();
        }
        View k2 = searchKeyboardView.k(this.h);
        if (k2 == null) {
            SearchKeyboardView searchKeyboardView2 = this.b;
            if (searchKeyboardView2 == null) {
                bbi.a();
            }
            return searchKeyboardView2.k(6);
        }
        if (this.h == 0) {
            SearchKeyboardView searchKeyboardView3 = this.b;
            if (searchKeyboardView3 == null) {
                bbi.a();
            }
            searchKeyboardView3.getSearchText().setFocusable(true);
            return k2;
        }
        return k2;
    }

    private final void s() {
        SearchKeyboardView searchKeyboardView = this.b;
        if (searchKeyboardView != null) {
            searchKeyboardView.B();
        }
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent keyEvent) {
        if (this.b == null) {
            return super.dispatchKeyEvent(keyEvent);
        }
        Integer valueOf = keyEvent != null ? Integer.valueOf(keyEvent.getAction()) : null;
        Integer valueOf2 = keyEvent != null ? Integer.valueOf(keyEvent.getKeyCode()) : null;
        if (valueOf != null && valueOf.intValue() == 0) {
            View currentFocus = getCurrentFocus();
            if (currentFocus == null) {
                return super.dispatchKeyEvent(keyEvent);
            }
            if (valueOf2 != null && valueOf2.intValue() == 21) {
                View view = this.a;
                if (view == null) {
                    bbi.b("focusHolder");
                }
                if (currentFocus == view) {
                    return true;
                }
            } else if (valueOf2 != null && valueOf2.intValue() == 22) {
                View view2 = this.a;
                if (view2 == null) {
                    bbi.b("focusHolder");
                }
                if (currentFocus == view2) {
                    return true;
                }
                Object parent = currentFocus.getParent();
                if (!(parent instanceof View)) {
                    parent = null;
                }
                View view3 = (View) parent;
                if (view3 == this.b) {
                    SearchKeyboardView searchKeyboardView = this.b;
                    if (searchKeyboardView == null) {
                        bbi.a();
                    }
                    int g = searchKeyboardView.g(currentFocus);
                    if (g == 0 || g % 6 == 0 || g == 39) {
                        this.h = g;
                        if (q()) {
                            afh afhVar = this.f;
                            if (afhVar == null) {
                                bbi.a();
                            }
                            afhVar.a();
                        } else if (r()) {
                            afi afiVar = this.g;
                            if (afiVar == null) {
                                bbi.a();
                            }
                            afiVar.d();
                        }
                        return true;
                    }
                } else {
                    Object tag = view3 != null ? view3.getTag() : null;
                    if (!(tag instanceof CharSequence)) {
                        tag = null;
                    }
                    if (TextUtils.equals((CharSequence) tag, "search_layout")) {
                        SearchKeyboardView searchKeyboardView2 = this.b;
                        if (searchKeyboardView2 == null) {
                            bbi.a();
                        }
                        View k2 = searchKeyboardView2.k(39);
                        if (k2 != null) {
                            k2.requestFocus();
                            return true;
                        }
                    }
                }
            } else if (valueOf2 != null && valueOf2.intValue() == 19) {
                View view4 = this.a;
                if (view4 == null) {
                    bbi.b("focusHolder");
                }
                if (currentFocus == view4) {
                    return true;
                }
            } else if (valueOf2 != null && valueOf2.intValue() == 20) {
                View view5 = this.a;
                if (view5 == null) {
                    bbi.b("focusHolder");
                }
                if (currentFocus == view5) {
                    return true;
                }
                SearchKeyboardView searchKeyboardView3 = this.b;
                if (searchKeyboardView3 == null) {
                    bbi.a();
                }
                if (currentFocus == searchKeyboardView3.getSearchText()) {
                    SearchKeyboardView searchKeyboardView4 = this.b;
                    if (searchKeyboardView4 == null) {
                        bbi.a();
                    }
                    searchKeyboardView4.j(1);
                    return true;
                }
            } else if (valueOf2 != null && valueOf2.intValue() == 4) {
                SearchKeyboardView searchKeyboardView5 = this.b;
                if (searchKeyboardView5 == null) {
                    bbi.a();
                }
                if (searchKeyboardView5.getSearchText().getText().toString().length() > 0) {
                    s();
                    SearchKeyboardView searchKeyboardView6 = this.b;
                    if (searchKeyboardView6 == null) {
                        bbi.a();
                    }
                    searchKeyboardView6.j(1);
                    return true;
                }
            }
        }
        return super.dispatchKeyEvent(keyEvent);
    }

    public final void t() {
        FragmentManager supportFragmentManager = getSupportFragmentManager();
        Fragment findFragmentByTag = supportFragmentManager.findFragmentByTag(afh.Companion.a());
        if (!(findFragmentByTag instanceof afh)) {
            findFragmentByTag = null;
        }
        this.f = (afh) findFragmentByTag;
        if (this.f == null) {
            this.f = afh.Companion.b();
        }
        afh afhVar = this.f;
        if (afhVar == null) {
            bbi.a();
        }
        if (!afhVar.isAdded()) {
            supportFragmentManager.beginTransaction().add(2131230865, this.f, afh.Companion.a()).commitAllowingStateLoss();
            return;
        }
        FragmentTransaction show = supportFragmentManager.beginTransaction().show(this.f);
        if (r()) {
            show.hide(this.g);
        }
        adl.a.a(supportFragmentManager, show);
    }

    private final void u() {
        FragmentManager supportFragmentManager = getSupportFragmentManager();
        Fragment findFragmentByTag = supportFragmentManager.findFragmentByTag(afi.Companion.a());
        if (!(findFragmentByTag instanceof afi)) {
            findFragmentByTag = null;
        }
        this.g = (afi) findFragmentByTag;
        if (this.g == null) {
            this.g = afi.Companion.a(this.e);
        }
        afi afiVar = this.g;
        if (afiVar == null) {
            bbi.a();
        }
        if (!afiVar.isAdded()) {
            FragmentTransaction add = supportFragmentManager.beginTransaction().add(2131230865, this.g, afi.Companion.a());
            if (this.f != null) {
                add.hide(this.f);
            }
            adl.a.a(supportFragmentManager, add);
            return;
        }
        FragmentTransaction show = supportFragmentManager.beginTransaction().show(this.g);
        if (q()) {
            show.hide(this.f);
        }
        adl.a.a(supportFragmentManager, show);
    }

    @Override
    public boolean onLongClick(View view) {
        bbi.b(view, "v");
        if (q()) {
            afh afhVar = this.f;
            if (afhVar == null) {
                bbi.a();
            }
            if (afhVar.c()) {
                agb.a aVar = new agb.a(this);
                aVar.a(1).a("确认清除搜索历史?").b(getString(2131492985), new c()).a(getString(2131492982), d.a);
                aVar.a().show();
                return true;
            }
        }
        if (r() && !this.g.j()) {
            LinkedHashMap<String, Object> linkedHashMap = new LinkedHashMap<>();
            if (this.g.i()) {
                linkedHashMap.put(adl.e(2131493127), m[0]);
                linkedHashMap.put(adl.e(2131493128), m[1]);
                linkedHashMap.put(adl.e(2131493129), m[2]);
                linkedHashMap.put(adl.e(2131493130), m[3]);
                linkedHashMap.put(adl.e(2131493131), m[4]);
                agb.a aVar2 = new agb.a(this);
                aVar2.a(2).a(adl.e(2131493194)).a(linkedHashMap, new e(linkedHashMap)).a((Object) this.g.b());
                aVar2.a().show();
            } else if (this.g.is_live()) {
                linkedHashMap.put("在线人数", live_orders[0]);
                linkedHashMap.put("开播时长", live_orders[1]);
                agb.a aVar3 = new agb.a(this);
                aVar3.a(2).a(adl.e(2131493194)).a(linkedHashMap, new ee(linkedHashMap)).a((Object) this.g.live_order);
                aVar3.a().show();
            } else {
                linkedHashMap.put(adl.e(2131493127), l[0]);
                linkedHashMap.put(adl.e(2131493124), l[1]);
                linkedHashMap.put(adl.e(2131493126), l[2]);
                linkedHashMap.put(adl.e(2131493125), l[3]);
                agb.a aVar4 = new agb.a(this);
                aVar4.a(2).a(adl.e(2131493194)).a(linkedHashMap, new f(linkedHashMap)).a((Object) this.g.a());
                aVar4.a().show();
            }
        }
        return true;
    }

    final class c implements agb.b {
        c() {
        }

        @Override
        public final void a(agb agbVar, View view) {
            SearchActivity.this.f.d();
            ok.a("tv_search_clearall_click", new String[0]);
            agbVar.dismiss();
        }
    }

    static final class d implements agb.b {
        public static final d a = new d();

        d() {
        }

        @Override
        public final void a(agb agbVar, View view) {
            agbVar.dismiss();
        }
    }

    final class e implements agb.c {
        final LinkedHashMap b;

        e(LinkedHashMap linkedHashMap) {
            this.b = linkedHashMap;
        }

        @Override
        public final void a(agb agbVar, View view, String str) {
            SearchActivity.this.g.c((String) this.b.get(str));
            agbVar.dismiss();
        }
    }

    final class ee implements agb.c {
        final LinkedHashMap b;

        ee(LinkedHashMap linkedHashMap) {
            this.b = linkedHashMap;
        }

        @Override
        public final void a(agb agbVar, View view, String str) {
            SearchActivity.this.g.cc((String) this.b.get(str));
            agbVar.dismiss();
        }
    }

    final class f implements agb.c {
        final LinkedHashMap b;

        f(LinkedHashMap linkedHashMap) {
            this.b = linkedHashMap;
        }

        @Override
        public final void a(agb agbVar, View view, String str) {
            String str2;
            String str3 = (String) this.b.get(str);
            SearchActivity.this.g.b(str3);
            if (TextUtils.equals(str3, SearchActivity.Companion.c()[0])) {
                str2 = "1";
            } else if (TextUtils.equals(str3, SearchActivity.Companion.c()[2])) {
                str2 = "3";
            } else if (TextUtils.equals(str3, SearchActivity.Companion.c()[1])) {
                str2 = "4";
            } else if (!TextUtils.equals(str3, SearchActivity.Companion.c()[3])) {
                str2 = "";
            } else {
                str2 = "5";
            }
            ok.a("tv_search_result_index_sort_click", "type", str2);
            agbVar.dismiss();
        }
    }
}