@@ -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)}}
|
||||
|
||||
@@ -11,7 +11,12 @@
|
||||
* 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则或简繁转换出现问题。
|
||||
* 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源!
|
||||
|
||||
**2022/04/012**
|
||||
**2022/04/13**
|
||||
|
||||
* 修复解码正文图片报错,添加解码日志
|
||||
* js文档:java.toast java.longToast
|
||||
|
||||
**2022/04/12**
|
||||
|
||||
* 更新cronet: 100.0.4896.88
|
||||
* 恢复epub加载方式
|
||||
|
||||
@@ -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)
|
||||
} ?: returnData.setErrorMsg("图片加载失败或不存在")
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出调试日志
|
||||
*/
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -15,8 +15,10 @@ 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
|
||||
import io.legado.app.lib.dialogs.SelectItem
|
||||
import io.legado.app.model.Download
|
||||
import io.legado.app.ui.association.OnLineImportActivity
|
||||
@@ -41,12 +43,13 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
binding.titleBar.title = intent.getStringExtra("title") ?: getString(R.string.loading)
|
||||
initWebView()
|
||||
viewModel.initData(intent) {
|
||||
val url = viewModel.baseUrl
|
||||
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)
|
||||
}
|
||||
@@ -67,7 +70,7 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
|
||||
}
|
||||
|
||||
@SuppressLint("JavascriptInterface")
|
||||
private fun initWebView() {
|
||||
private fun initWebView(url: String, headerMap: HashMap<String, String>) {
|
||||
binding.webView.webChromeClient = CustomWebChromeClient()
|
||||
binding.webView.webViewClient = CustomWebViewClient()
|
||||
binding.webView.settings.apply {
|
||||
@@ -76,7 +79,13 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
|
||||
allowContentAccess = true
|
||||
useWideViewPort = true
|
||||
loadWithOverviewMode = true
|
||||
javaScriptEnabled = true
|
||||
headerMap[AppConst.UA_NAME]?.let {
|
||||
userAgentString = it
|
||||
}
|
||||
}
|
||||
val cookieManager = CookieManager.getInstance()
|
||||
cookieManager.setCookie(url, CookieStore.getCookie(url))
|
||||
binding.webView.addJavascriptInterface(this, "app")
|
||||
upWebViewTheme()
|
||||
binding.webView.setOnLongClickListener {
|
||||
@@ -207,6 +216,10 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
|
||||
|
||||
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
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,7 +84,7 @@ class WebViewLoginFragment : BaseFragment(R.layout.fragment_web_view_login) {
|
||||
}
|
||||
}
|
||||
source.loginUrl?.let {
|
||||
binding.webView.loadUrl(it)
|
||||
binding.webView.loadUrl(it, source.getHeaderMap(true))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user