From ab3244d7a3c048e6fc775208f4244be8e8d91831 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 3 Nov 2019 13:11:45 +0800 Subject: [PATCH] up --- .../java/io/legado/app/help/http/AjaxWebView.kt | 8 ++++---- .../java/io/legado/app/help/http/HttpHelper.kt | 15 ++++++--------- .../io/legado/app/model/analyzeRule/AnalyzeUrl.kt | 4 ++++ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt b/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt index abf3f0dae..95fc361db 100644 --- a/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt +++ b/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt @@ -78,7 +78,7 @@ class AjaxWebView { } fun load(params: AjaxParams) { - if (params.audioSuffix != "") { + if (params.sourceRegex != "") { mHandler.obtainMessage(MSG_SNIFF_START, params) .sendToTarget() } else { @@ -97,7 +97,7 @@ class AjaxWebView { var postData: ByteArray? = null var headerMap: Map? = null var cookieStore: CookieStore? = null - var audioSuffix: String? = null + var sourceRegex: String? = null var javaScript: String? = null private var audioSuffixList: List? = null @@ -105,7 +105,7 @@ class AjaxWebView { get() = this.headerMap?.get("User-Agent") val isSniff: Boolean - get() = !TextUtils.isEmpty(audioSuffix) + get() = !TextUtils.isEmpty(sourceRegex) fun setCookie(url: String) { if (cookieStore != null) { @@ -125,7 +125,7 @@ class AjaxWebView { fun getAudioSuffixList(): List? { if (audioSuffixList == null) { audioSuffixList = if (isSniff) { - audioSuffix?.split("\\|\\|".toRegex()) + sourceRegex?.split("\\|\\|".toRegex()) } else { Collections.emptyList() } 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 c091a6c2c..745e91316 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 @@ -1,11 +1,11 @@ package io.legado.app.help.http -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.suspendCancellableCoroutine import okhttp3.* import retrofit2.Retrofit import java.util.* import java.util.concurrent.TimeUnit +import kotlin.coroutines.resume object HttpHelper { @@ -74,23 +74,20 @@ object HttpHelper { } } - @ExperimentalCoroutinesApi suspend fun ajax(params: AjaxWebView.AjaxParams): String = suspendCancellableCoroutine { block -> val webView = AjaxWebView() + block.invokeOnCancellation { + webView.destroyWebView() + } webView.callback = object : AjaxWebView.Callback() { override fun onResult(result: String) { - block.resume(result) { - webView.destroyWebView() - } + block.resume(result) } override fun onError(error: Throwable) { - block.resume(error.localizedMessage) { - webView.destroyWebView() - } + block.resume(error.localizedMessage) } - } webView.load(params) } diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt index ef4fa3e05..43ff6c619 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt @@ -59,6 +59,7 @@ class AnalyzeUrl( private var body: RequestBody? = null private var method = RequestMethod.GET private var webViewJs: String? = null + private var sourceRegex: String? = null val postData: ByteArray get() { @@ -182,6 +183,7 @@ class AnalyzeUrl( options["body"]?.let { bodyTxt = it } options["charset"]?.let { charset = it } options["js"]?.let { webViewJs = it } + options["sourceRegex"]?.let { sourceRegex = it } } } when (method) { @@ -302,6 +304,8 @@ class AnalyzeUrl( val params = AjaxWebView.AjaxParams(tag) params.url = url params.requestMethod = method + params.javaScript = webViewJs + params.sourceRegex = sourceRegex return HttpHelper.ajax(params) } }