From 0a47879d7f59d63d875c1f5a43362232ad398d01 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Sun, 3 Jan 2021 20:28:09 +0800 Subject: [PATCH] Fix compatibility of search with play ver --- .../java/me/iacn/biliroaming/hook/BangumiSeasonHook.kt | 9 ++++++--- .../java/me/iacn/biliroaming/network/BiliRoamingApi.kt | 10 +++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/me/iacn/biliroaming/hook/BangumiSeasonHook.kt b/app/src/main/java/me/iacn/biliroaming/hook/BangumiSeasonHook.kt index 7a57fcec19..3c074490a4 100644 --- a/app/src/main/java/me/iacn/biliroaming/hook/BangumiSeasonHook.kt +++ b/app/src/main/java/me/iacn/biliroaming/hook/BangumiSeasonHook.kt @@ -115,14 +115,17 @@ class BangumiSeasonHook(classLoader: ClassLoader) : BaseHook(classLoader) { url.startsWith("https://appintl.biliapi.net/intl/gateway/app/view")) && body.getIntField("code") == FAIL_CODE) { fixView(body, url) - } else if (url != null && url.startsWith("https://appintl.biliapi.net/intl/gateway/app/search/type")) { + } else if (url != null && url.startsWith("https://appintl.biliapi.net/intl/gateway/app/search/type") && !url.contains("type=$TH_TYPE")) { fixPlaySearchType(body, url) } else if (instance.generalResponseClass?.isInstance(body) == true) { val data = body.getObjectField("data") ?: return@hookBeforeAllConstructors if (data.javaClass == searchAllResultClass) { addThailandTag(data) } - if (url != null && data.javaClass == bangumiSearchPageClass && url.startsWith("https://app.bilibili.com/x/v2/search/type") && url.contains("type=$TH_TYPE")) { + if (url != null && data.javaClass == bangumiSearchPageClass && + (url.startsWith("https://app.bilibili.com/x/v2/search/type") || + url.startsWith("https://appintl.biliapi.net/intl/gateway/app/search/type")) + && url.contains("type=$TH_TYPE")) { body.setObjectField("data", retrieveThailandSearch(data, url)) } } @@ -156,7 +159,7 @@ class BangumiSeasonHook(classLoader: ClassLoader) : BaseHook(classLoader) { if (sPrefs.getBoolean("hidden", false) && sPrefs.getBoolean("search_th", false)) { "com.bilibili.bangumi.ui.page.search.BangumiSearchResultFragment".findClassOrNull(mClassLoader)?.run { - hookBeforeMethod("loadFirstPage") { param -> + hookBeforeMethod("setUserVisibleCompat", Boolean::class.javaPrimitiveType) { param -> param.thisObject.callMethodAs("getArguments").run { if (getString("from") == "th") { declaredFields.filter { diff --git a/app/src/main/java/me/iacn/biliroaming/network/BiliRoamingApi.kt b/app/src/main/java/me/iacn/biliroaming/network/BiliRoamingApi.kt index 94a4017a27..5fcdd35598 100644 --- a/app/src/main/java/me/iacn/biliroaming/network/BiliRoamingApi.kt +++ b/app/src/main/java/me/iacn/biliroaming/network/BiliRoamingApi.kt @@ -83,7 +83,8 @@ object BiliRoamingApi { "build" to "1001310", "mobi_app" to "bstar_a", "platform" to "android", - "s_locale" to "zh_SG" + "s_locale" to "zh_SG", + "c_locale" to "zh_SG" ))) .toString() return getContent(uri)?.replace("bstar://bangumi/season/", "https://bangumi.bilibili.com/anime/") @@ -388,7 +389,7 @@ object BiliRoamingApi { @SuppressLint("SetJavaScriptEnabled") fun getContent(urlString: String): String? { - val timeout = 5000 + val timeout = 10000 return try { // Work around for android 7 if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N && @@ -415,7 +416,10 @@ object BiliRoamingApi { view?.loadUrl("javascript:listener.callback(document.documentElement.innerText)") } } - webView.loadUrl(urlString) + webView.loadUrl(urlString, mapOf( + "x-from-biliroaming" to BuildConfig.VERSION_NAME, + "Build" to BuildConfig.VERSION_CODE.toString() + )) } try { if (!listener.latch.await((timeout * 2).toLong(), TimeUnit.MILLISECONDS)) {