From 67501170cce0ddaa26a31668e23c1d81e01017bf Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Wed, 4 May 2022 14:31:33 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat:=E6=B7=BB=E5=8A=A0=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=A0=81=E5=AF=B9=E8=AF=9D=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 7 ++ app/src/main/assets/help/jsHelp.md | 4 + app/src/main/assets/updateLog.md | 4 + .../java/io/legado/app/help/JsExtensions.kt | 30 +++++++ .../association/VerificationCodeActivity.kt | 26 ++++++ .../ui/association/VerificationCodeDialog.kt | 83 +++++++++++++++++++ .../layout/dialog_verification_code_view.xml | 70 ++++++++++++++++ app/src/main/res/values-es-rES/strings.xml | 2 + app/src/main/res/values-ja-rJP/strings.xml | 2 + app/src/main/res/values-pt-rBR/strings.xml | 2 + app/src/main/res/values-zh-rHK/strings.xml | 2 + app/src/main/res/values-zh-rTW/strings.xml | 2 + app/src/main/res/values-zh/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + 14 files changed, 238 insertions(+) create mode 100644 app/src/main/java/io/legado/app/ui/association/VerificationCodeActivity.kt create mode 100644 app/src/main/java/io/legado/app/ui/association/VerificationCodeDialog.kt create mode 100644 app/src/main/res/layout/dialog_verification_code_view.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d33213e6e..da98accad 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -359,6 +359,13 @@ + + + { + putExtra("imageUrl", imageUrl) + putExtra("sourceOrigin", getSource()?.getKey()) + } + var waitUserInput: Boolean = false + while(CacheManager.get(key) == null) { + if (!waitUserInput) { + log("等待输入验证码...") + waitUserInput = true + } + } + CacheManager.get(key)!!.let { + if (it.isBlank()) { + throw NoStackTraceException("未输入验证码或者验证码为空") + } else { + it + } + } + } + } + /** * 可从网络,本地文件(阅读私有缓存目录和书籍保存位置支持相对路径)导入JavaScript脚本 */ diff --git a/app/src/main/java/io/legado/app/ui/association/VerificationCodeActivity.kt b/app/src/main/java/io/legado/app/ui/association/VerificationCodeActivity.kt new file mode 100644 index 000000000..13ade4694 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/association/VerificationCodeActivity.kt @@ -0,0 +1,26 @@ +package io.legado.app.ui.association + +import android.os.Bundle +import io.legado.app.base.BaseActivity +import io.legado.app.databinding.ActivityTranslucenceBinding +import io.legado.app.utils.showDialogFragment +import io.legado.app.utils.viewbindingdelegate.viewBinding + +/** + * 验证码 + */ +class VerificationCodeActivity : + BaseActivity() { + + override val binding by viewBinding(ActivityTranslucenceBinding::inflate) + + override fun onActivityCreated(savedInstanceState: Bundle?) { + intent.getStringExtra("imageUrl")?.let { + val sourceOrigin = intent.getStringExtra("sourceOrigin") + showDialogFragment( + VerificationCodeDialog(it, sourceOrigin) + ) + } ?: finish() + } + +} \ 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 new file mode 100644 index 000000000..568800b29 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/association/VerificationCodeDialog.kt @@ -0,0 +1,83 @@ +package io.legado.app.ui.association + +import android.os.Bundle +import android.view.View +import android.view.ViewGroup +import android.net.Uri +import com.bumptech.glide.request.RequestOptions +import io.legado.app.R +import io.legado.app.base.BaseDialogFragment +import io.legado.app.databinding.DialogVerificationCodeViewBinding +import io.legado.app.help.CacheManager +import io.legado.app.help.glide.ImageLoader +import io.legado.app.help.glide.OkHttpModelLoader +import io.legado.app.lib.theme.primaryColor +import io.legado.app.ui.widget.dialog.PhotoDialog +import io.legado.app.utils.setLayout +import io.legado.app.utils.showDialogFragment +import io.legado.app.utils.viewbindingdelegate.viewBinding + +//图片验证码输入对话框 +class VerificationCodeDialog() : BaseDialogFragment(R.layout.dialog_verification_code_view) { + + constructor(imageUrl: String, sourceOrigin: String? = null) : this() { + arguments = Bundle().apply { + putString("sourceOrigin", sourceOrigin) + putString("imageUrl", imageUrl) + } + } + + val binding by viewBinding(DialogVerificationCodeViewBinding::bind) + + override fun onStart() { + super.onStart() + setLayout(1f, ViewGroup.LayoutParams.WRAP_CONTENT) + } + + override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { + binding.run { + toolBar.setBackgroundColor(primaryColor) + val sourceOrigin = arguments?.getString("sourceOrigin") + val key = "${sourceOrigin ?: ""}_verificationCode" + arguments?.getString("imageUrl")?.let { imageUrl -> + ImageLoader.load(requireContext(), imageUrl).apply { + sourceOrigin?.let { + apply( + RequestOptions().set( + OkHttpModelLoader.sourceOriginOption, + it + ) + ) + } + }.error(R.drawable.image_loading_error) + .into(ivImage) + ivImage.setOnClickListener { + showDialogFragment(PhotoDialog(imageUrl, sourceOrigin)) + } + ivImage.setOnLongClickListener { + showDialogFragment(PhotoDialog(imageUrl, sourceOrigin)) + true + } + } + tvOk.setOnClickListener { + val verificationCode = binding.verificationCode.text.toString() + verificationCode?.let { + CacheManager.put(key, it) + dismiss() + } + } + tvCancel.setOnClickListener { + dismiss() + } + } + } + + override fun onDestroy() { + val sourceOrigin = arguments?.getString("sourceOrigin") + val key = "${sourceOrigin ?: ""}_verificationCode" + CacheManager.get(key) ?: CacheManager.put(key, "") + super.onDestroy() + activity?.finish() + } + +} \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_verification_code_view.xml b/app/src/main/res/layout/dialog_verification_code_view.xml new file mode 100644 index 000000000..c218ba54d --- /dev/null +++ b/app/src/main/res/layout/dialog_verification_code_view.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 4806bfc88..f62a1d248 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -969,5 +969,7 @@ 批量换源 书籍类型不一样 是否确认换源 + 输入验证码 + 验证码 diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 3385b091b..11a2729de 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -972,5 +972,7 @@ 批量换源 书籍类型不一样 是否确认换源 + 输入验证码 + 验证码 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 863b931ad..f0e4b8cf3 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -972,5 +972,7 @@ 批量换源 书籍类型不一样 是否确认换源 + 输入验证码 + 验证码 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 416e92a93..7b938e9f3 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -969,5 +969,7 @@ 批量换源 书籍类型不一样 是否确认换源 + 输入验证码 + 验证码 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 874d66764..6ba87de41 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -971,5 +971,7 @@ 批量换源 书籍类型不一样 是否确认换源 + 输入验证码 + 验证码 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 6b9b415d0..7b0f3ef18 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -971,5 +971,7 @@ 批量换源 书籍类型不一样 是否确认换源 + 输入验证码 + 验证码 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bc5f63327..05df4e53b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -972,5 +972,7 @@ 批量换源 书籍类型不一样 是否确认换源 + 输入验证码 + 验证码 From 4c83e00bf8904ea291b57a9a93b9a760548606fb Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Wed, 4 May 2022 17:04:11 +0800 Subject: [PATCH 2/5] =?UTF-8?q?feat(CacheManager):=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=86=85=E5=AD=98=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/help/CacheManager.kt | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/help/CacheManager.kt b/app/src/main/java/io/legado/app/help/CacheManager.kt index 606248559..156b16998 100644 --- a/app/src/main/java/io/legado/app/help/CacheManager.kt +++ b/app/src/main/java/io/legado/app/help/CacheManager.kt @@ -1,5 +1,6 @@ package io.legado.app.help +import androidx.collection.LruCache import io.legado.app.data.appDb import io.legado.app.data.entities.Cache import io.legado.app.model.analyzeRule.QueryTTF @@ -10,6 +11,11 @@ import splitties.init.appCtx object CacheManager { private val queryTTFMap = hashMapOf>() + private val memoryLruCache = object : LruCache(100) { + override fun sizeOf(key: String, value: Cache): Int { + return 1 + } + } /** * saveTime 单位为秒 @@ -23,13 +29,26 @@ object CacheManager { is ByteArray -> ACache.get(appCtx).put(key, value, saveTime) else -> { val cache = Cache(key, value.toString(), deadline) + memoryLruCache.put(key, cache) appDb.cacheDao.insert(cache) } } } fun get(key: String): String? { - return appDb.cacheDao.get(key, System.currentTimeMillis()) + return getFromMemory(key) ?: appDb.cacheDao.get(key, System.currentTimeMillis()) + } + + //从内存中获取数据 使用lrucache 支持过期功能 + private fun getFromMemory(key: String): String? { + val cache = memoryLruCache.get(key) ?: return null + val deadline = cache!!.deadline + return if (deadline == 0L || deadline > System.currentTimeMillis()) { + cache!!.value + } else { + memoryLruCache.remove(key) + null + } } fun getInt(key: String): Int? { @@ -70,6 +89,7 @@ object CacheManager { fun delete(key: String) { appDb.cacheDao.delete(key) + memoryLruCache.remove(key) ACache.get(appCtx).remove(key) } } \ No newline at end of file From e94a01bc691662e4dc26a2bce7678ab9ceed25f3 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Wed, 4 May 2022 18:50:39 +0800 Subject: [PATCH 3/5] =?UTF-8?q?feat:=E6=94=AF=E6=8C=81=E6=9B=B4=E5=A4=9A?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/help/jsHelp.md | 3 + app/src/main/assets/updateLog.md | 2 +- .../java/io/legado/app/help/JsExtensions.kt | 45 ++++-------- .../legado/app/help/SourceVerificationHelp.kt | 69 +++++++++++++++++++ .../ui/association/VerificationCodeDialog.kt | 15 ++-- .../legado/app/ui/browser/WebViewActivity.kt | 5 +- .../io/legado/app/ui/browser/WebViewModel.kt | 12 ++++ 7 files changed, 109 insertions(+), 42 deletions(-) create mode 100644 app/src/main/java/io/legado/app/help/SourceVerificationHelp.kt diff --git a/app/src/main/assets/help/jsHelp.md b/app/src/main/assets/help/jsHelp.md index 2bbf5018e..420f45ebe 100644 --- a/app/src/main/assets/help/jsHelp.md +++ b/app/src/main/assets/help/jsHelp.md @@ -67,6 +67,9 @@ java.webView(html: String?, url: String?, js: String?): String * @param url 要打开的链接 * @param title 浏览器的标题 java.startBrowser(url: String, title: String) + +* 使用内置浏览器打开链接,并等待网页结果 .body()获取网页内容 +java.startBrowserAwait(url: String, title: String): StrResponse ``` * 调试 ``` diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 6e365bba3..9bd798800 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -13,7 +13,7 @@ **2022/05/04** -* js添加 getVerificationCode +* js添加 getVerificationCode startBrowserAwait **2022/05/02** 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 b931790ba..e63dc6528 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -15,13 +15,10 @@ import io.legado.app.help.http.* import io.legado.app.model.Debug import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.QueryTTF -import io.legado.app.ui.association.VerificationCodeActivity -import io.legado.app.ui.browser.WebViewActivity import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.async import kotlinx.coroutines.runBlocking -import kotlinx.coroutines.withContext import org.jsoup.Connection import org.jsoup.Jsoup import splitties.init.appCtx @@ -135,46 +132,28 @@ interface JsExtensions { } /** - * 使用内置浏览器打开链接,可用于获取验证码 手动验证网站防爬 + * 使用内置浏览器打开链接,手动验证网站防爬 * @param url 要打开的链接 * @param title 浏览器页面的标题 */ fun startBrowser(url: String, title: String) { - appCtx.startActivity { - putExtra("title", title) - putExtra("url", url) - IntentData.put(url, getSource()?.getHeaderMap(true)) - } + SourceVerificationHelp.startBrowser(getSource(), url, title) } /** - * 打开验证码对话框,等待输入验证码 + * 使用内置浏览器打开链接,并等待网页结果 */ - fun getVerificationCode(imageUrl: String): String { - return runBlocking { - val key = "${getSource()?.getKey() ?: ""}_verificationCode" - CacheManager.delete(key) - appCtx.startActivity { - putExtra("imageUrl", imageUrl) - putExtra("sourceOrigin", getSource()?.getKey()) - } - var waitUserInput: Boolean = false - while(CacheManager.get(key) == null) { - if (!waitUserInput) { - log("等待输入验证码...") - waitUserInput = true - } - } - CacheManager.get(key)!!.let { - if (it.isBlank()) { - throw NoStackTraceException("未输入验证码或者验证码为空") - } else { - it - } - } - } + fun startBrowserAwait(url: String, title: String): StrResponse { + return StrResponse(url, SourceVerificationHelp.getVerificationResult(getSource(), url, title, true)) } + /** + * 打开图片验证码对话框,等待返回验证结果 + */ + fun getVerificationCode(imageUrl: String): String { + return SourceVerificationHelp.getVerificationResult(getSource(), imageUrl, "", false) + } + /** * 可从网络,本地文件(阅读私有缓存目录和书籍保存位置支持相对路径)导入JavaScript脚本 */ diff --git a/app/src/main/java/io/legado/app/help/SourceVerificationHelp.kt b/app/src/main/java/io/legado/app/help/SourceVerificationHelp.kt new file mode 100644 index 000000000..3f3a302dc --- /dev/null +++ b/app/src/main/java/io/legado/app/help/SourceVerificationHelp.kt @@ -0,0 +1,69 @@ +package io.legado.app.help + +import io.legado.app.utils.startActivity +import io.legado.app.constant.AppLog +import io.legado.app.exception.NoStackTraceException +import io.legado.app.data.entities.BaseSource +import io.legado.app.ui.browser.WebViewActivity +import io.legado.app.ui.association.VerificationCodeActivity +import splitties.init.appCtx +import kotlinx.coroutines.runBlocking + + +object SourceVerificationHelp { + + /** + * 获取书源验证结果 + * 图片验证码 防爬 滑动验证码 点击字符 等等 + */ + fun getVerificationResult(source: BaseSource?, url: String, title: String, useBrowser: Boolean): String { + source ?: throw NoStackTraceException("getVerificationResult parameter source cannot be null") + return runBlocking { + val key = "${source?.getKey() ?: ""}_verificationResult" + CacheManager.delete(key) + + if (!useBrowser) { + appCtx.startActivity { + putExtra("imageUrl", url) + putExtra("sourceOrigin", source?.getKey()) + } + } else { + startBrowser(source, url, title, true) + } + + var waitUserInput: Boolean = false + while(CacheManager.get(key) == null) { + if (!waitUserInput) { + AppLog.putDebug("等待返回验证结果...") + waitUserInput = true + } + } + CacheManager.get(key)!!.let { + if (it.isBlank()) { + throw NoStackTraceException("验证结果为空") + } else { + it + } + } + } + } + + /** + * 启动内置浏览器 + @param saveResult 保存网页源代码到数据库 + */ + fun startBrowser(source: BaseSource?, url: String, title: String, saveResult: Boolean? = false) { + source ?: throw NoStackTraceException("startBrowser parameter source cannot be null") + appCtx.startActivity { + putExtra("title", title) + putExtra("url", url) + putExtra("sourceOrigin", source?.getKey()) + putExtra("sourceVerificationEnable", saveResult) + IntentData.put(url, source?.getHeaderMap(true)) + } + } + + private fun checkActivityStatus(): Boolean { + return true + } +} \ 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 568800b29..0e8265f7a 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 @@ -17,7 +17,12 @@ import io.legado.app.utils.setLayout import io.legado.app.utils.showDialogFragment import io.legado.app.utils.viewbindingdelegate.viewBinding -//图片验证码输入对话框 +/** + * 图片验证码对话框 + * 结果保存在数据库中 + * val key = "${sourceOrigin ?: ""}_verificationResult" + * CacheManager.get(key) + */ class VerificationCodeDialog() : BaseDialogFragment(R.layout.dialog_verification_code_view) { constructor(imageUrl: String, sourceOrigin: String? = null) : this() { @@ -38,7 +43,7 @@ class VerificationCodeDialog() : BaseDialogFragment(R.layout.dialog_verification binding.run { toolBar.setBackgroundColor(primaryColor) val sourceOrigin = arguments?.getString("sourceOrigin") - val key = "${sourceOrigin ?: ""}_verificationCode" + val key = "${sourceOrigin ?: ""}_verificationResult" arguments?.getString("imageUrl")?.let { imageUrl -> ImageLoader.load(requireContext(), imageUrl).apply { sourceOrigin?.let { @@ -54,10 +59,6 @@ class VerificationCodeDialog() : BaseDialogFragment(R.layout.dialog_verification ivImage.setOnClickListener { showDialogFragment(PhotoDialog(imageUrl, sourceOrigin)) } - ivImage.setOnLongClickListener { - showDialogFragment(PhotoDialog(imageUrl, sourceOrigin)) - true - } } tvOk.setOnClickListener { val verificationCode = binding.verificationCode.text.toString() @@ -74,7 +75,7 @@ class VerificationCodeDialog() : BaseDialogFragment(R.layout.dialog_verification override fun onDestroy() { val sourceOrigin = arguments?.getString("sourceOrigin") - val key = "${sourceOrigin ?: ""}_verificationCode" + val key = "${sourceOrigin ?: ""}_verificationResult" CacheManager.get(key) ?: CacheManager.put(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 e4532d566..71485b027 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 @@ -26,6 +26,7 @@ import io.legado.app.ui.document.HandleFileContract import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding import java.net.URLDecoder +import kotlinx.coroutines.runBlocking class WebViewActivity : VMBaseActivity() { @@ -135,7 +136,6 @@ class WebViewActivity : VMBaseActivity() { viewModel.saveImage(webPic, path) } } - private fun selectSaveFolder() { val default = arrayListOf>() val path = ACache.get(this).getAsString(imagePathKey) @@ -176,6 +176,9 @@ class WebViewActivity : VMBaseActivity() { override fun onDestroy() { super.onDestroy() + runBlocking { + viewModel.saveVerificationResult() + } 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 16c813ef4..79f6e21ad 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 @@ -9,6 +9,7 @@ import androidx.documentfile.provider.DocumentFile import io.legado.app.base.BaseViewModel import io.legado.app.constant.AppConst import io.legado.app.exception.NoStackTraceException +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 @@ -21,6 +22,8 @@ class WebViewModel(application: Application) : BaseViewModel(application) { var baseUrl: String = "" var html: String? = null val headerMap: HashMap = hashMapOf() + var sourceVerificationEnable: Boolean = false + var sourceOrigin: String = "" fun initData( intent: Intent, @@ -29,6 +32,8 @@ class WebViewModel(application: Application) : BaseViewModel(application) { execute { val url = intent.getStringExtra("url") ?: throw NoStackTraceException("url不能为空") + sourceOrigin = intent.getStringExtra("sourceOrigin") ?: "" + sourceVerificationEnable = intent.getBooleanExtra("sourceVerificationEnable", false) val headerMapF = IntentData.get>(url) val analyzeUrl = AnalyzeUrl(url, headerMapF = headerMapF) baseUrl = analyzeUrl.url @@ -78,5 +83,12 @@ class WebViewModel(application: Application) : BaseViewModel(application) { } } + fun saveVerificationResult() { + if (sourceVerificationEnable) { + val key = "${sourceOrigin}_verificationResult" + html = AnalyzeUrl(baseUrl, headerMapF = headerMap).getStrResponse(useWebView = false).body + CacheManager.put(key, html!!) + } + } } \ No newline at end of file From 1b0515ee9007e6be4048f6def030a5dacbb7568a Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Thu, 5 May 2022 06:42:58 +0800 Subject: [PATCH 4/5] =?UTF-8?q?feat(ui/browser):=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=A1=AE=E8=AE=A4=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/ui/browser/WebViewActivity.kt | 6 ++++++ app/src/main/java/io/legado/app/ui/browser/WebViewModel.kt | 2 +- app/src/main/res/menu/web_view.xml | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) 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 71485b027..2f3fbef85 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 @@ -66,6 +66,12 @@ class WebViewActivity : VMBaseActivity() { when (item.itemId) { R.id.menu_open_in_browser -> openUrl(viewModel.baseUrl) R.id.menu_copy_url -> sendToClip(viewModel.baseUrl) + R.id.menu_ok -> { + if (viewModel.sourceVerificationEnable) { + binding.titleBar.snackbar(R.string.ok) + activity?.finish() + } + } } return super.onCompatOptionsItemSelected(item) } 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 79f6e21ad..7471db654 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 @@ -87,7 +87,7 @@ class WebViewModel(application: Application) : BaseViewModel(application) { if (sourceVerificationEnable) { val key = "${sourceOrigin}_verificationResult" html = AnalyzeUrl(baseUrl, headerMapF = headerMap).getStrResponse(useWebView = false).body - CacheManager.put(key, html!!) + CacheManager.put(key, html ?: "") } } diff --git a/app/src/main/res/menu/web_view.xml b/app/src/main/res/menu/web_view.xml index 281e17243..57b095c91 100644 --- a/app/src/main/res/menu/web_view.xml +++ b/app/src/main/res/menu/web_view.xml @@ -2,6 +2,12 @@ + + Date: Thu, 5 May 2022 06:52:04 +0800 Subject: [PATCH 5/5] =?UTF-8?q?fix:WebView=E7=99=BB=E5=BD=95=20=E7=95=8C?= =?UTF-8?q?=E9=9D=A2bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/browser/WebViewActivity.kt | 2 +- .../io/legado/app/ui/login/WebViewLoginFragment.kt | 2 +- app/src/main/res/menu/source_webview_login.xml | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/menu/source_webview_login.xml 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 2f3fbef85..3973b2023 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 @@ -69,7 +69,7 @@ class WebViewActivity : VMBaseActivity() { R.id.menu_ok -> { if (viewModel.sourceVerificationEnable) { binding.titleBar.snackbar(R.string.ok) - activity?.finish() + finish() } } } diff --git a/app/src/main/java/io/legado/app/ui/login/WebViewLoginFragment.kt b/app/src/main/java/io/legado/app/ui/login/WebViewLoginFragment.kt index c9feb1c4d..01e3a323d 100644 --- a/app/src/main/java/io/legado/app/ui/login/WebViewLoginFragment.kt +++ b/app/src/main/java/io/legado/app/ui/login/WebViewLoginFragment.kt @@ -35,7 +35,7 @@ class WebViewLoginFragment : BaseFragment(R.layout.fragment_web_view_login) { } override fun onCompatCreateOptionsMenu(menu: Menu) { - menuInflater.inflate(R.menu.source_login, menu) + menuInflater.inflate(R.menu.source_webview_login, menu) } override fun onCompatOptionsItemSelected(item: MenuItem) { diff --git a/app/src/main/res/menu/source_webview_login.xml b/app/src/main/res/menu/source_webview_login.xml new file mode 100644 index 000000000..5723c1b13 --- /dev/null +++ b/app/src/main/res/menu/source_webview_login.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file