From 746562362223d471afd345c93c2fb77c4d1597a2 Mon Sep 17 00:00:00 2001 From: david082321 Date: Mon, 27 Sep 2021 18:00:07 +0800 Subject: [PATCH] Remove area search when didn't fill input box (#276) --- .../biliroaming/hook/BangumiSeasonHook.kt | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 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 3b0136d364..db9f20f43c 100644 --- a/app/src/main/java/me/iacn/biliroaming/hook/BangumiSeasonHook.kt +++ b/app/src/main/java/me/iacn/biliroaming/hook/BangumiSeasonHook.kt @@ -293,16 +293,24 @@ class BangumiSeasonHook(classLoader: ClassLoader) : BaseHook(classLoader) { mClassLoader ) val pageArrays = pageTypesClass.getStaticObjectFieldAs>("\$VALUES") - val newPageArray = pageArrays.copyOf(pageArrays.size + 4) var counter = 0 for (area in AREA_TYPES) { - newPageArray[pageArrays.size + counter++] = pageTypesClass.new( - "PAGE_BANGUMI", - 4, - "bilibili://search-result/new-bangumi?from=" + area.value.type, - area.key, - "bangumi" - ) + if (!sPrefs.getString(area.value.type + "_server", null).isNullOrBlank()) { + counter++ + } + } + val newPageArray = pageArrays.copyOf(pageArrays.size + counter) + counter = 0 + for (area in AREA_TYPES) { + if (!sPrefs.getString(area.value.type + "_server", null).isNullOrBlank()) { + newPageArray[pageArrays.size + counter++] = pageTypesClass.new( + "PAGE_BANGUMI", + 4, + "bilibili://search-result/new-bangumi?from=" + area.value.type, + area.key, + "bangumi" + ) + } } pageTypesClass.setStaticObjectField("\$VALUES", newPageArray) } @@ -340,13 +348,15 @@ class BangumiSeasonHook(classLoader: ClassLoader) : BaseHook(classLoader) { body ?: return if (sPrefs.getBoolean("hidden", false) && sPrefs.getBoolean("search_area", false)) { for (area in AREA_TYPES) { - searchAllResultNavInfoClass?.new()?.run { - setObjectField("name", area.value.text) - setIntField("pages", 0) - setIntField("total", 0) - setIntField("type", area.key) - }?.also { - body.getObjectFieldAs>("nav").add(1, it) + if (!sPrefs.getString(area.value.type + "_server", null).isNullOrBlank()) { + searchAllResultNavInfoClass?.new()?.run { + setObjectField("name", area.value.text) + setIntField("pages", 0) + setIntField("total", 0) + setIntField("type", area.key) + }?.also { + body.getObjectFieldAs>("nav").add(1, it) + } } } }