diff --git a/app/build.gradle b/app/build.gradle index 7ebca8006..c3320ce89 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -160,7 +160,7 @@ dependencies { implementation('androidx.core:core-ktx:1.10.1') implementation('androidx.appcompat:appcompat:1.6.1') implementation('androidx.activity:activity-ktx:1.7.2') - implementation('androidx.fragment:fragment-ktx:1.5.7') + implementation('androidx.fragment:fragment-ktx:1.6.0') implementation('androidx.preference:preference-ktx:1.2.0') implementation('androidx.constraintlayout:constraintlayout:2.1.4') implementation('androidx.swiperefreshlayout:swiperefreshlayout:1.1.0') diff --git a/app/cronetlib/cronet_api.jar b/app/cronetlib/cronet_api.jar index 1df93ef04..36f94ff4d 100644 Binary files a/app/cronetlib/cronet_api.jar and b/app/cronetlib/cronet_api.jar differ diff --git a/app/cronetlib/cronet_impl_common_java.jar b/app/cronetlib/cronet_impl_common_java.jar index 2fe3f4282..2e1311187 100644 Binary files a/app/cronetlib/cronet_impl_common_java.jar and b/app/cronetlib/cronet_impl_common_java.jar differ diff --git a/app/src/main/assets/cronet.json b/app/src/main/assets/cronet.json index 40a9ca12c..20db6c2b6 100644 --- a/app/src/main/assets/cronet.json +++ b/app/src/main/assets/cronet.json @@ -1 +1 @@ -{"x86":"86a6007bc94a30af4bc61789d28a8f00","armeabi-v7a":"309165f6aac13e01023448a22e9495f2","x86_64":"2ff1e1f490daf7ed535c081807661f7d","arm64-v8a":"722ae9a6b64c1643f5b9db41509342e5","version":"114.0.5735.57"} \ No newline at end of file +{"x86":"46d237d466eddce29196b3f9a71aa23a","armeabi-v7a":"9507ec16a4a3141c4cfd50bec40cdb33","x86_64":"fad87777baadfee3cbc4bd6217519283","arm64-v8a":"68790ba327b8c180e206bd7c61f8254d","version":"114.0.5735.60"} \ No newline at end of file diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 1e9e86511..34047bdbe 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -13,6 +13,7 @@ * 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源! **2023/06/11** +* 更新cronet: 114.0.5735.60 * 修复长按菜单全文搜索结果不全或无结果问题 * 优化全文搜索速度 diff --git a/app/src/main/java/io/legado/app/base/adapter/RecyclerAdapter.kt b/app/src/main/java/io/legado/app/base/adapter/RecyclerAdapter.kt index fd5288016..d45502c28 100644 --- a/app/src/main/java/io/legado/app/base/adapter/RecyclerAdapter.kt +++ b/app/src/main/java/io/legado/app/base/adapter/RecyclerAdapter.kt @@ -161,7 +161,7 @@ abstract class RecyclerAdapter(protected val context: Co onCurrentListChanged() } } - handler.postDelayed(1000) { + handler.postDelayed(500) { if (diffJob?.isCompleted == false) { diffJob?.cancel() setItems(items) diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index 2ddb94eeb..c82b849e6 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -727,15 +727,13 @@ interface JsExtensions : JsEncodeUtils { var qTTF = CacheManager.getQueryTTF(key) if (qTTF != null) return qTTF val font: ByteArray? = when { - str.isAbsUrl() -> runBlocking { + str.isAbsUrl() -> { var x = CacheManager.getByteArray(key) if (x == null) { x = AnalyzeUrl(str, source = getSource()).getByteArray() - x.let { - CacheManager.put(key, it) - } + CacheManager.put(key, x) } - return@runBlocking x + x } str.isContentScheme() -> Uri.parse(str).readBytes(appCtx) diff --git a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt index 7905e354a..8dd9034a5 100644 --- a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt +++ b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt @@ -71,7 +71,7 @@ val okHttpClient: OkHttpClient by lazy { }) .addNetworkInterceptor { chain -> var request = chain.request() - val enableCookieJar = request.header(cookieJarHeader) != null + val enableCookieJar = request.header(cookieJarHeader) != null if (enableCookieJar) { val requestBuilder = request.newBuilder() diff --git a/app/src/main/java/io/legado/app/help/source/SourceVerificationHelp.kt b/app/src/main/java/io/legado/app/help/source/SourceVerificationHelp.kt index 908ad1a1f..432fcd081 100644 --- a/app/src/main/java/io/legado/app/help/source/SourceVerificationHelp.kt +++ b/app/src/main/java/io/legado/app/help/source/SourceVerificationHelp.kt @@ -8,55 +8,73 @@ import io.legado.app.help.IntentData import io.legado.app.ui.association.VerificationCodeActivity import io.legado.app.ui.browser.WebViewActivity import io.legado.app.utils.startActivity -import kotlinx.coroutines.runBlocking import splitties.init.appCtx +import java.util.concurrent.locks.LockSupport +import kotlin.time.Duration.Companion.minutes object SourceVerificationHelp { - private var key: String = "" - /** + private val waitTime = 1.minutes.inWholeNanoseconds + + private fun getKey(source: BaseSource) = getKey(source.getKey()) + fun getKey(sourceKey: String) = "${sourceKey}_verificationResult" + + /** * 获取书源验证结果 * 图片验证码 防爬 滑动验证码 点击字符 等等 */ - fun getVerificationResult(source: BaseSource?, url: String, title: String, useBrowser: Boolean): String { - source ?: throw NoStackTraceException("getVerificationResult parameter source cannot be null") - return runBlocking { - key = "${source.getKey()}_verificationResult" - CacheManager.delete(key) + fun getVerificationResult( + source: BaseSource?, + url: String, + title: String, + useBrowser: Boolean + ): String { + source + ?: throw NoStackTraceException("getVerificationResult parameter source cannot be null") - if (!useBrowser) { - appCtx.startActivity { - putExtra("imageUrl", url) - putExtra("sourceOrigin", source.getKey()) - putExtra("sourceName", source.getTag()) - } - } else { - startBrowser(source, url, title, true) - } + val key = getKey(source) + CacheManager.delete(key) - var waitUserInput = false - while(CacheManager.get(key) == null) { - if (!waitUserInput) { - AppLog.putDebug("等待返回验证结果...") - waitUserInput = true - } + if (!useBrowser) { + appCtx.startActivity { + putExtra("imageUrl", url) + putExtra("sourceOrigin", source.getKey()) + putExtra("sourceName", source.getTag()) + IntentData.put(key, Thread.currentThread()) } - CacheManager.get(key)!!.let { - it.ifBlank { - throw NoStackTraceException("验证结果为空") - } + } else { + startBrowser(source, url, title, true) + } + + var waitUserInput = false + while (CacheManager.get(key) == null) { + if (!waitUserInput) { + AppLog.putDebug("等待返回验证结果...") + waitUserInput = true } - } + LockSupport.parkNanos(this, waitTime) + } + + return CacheManager.get(key)!!.let { + it.ifBlank { + throw NoStackTraceException("验证结果为空") + } + } } /** * 启动内置浏览器 - @param saveResult 保存网页源代码到数据库 + * @param saveResult 保存网页源代码到数据库 */ - fun startBrowser(source: BaseSource?, url: String, title: String, saveResult: Boolean? = false) { + fun startBrowser( + source: BaseSource?, + url: String, + title: String, + saveResult: Boolean? = false + ) { source ?: throw NoStackTraceException("startBrowser parameter source cannot be null") - key = "${source.getKey()}_verificationResult" + val key = getKey(source) appCtx.startActivity { putExtra("title", title) putExtra("url", url) @@ -64,10 +82,14 @@ object SourceVerificationHelp { putExtra("sourceName", source.getTag()) putExtra("sourceVerificationEnable", saveResult) IntentData.put(url, source.getHeaderMap(true)) + IntentData.put(key, Thread.currentThread()) } } - fun checkResult() { + + fun checkResult(key: String) { CacheManager.get(key) ?: CacheManager.putMemory(key, "") + val thread = IntentData.get(key) + LockSupport.unpark(thread) } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/legado/app/ui/association/VerificationCodeDialog.kt b/app/src/main/java/io/legado/app/ui/association/VerificationCodeDialog.kt index a8d9af42b..9d5de7641 100644 --- a/app/src/main/java/io/legado/app/ui/association/VerificationCodeDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/VerificationCodeDialog.kt @@ -56,20 +56,20 @@ class VerificationCodeDialog() : BaseDialogFragment(R.layout.dialog_verification setLayout(1f, ViewGroup.LayoutParams.WRAP_CONTENT) } - override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { + private var sourceOrigin: String? = null + private var key = "" + + override fun onFragmentCreated(view: View, savedInstanceState: Bundle?): Unit = binding.run { initMenu() - binding.run { - toolBar.setBackgroundColor(primaryColor) - arguments?.let { arguments -> - toolBar.subtitle = arguments.getString("sourceName") - val sourceOrigin = arguments.getString("sourceOrigin") - arguments.getString("imageUrl")?.let { imageUrl -> - loadImage(imageUrl, sourceOrigin) - verificationCodeImageView.setOnClickListener { - showDialogFragment(PhotoDialog(imageUrl, sourceOrigin)) - } - } - } + val arguments = arguments ?: return@run + toolBar.setBackgroundColor(primaryColor) + toolBar.subtitle = arguments.getString("sourceName") + sourceOrigin = arguments.getString("sourceOrigin") + key = SourceVerificationHelp.getKey(sourceOrigin!!) + val imageUrl = arguments.getString("imageUrl") ?: return@run + loadImage(imageUrl, sourceOrigin) + verificationCodeImageView.setOnClickListener { + showDialogFragment(PhotoDialog(imageUrl, sourceOrigin)) } } @@ -118,20 +118,16 @@ class VerificationCodeDialog() : BaseDialogFragment(R.layout.dialog_verification override fun onMenuItemClick(item: MenuItem): Boolean { when (item.itemId) { R.id.menu_ok -> { - val sourceOrigin = arguments?.getString("sourceOrigin") - val key = "${sourceOrigin}_verificationResult" val verificationCode = binding.verificationCode.text.toString() - verificationCode.let { - CacheManager.putMemory(key, it) - dismiss() - } + CacheManager.putMemory(key, verificationCode) + dismiss() } } return false } override fun onDestroy() { - SourceVerificationHelp.checkResult() + SourceVerificationHelp.checkResult(key) super.onDestroy() activity?.finish() } diff --git a/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt b/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt index 40598e232..881ddc6ab 100644 --- a/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt +++ b/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt @@ -172,8 +172,12 @@ class WebViewActivity : VMBaseActivity() { return super.onKeyUp(keyCode, event) } + override fun finish() { + SourceVerificationHelp.checkResult(viewModel.key) + super.finish() + } + override fun onDestroy() { - SourceVerificationHelp.checkResult() super.onDestroy() binding.webView.destroy() } diff --git a/app/src/main/java/io/legado/app/ui/browser/WebViewModel.kt b/app/src/main/java/io/legado/app/ui/browser/WebViewModel.kt index 3ddec4f49..7c8f6f77b 100644 --- a/app/src/main/java/io/legado/app/ui/browser/WebViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/browser/WebViewModel.kt @@ -14,6 +14,7 @@ import io.legado.app.help.CacheManager import io.legado.app.help.IntentData import io.legado.app.help.http.newCallResponseBody import io.legado.app.help.http.okHttpClient +import io.legado.app.help.source.SourceVerificationHelp import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.utils.DocumentUtils import io.legado.app.utils.FileUtils @@ -30,6 +31,7 @@ class WebViewModel(application: Application) : BaseViewModel(application) { val headerMap: HashMap = hashMapOf() var sourceVerificationEnable: Boolean = false var sourceOrigin: String = "" + var key = "" fun initData( intent: Intent, @@ -39,6 +41,7 @@ class WebViewModel(application: Application) : BaseViewModel(application) { val url = intent.getStringExtra("url") ?: throw NoStackTraceException("url不能为空") sourceOrigin = intent.getStringExtra("sourceOrigin") ?: "" + key = SourceVerificationHelp.getKey(sourceOrigin) sourceVerificationEnable = intent.getBooleanExtra("sourceVerificationEnable", false) val headerMapF = IntentData.get>(url) val analyzeUrl = AnalyzeUrl(url, headerMapF = headerMapF) diff --git a/build.gradle b/build.gradle index 7b58f2cff..36fcbee32 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { ext{ compile_sdk_version = 33 build_tool_version = '33.0.1' - kotlin_version = '1.8.21' + kotlin_version = '1.8.22' agp_version = '8.0.2' //exoplayer_version = '2.18.6' media3_version = "1.0.2" diff --git a/gradle.properties b/gradle.properties index f2b8dd45e..cd75610a0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -41,7 +41,7 @@ android.defaults.buildfeatures.shaders=false # and none from the library's dependencies, thereby reducing the size of the R class for that library. android.nonTransitiveRClass=true # https://chromiumdash.appspot.com/releases?platform=Android -CronetVersion=114.0.5735.57 +CronetVersion=114.0.5735.60 CronetMainVersion=114.0.0.0 android.injected.testOnly=false android.nonFinalResIds=true \ No newline at end of file