From 323b1ba9f58fab66f524c8dc03ba7c4905ac544c Mon Sep 17 00:00:00 2001 From: fengyuecanzhu <1021300691@qq.com> Date: Wed, 11 May 2022 09:37:09 +0800 Subject: [PATCH] fix getEnableReadCrawlers --- .../xyz/fycz/myreader/model/SearchEngine.java | 8 +- .../webapi/crawler/ReadCrawlerUtil.java | 3 + .../main/java/xyz/fycz/dynamic/AppLoadImpl.kt | 4 +- .../java/xyz/fycz/dynamic/fix/App244Fix2.kt | 77 +++++++++++++++++++ 4 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 dynamic/src/main/java/xyz/fycz/dynamic/fix/App244Fix2.kt diff --git a/app/src/main/java/xyz/fycz/myreader/model/SearchEngine.java b/app/src/main/java/xyz/fycz/myreader/model/SearchEngine.java index bec483e..a4e7230 100644 --- a/app/src/main/java/xyz/fycz/myreader/model/SearchEngine.java +++ b/app/src/main/java/xyz/fycz/myreader/model/SearchEngine.java @@ -161,8 +161,8 @@ public class SearchEngine { searchSiteIndex++; if (searchSiteIndex < mSourceList.size()) { ReadCrawler crawler = mSourceList.get(searchSiteIndex); - //BookApi.search(keyword, crawler, executorService) - BookApi.search(keyword, crawler) + BookApi.search(keyword, crawler, executorService) + //BookApi.search(keyword, crawler) .subscribeOn(scheduler) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer>() { @@ -210,8 +210,8 @@ public class SearchEngine { if (searchSiteIndex < mSourceList.size()) { ReadCrawler crawler = mSourceList.get(searchSiteIndex); String searchKey = title; - //BookApi.search(searchKey, crawler, executorService) - BookApi.search(searchKey, crawler) + BookApi.search(searchKey, crawler, executorService) + //BookApi.search(searchKey, crawler) .subscribeOn(scheduler) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer>() { diff --git a/app/src/main/java/xyz/fycz/myreader/webapi/crawler/ReadCrawlerUtil.java b/app/src/main/java/xyz/fycz/myreader/webapi/crawler/ReadCrawlerUtil.java index e55f646..ef81df6 100644 --- a/app/src/main/java/xyz/fycz/myreader/webapi/crawler/ReadCrawlerUtil.java +++ b/app/src/main/java/xyz/fycz/myreader/webapi/crawler/ReadCrawlerUtil.java @@ -244,6 +244,9 @@ public class ReadCrawlerUtil { List sources = TextUtils.isEmpty(group) ? BookSourceManager.getEnabledBookSource() : BookSourceManager.getEnableSourceByGroup(group); + if (sources.size() == 0){ + sources = BookSourceManager.getEnabledBookSource(); + } for (BookSource source : sources) { crawlers.add(getReadCrawler(source)); } diff --git a/dynamic/src/main/java/xyz/fycz/dynamic/AppLoadImpl.kt b/dynamic/src/main/java/xyz/fycz/dynamic/AppLoadImpl.kt index 93ffd53..b42b82a 100644 --- a/dynamic/src/main/java/xyz/fycz/dynamic/AppLoadImpl.kt +++ b/dynamic/src/main/java/xyz/fycz/dynamic/AppLoadImpl.kt @@ -27,6 +27,7 @@ import me.fycz.maple.MapleUtils import me.fycz.maple.MethodHook import xyz.fycz.dynamic.fix.App243Fix import xyz.fycz.dynamic.fix.App244Fix +import xyz.fycz.dynamic.fix.App244Fix2 import xyz.fycz.dynamic.fix.AppFix import xyz.fycz.myreader.application.App import xyz.fycz.myreader.ui.activity.MainActivity @@ -45,7 +46,8 @@ class AppLoadImpl : IAppLoader { private val fixList = listOf( App243Fix::class.java, - App244Fix::class.java + App244Fix::class.java, + App244Fix2::class.java, ) override fun onLoad(appParam: AppParam) { diff --git a/dynamic/src/main/java/xyz/fycz/dynamic/fix/App244Fix2.kt b/dynamic/src/main/java/xyz/fycz/dynamic/fix/App244Fix2.kt new file mode 100644 index 0000000..55ec6cf --- /dev/null +++ b/dynamic/src/main/java/xyz/fycz/dynamic/fix/App244Fix2.kt @@ -0,0 +1,77 @@ +/* + * This file is part of FYReader. + * FYReader is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * FYReader is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with FYReader. If not, see . + * + * Copyright (C) 2020 - 2022 fengyuecanzhu + */ + +package xyz.fycz.dynamic.fix + +import android.text.TextUtils +import me.fycz.maple.MapleBridge +import me.fycz.maple.MapleUtils +import me.fycz.maple.MethodReplacement +import xyz.fycz.myreader.greendao.entity.Book +import xyz.fycz.myreader.model.sourceAnalyzer.BookSourceManager +import xyz.fycz.myreader.ui.adapter.BookcaseAdapter +import xyz.fycz.myreader.webapi.crawler.ReadCrawlerUtil +import xyz.fycz.myreader.webapi.crawler.base.ReadCrawler + +/** + * @author fengyue + * @date 2022/5/11 9:31 + */ +@AppFix([243, 244], ["修复搜索时当前分组不存在时无法搜索的问题"], "2022-05-11") +class App244Fix2 : AppFixHandle{ + override fun onFix(key: String): BooleanArray { + var fx = false + try { + fixGetEnableReadCrawlers() + fx = true + fixResult(key, "getEnableReadCrawlers", true) + } catch (e: Exception) { + MapleUtils.log(e) + fixResult(key, "getEnableReadCrawlers", false) + } + return booleanArrayOf(fx) + } + + private fun fixGetEnableReadCrawlers() { + MapleUtils.findAndHookMethod( + ReadCrawlerUtil::class.java, + "getEnableReadCrawlers", + String::class.java, + object : MethodReplacement() { + override fun replaceHookedMethod(param: MapleBridge.MethodHookParam): Any { + return getEnableReadCrawlers(param.args[0] as String) + } + } + ) + } + + fun getEnableReadCrawlers(group: String?): List { + val crawlers = ArrayList() + var sources = + if (group.isNullOrEmpty()) + BookSourceManager.getEnabledBookSource() + else BookSourceManager.getEnableSourceByGroup(group) + if (sources.size == 0) { + sources = BookSourceManager.getEnabledBookSource() + } + for (source in sources) { + crawlers.add(ReadCrawlerUtil.getReadCrawler(source)) + } + return crawlers + } +} \ No newline at end of file