From 89f4ebcecfda5b5a10f3330ce915f1a770b52101 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Wed, 13 Apr 2022 09:59:23 +0800 Subject: [PATCH 1/7] feat:add js toast --- app/src/main/assets/help/jsHelp.md | 5 +++++ app/src/main/assets/updateLog.md | 7 ++++++- .../main/java/io/legado/app/help/JsExtensions.kt | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/src/main/assets/help/jsHelp.md b/app/src/main/assets/help/jsHelp.md index 1d2ae5eaa..bbdd559ca 100644 --- a/app/src/main/assets/help/jsHelp.md +++ b/app/src/main/assets/help/jsHelp.md @@ -68,6 +68,11 @@ java.webView(html: String?, url: String?, js: String?): String java.log(msg) java.logType(var) ``` +* 弹窗提示 +``` +java.longToast(msg: Any?) +java.toast(msg: Any?) +``` * 从网络(由java.cacheFile实现)、本地导入JavaScript脚本 ``` {{java.importScript(url)}} diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index eb8d270e7..fbd1ccd18 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -11,7 +11,12 @@ * 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则或简繁转换出现问题。 * 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源! -**2022/04/012** +**2022/04/13** + +* 修复解码正文图片报错,添加解码日志 +* js文档:java.toast java.longToast + +**2022/04/12** * 更新cronet: 100.0.4896.88 * 恢复epub加载方式 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 0e548a43b..4c9cf31fe 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -34,6 +34,7 @@ import java.util.zip.ZipInputStream /** * js扩展类, 在js中通过java变量调用 + * 添加方法,请更新文档/legado/app/src/main/assets/help/JsHelp.md * 所有对于文件的读写删操作都是相对路径,只能操作阅读缓存内的文件 * /android/data/{package}/cache/... */ @@ -526,6 +527,20 @@ interface JsExtensions { return contentArray.joinToString("") } + /** + * 弹窗提示 + */ + fun toast(msg: Any?) { + appCtx.toastOnUi(msg.toString()) + } + + /** + * 弹窗提示 停留时间较长 + */ + fun longToast(msg: Any?) { + appCtx.longToastOnUi(msg.toString()) + } + /** * 输出调试日志 */ From de027e9d31b093d5a25ddff4764fb72b5abd4b6a Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Wed, 13 Apr 2022 10:35:01 +0800 Subject: [PATCH 2/7] =?UTF-8?q?fix:=E5=86=85=E7=BD=AE=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=99=A8=E6=9C=AA=E5=90=AF=E7=94=A8cookie=E5=92=8Cjs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/browser/WebViewActivity.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 2e4c1fade..bac99cedf 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 @@ -17,6 +17,7 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.databinding.ActivityWebViewBinding import io.legado.app.help.config.AppConfig +import io.legado.app.help.http.CookieStore import io.legado.app.lib.dialogs.SelectItem import io.legado.app.model.Download import io.legado.app.ui.association.OnLineImportActivity @@ -41,9 +42,9 @@ class WebViewActivity : VMBaseActivity() { override fun onActivityCreated(savedInstanceState: Bundle?) { binding.titleBar.title = intent.getStringExtra("title") ?: getString(R.string.loading) - initWebView() viewModel.initData(intent) { val url = viewModel.baseUrl + initWebView(url) val html = viewModel.html if (html.isNullOrEmpty()) { binding.webView.loadUrl(url, viewModel.headerMap) @@ -67,7 +68,7 @@ class WebViewActivity : VMBaseActivity() { } @SuppressLint("JavascriptInterface") - private fun initWebView() { + private fun initWebView(url: String) { binding.webView.webChromeClient = CustomWebChromeClient() binding.webView.webViewClient = CustomWebViewClient() binding.webView.settings.apply { @@ -76,7 +77,10 @@ class WebViewActivity : VMBaseActivity() { allowContentAccess = true useWideViewPort = true loadWithOverviewMode = true + javaScriptEnabled = true } + val cookieManager = CookieManager.getInstance() + cookieManager.setCookie(url, CookieStore.getCookie(url)) binding.webView.addJavascriptInterface(this, "app") upWebViewTheme() binding.webView.setOnLongClickListener { @@ -207,6 +211,10 @@ class WebViewActivity : VMBaseActivity() { override fun onPageFinished(view: WebView?, url: String?) { super.onPageFinished(view, url) + val cookieManager = CookieManager.getInstance() + url?.let { + CookieStore.setCookie(it, cookieManager.getCookie(it)) + } view?.title?.let { title -> if (title != url && title != view.url && title.isNotBlank()) { binding.titleBar.title = title From ccbe25350e5d3c7f2a14ab8c427bb64a5d04ff41 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Wed, 13 Apr 2022 11:14:51 +0800 Subject: [PATCH 3/7] =?UTF-8?q?fix:=E5=86=85=E7=BD=AE=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=99=A8headmap=E6=9C=AA=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/login/WebViewLoginFragment.kt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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 8d4d8ea9c..54775b50d 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 @@ -44,8 +44,10 @@ class WebViewLoginFragment : BaseFragment(R.layout.fragment_web_view_login) { if (!checking) { checking = true binding.titleBar.snackbar(R.string.check_host_cookie) - viewModel.source?.loginUrl?.let { - binding.webView.loadUrl(it) + viewModel.source?.let { source -> + source.loginUrl?.let { + binding.webView.loadUrl(it, source.getHeaderMap(true)) + } } } } @@ -57,9 +59,6 @@ class WebViewLoginFragment : BaseFragment(R.layout.fragment_web_view_login) { binding.webView.settings.apply { builtInZoomControls = true javaScriptEnabled = true - source.getHeaderMap()[AppConst.UA_NAME]?.let { - userAgentString = it - } } val cookieManager = CookieManager.getInstance() source.loginUrl?.let { @@ -82,7 +81,7 @@ class WebViewLoginFragment : BaseFragment(R.layout.fragment_web_view_login) { } } source.loginUrl?.let { - binding.webView.loadUrl(it) + binding.webView.loadUrl(it, source.getHeaderMap(true)) } } From e65cf6fa1f9b78e0abe2d2e156b6966318998f73 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Wed, 13 Apr 2022 12:13:42 +0800 Subject: [PATCH 4/7] =?UTF-8?q?fix:=E5=86=85=E7=BD=AE=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=99=A8UA=E6=9C=AA=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/browser/WebViewActivity.kt | 11 ++++++++--- .../io/legado/app/ui/login/WebViewLoginFragment.kt | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-) 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 bac99cedf..96435e5fb 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 @@ -15,6 +15,7 @@ import androidx.webkit.WebSettingsCompat import androidx.webkit.WebViewFeature import io.legado.app.R import io.legado.app.base.VMBaseActivity +import io.legado.app.constant.AppConst import io.legado.app.databinding.ActivityWebViewBinding import io.legado.app.help.config.AppConfig import io.legado.app.help.http.CookieStore @@ -44,10 +45,11 @@ class WebViewActivity : VMBaseActivity() { binding.titleBar.title = intent.getStringExtra("title") ?: getString(R.string.loading) viewModel.initData(intent) { val url = viewModel.baseUrl - initWebView(url) + val headerMap = viewModel.headerMap + initWebView(url, headerMap) val html = viewModel.html if (html.isNullOrEmpty()) { - binding.webView.loadUrl(url, viewModel.headerMap) + binding.webView.loadUrl(url, headerMap) } else { binding.webView.loadDataWithBaseURL(url, html, "text/html", "utf-8", url) } @@ -68,7 +70,7 @@ class WebViewActivity : VMBaseActivity() { } @SuppressLint("JavascriptInterface") - private fun initWebView(url: String) { + private fun initWebView(url: String, headerMap: HashMap) { binding.webView.webChromeClient = CustomWebChromeClient() binding.webView.webViewClient = CustomWebViewClient() binding.webView.settings.apply { @@ -78,6 +80,9 @@ class WebViewActivity : VMBaseActivity() { useWideViewPort = true loadWithOverviewMode = true javaScriptEnabled = true + headerMap[AppConst.UA_NAME]?.let { + userAgentString = it + } } val cookieManager = CookieManager.getInstance() cookieManager.setCookie(url, CookieStore.getCookie(url)) 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 54775b50d..c9feb1c4d 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 @@ -59,6 +59,9 @@ class WebViewLoginFragment : BaseFragment(R.layout.fragment_web_view_login) { binding.webView.settings.apply { builtInZoomControls = true javaScriptEnabled = true + source.getHeaderMap()[AppConst.UA_NAME]?.let { + userAgentString = it + } } val cookieManager = CookieManager.getInstance() source.loginUrl?.let { From a7a62d752f6b73c948ad41639f912885917fbf80 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Wed, 13 Apr 2022 16:26:29 +0800 Subject: [PATCH 5/7] =?UTF-8?q?fix:web=E7=AB=AFepub=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E6=9C=AA=E4=BB=A3=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/api/controller/BookController.kt | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/api/controller/BookController.kt b/app/src/main/java/io/legado/app/api/controller/BookController.kt index 73d83871a..c94f7dcb3 100644 --- a/app/src/main/java/io/legado/app/api/controller/BookController.kt +++ b/app/src/main/java/io/legado/app/api/controller/BookController.kt @@ -22,6 +22,7 @@ import io.legado.app.model.localBook.LocalBook import io.legado.app.model.localBook.UmdFile import io.legado.app.model.webBook.WebBook import io.legado.app.utils.* +import io.legado.app.ui.book.read.page.provider.ImageProvider import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking import splitties.init.appCtx @@ -79,23 +80,16 @@ object BookController { ?: return returnData.setErrorMsg("bookUrl为空") val src = parameters["path"]?.firstOrNull() ?: return returnData.setErrorMsg("图片链接为空") + val width = parameters["width"]?.firstOrNull()?.toInt() ?: 640 if (this.bookUrl != bookUrl) { this.book = appDb.bookDao.getBook(bookUrl) ?: return returnData.setErrorMsg("bookUrl不对") - } - val vFile = BookHelp.getImage(book, src) - if (!vFile.exists()) { - if (this.bookUrl != bookUrl) { - this.bookSource = appDb.bookSourceDao.getBookSource(book.origin) - } - runBlocking { - BookHelp.saveImage(bookSource, book, src) - } + this.bookSource = appDb.bookSourceDao.getBookSource(book.origin) } this.bookUrl = bookUrl - return returnData.setData( - ImageLoader.loadBitmap(appCtx, vFile.absolutePath).submit().get() - ) + return ImageProvider.getImage(book, src, bookSource, width, width)?.let { + returnData.setData(it) + } } /** From 7befacc32423865b8d7170d14517b5aca06694d7 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Wed, 13 Apr 2022 16:35:41 +0800 Subject: [PATCH 6/7] =?UTF-8?q?fix:web=E7=AB=AFepub=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E6=9C=AA=E4=BB=A3=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/api/controller/BookController.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/api/controller/BookController.kt b/app/src/main/java/io/legado/app/api/controller/BookController.kt index c94f7dcb3..30f887ed3 100644 --- a/app/src/main/java/io/legado/app/api/controller/BookController.kt +++ b/app/src/main/java/io/legado/app/api/controller/BookController.kt @@ -89,7 +89,7 @@ object BookController { this.bookUrl = bookUrl return ImageProvider.getImage(book, src, bookSource, width, width)?.let { returnData.setData(it) - } + } ?: returnData.setErrorMsg("图片加载失败或不存在") } /** From d1ec6bfdf4c7a410339dcb4fe848c154d0b94813 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Wed, 13 Apr 2022 17:44:47 +0800 Subject: [PATCH 7/7] =?UTF-8?q?fix:=E6=9B=B4=E5=A4=9A=E7=9A=84=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/page/provider/ImageProvider.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt index 877e190be..605fc5eff 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt @@ -82,7 +82,7 @@ object ImageProvider { .get() } catch (e: Exception) { Coroutine.async { - putDebug("${vFile.absolutePath} 解码失败", e) + putDebug("${vFile.absolutePath} 解码失败\n${e.toString()}", e) if (FileUtils.readText(vFile.absolutePath).isXml()) { putDebug("${vFile.absolutePath}为xml,自动删除") vFile.delete() @@ -106,7 +106,7 @@ object ImageProvider { .get() } catch (e: Exception) { Coroutine.async { - putDebug("${vFile.absolutePath} 解码失败", e) + putDebug("${vFile.absolutePath} 解码失败\n${e.toString()}", e) if (FileUtils.readText(vFile.absolutePath).isXml()) { putDebug("${vFile.absolutePath}为xml,自动删除") vFile.delete()