导航菜单

页面标题

页面副标题

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

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

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


package com.bilibili.tv.provider;

import android.content.SearchRecentSuggestionsProvider;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;
import android.text.TextUtils;
import bl.bbg;
import bl.bbi;
import bl.blv;
import bl.kt;
import bl.vo;
import com.bilibili.okretro.BiliApiParseException;
import com.bilibili.okretro.GeneralResponse;
import com.bilibili.tv.api.TvApiService;
import com.bilibili.tv.api.search.BiliSearchSuggest;
import com.bilibili.tv.api.search.SuggestParser;
import java.io.IOException;
import java.util.List;
import kotlin.TypeCastException;
import tv.danmaku.android.log.BLog;

public final class TvSearchSuggestionProvider extends SearchRecentSuggestionsProvider {
    public static final a Companion = new a(null);

    public TvSearchSuggestionProvider() {
        setupSuggestions("com.bilibili.tv.provider.TvSearchSuggestionProvider", 1);
    }

    @Override
    public Cursor query(Uri uri, String[] strArr, String str, String[] strArr2, String str2) {
        List<BiliSearchSuggest> list;
        bbi.b(uri, "uri");
        if (strArr2 == null) {
            bbi.a();
        }
        String str3 = strArr2[0];
        String str4 = str3;
        if (str4.length() == 0) {
            return a(uri, strArr, str, strArr2, "suggest_intent_query");
        }
        int i = 64;
        MatrixCursor matrixCursor = new MatrixCursor(new String[]{"_id", "suggest_intent_query", "suggest_text_1", "suggest_text_2_url"});
        String[] strArr3 = new String[4];
        String str5 = (String) null;
        if (TextUtils.isDigitsOnly(str4)) {
            if (blv.a(str4, -1) > 0) {
                String str6 = "<em class=\"suggest_high_light\">" + str3 + "</em>";
                bbi.a((Object) str6, "sb.append(MatchKeywordMa…_REPLACE_MARK).toString()");
                str5 = "av" + str6;
            }
        } else if (kt.e(str4, "av") && str3.length() > 2) {
            if (str3 == null) {
                throw new TypeCastException("null cannot be cast to non-null type java.lang.String");
            }
            String substring = str3.substring(2);
            bbi.a((Object) substring, "(this as java.lang.String).substring(startIndex)");
            if (TextUtils.isDigitsOnly(substring)) {
                str5 = "av<em class=\"suggest_high_light\">" + substring + "</em>";
                bbi.a((Object) str5, "sb.append(\"av\").append(M…_REPLACE_MARK).toString()");
            } else {
                str5 = str3;
            }
        }
        if (str5 != null) {
            strArr3[0] = Integer.toString(64);
            strArr3[2] = str5;
            strArr3[1] = strArr3[2];
            StringBuilder sb = new StringBuilder();
            sb.append("bilibili://video/");
            String substring2 = str5.substring(2);
            bbi.a((Object) substring2, "(this as java.lang.String).substring(startIndex)");
            sb.append(substring2);
            strArr3[3] = sb.toString();
            matrixCursor.addRow(strArr3);
            i = 65;
        }
        if (str3.length() < 1) {
            return matrixCursor;
        }
        try {
            GeneralResponse<List<BiliSearchSuggest>> f = ((TvApiService) vo.a(TvApiService.class)).suggest(str3).a(new SuggestParser()).d().f();
            if (f != null && (list = f.data) != null) {
                for (BiliSearchSuggest biliSearchSuggest : list) {
                    int i2 = i + 1;
                    strArr3[0] = Integer.toString(i);
                    strArr3[1] = str3;
                    bbi.a((Object) biliSearchSuggest, "item");
                    a(strArr3, biliSearchSuggest);
                    matrixCursor.addRow(strArr3);
                    i = i2;
                }
            }
        } catch (BiliApiParseException e) {
            BLog.e(e.toString());
        } catch (IOException e2) {
            BLog.e(e2.toString());
        }
        return matrixCursor;
    }

    private final Cursor a(Uri uri, String[] strArr, String str, String[] strArr2, String str2) {
        Cursor cursor;
        Cursor cursor2 = (Cursor) null;
        try {
            cursor = super.query(uri, strArr, str, strArr2, str2);
        } catch (Exception unused) {
            cursor = cursor2;
        }
        if (cursor == null) {
            return new MatrixCursor(new String[0]);
        }
        MatrixCursor matrixCursor = new MatrixCursor(new String[]{"_id", "suggest_intent_query", "suggest_text_1"});
        while (cursor.moveToNext()) {
            String[] strArr3 = new String[3];
            strArr3[0] = cursor.getString(cursor.getColumnIndex("_id"));
            strArr3[2] = cursor.getString(cursor.getColumnIndex("suggest_intent_query"));
            strArr3[1] = strArr3[2];
            matrixCursor.addRow(strArr3);
        }
        cursor.close();
        return matrixCursor;
    }

    private final void a(String[] strArr, BiliSearchSuggest biliSearchSuggest) {
        strArr[2] = biliSearchSuggest.name;
        strArr[3] = (String) null;
    }

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

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

        public final Uri a(String str) {
            bbi.b(str, "query");
            Uri.Builder fragment = new Uri.Builder().scheme("content").authority("com.bilibili.tv.provider.TvSearchSuggestionProvider").query("").fragment("");
            fragment.appendPath("search_suggest_query");
            Uri build = fragment.build();
            bbi.a((Object) build, "uriBuilder.build()");
            return build;
        }
    }
}