Merge pull request #1937 from Xwite/master

fix #1831
pull/1941/head
kunfei 3 years ago committed by GitHub
commit a73c25f423
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/src/main/java/io/legado/app/data/entities/Book.kt
  2. 4
      app/src/main/java/io/legado/app/help/BookHelp.kt
  3. 2
      app/src/main/java/io/legado/app/model/localBook/EpubFile.kt
  4. 10
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt
  5. 2
      app/src/main/res/values-es-rES/strings.xml
  6. 2
      app/src/main/res/values-ja-rJP/strings.xml
  7. 2
      app/src/main/res/values-pt-rBR/strings.xml
  8. 2
      app/src/main/res/values-zh-rHK/strings.xml
  9. 2
      app/src/main/res/values-zh-rTW/strings.xml
  10. 2
      app/src/main/res/values-zh/strings.xml
  11. 2
      app/src/main/res/values/strings.xml

@ -202,7 +202,8 @@ data class Book(
if (useReplaceRule != null) { if (useReplaceRule != null) {
return useReplaceRule return useReplaceRule
} }
if (type == BookType.image) { //图片类书源 epub本地 默认关闭净化
if (type == BookType.image || isEpub()) {
return false return false
} }
return AppConfig.replaceEnableDefault return AppConfig.replaceEnableDefault

@ -144,7 +144,9 @@ object BookHelp {
fun getImageSuffix(src: String): String { fun getImageSuffix(src: String): String {
var suffix = src.substringAfterLast(".").substringBefore(",") var suffix = src.substringAfterLast(".").substringBefore(",")
if (suffix.length > 5) { //检查截取的后缀字符是否合法 [a-zA-Z0-9]
val fileSuffixRegex = Regex("^[a-z0-9]+$", RegexOption.IGNORE_CASE)
if (suffix.length > 5 || !suffix.matches(fileSuffixRegex)) {
suffix = "jpg" suffix = "jpg"
} }
return suffix return suffix

@ -33,7 +33,7 @@ class EpubFile(var book: Book) {
if (eFile == null || eFile?.book?.bookUrl != book.bookUrl) { if (eFile == null || eFile?.book?.bookUrl != book.bookUrl) {
eFile = EpubFile(book) eFile = EpubFile(book)
//对于Epub文件默认不启用替换 //对于Epub文件默认不启用替换
book.setUseReplaceRule(false) //io.legado.app.data.entities.Book getUseReplaceRule
return eFile!! return eFile!!
} }
eFile?.book = book eFile?.book = book

@ -13,8 +13,7 @@ import io.legado.app.help.BookHelp
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.localBook.EpubFile import io.legado.app.model.localBook.EpubFile
import io.legado.app.utils.BitmapUtils import io.legado.app.utils.*
import io.legado.app.utils.FileUtils
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import splitties.init.appCtx import splitties.init.appCtx
@ -113,6 +112,11 @@ object ImageProvider {
width: Int, width: Int,
height: Int? = null height: Int? = null
): Bitmap { ): Bitmap {
//src为空白时 可能被净化替换掉了 或者规则失效
if (book.getUseReplaceRule() && src.isBlank()) {
book.setUseReplaceRule(false)
appCtx.toastOnUi(R.string.error_image_url_empty)
}
val vFile = BookHelp.getImage(book, src) val vFile = BookHelp.getImage(book, src)
if (!vFile.exists()) return errorBitmap if (!vFile.exists()) return errorBitmap
//epub文件提供图片链接是相对链接,同时阅读多个epub文件,缓存命中错误 //epub文件提供图片链接是相对链接,同时阅读多个epub文件,缓存命中错误
@ -122,7 +126,7 @@ object ImageProvider {
@Suppress("BlockingMethodInNonBlockingContext") @Suppress("BlockingMethodInNonBlockingContext")
return kotlin.runCatching { return kotlin.runCatching {
val bitmap = BitmapUtils.decodeBitmap(vFile.absolutePath, width, height) val bitmap = BitmapUtils.decodeBitmap(vFile.absolutePath, width, height)
?: throw NoStackTraceException("解析图片失败") ?: throw NoStackTraceException(appCtx.getString(R.string.error_decode_bitmap))
bitmapLruCache.put(vFile.absolutePath, bitmap) bitmapLruCache.put(vFile.absolutePath, bitmap)
bitmap bitmap
}.onFailure { }.onFailure {

@ -993,4 +993,6 @@
<string name="bitmap_cache_size">bitmap cache size</string> <string name="bitmap_cache_size">bitmap cache size</string>
<string name="export_pics_file">Export Picture Files</string> <string name="export_pics_file">Export Picture Files</string>
<!-- string end --> <!-- string end -->
<string name="error_decode_bitmap">Fail to decode bitmap</string>
<string name="error_image_url_empty">Image url is empty, check replacement rules</string>
</resources> </resources>

@ -996,4 +996,6 @@
<string name="bitmap_cache_size">bitmap cache size</string> <string name="bitmap_cache_size">bitmap cache size</string>
<string name="export_pics_file">Export Picture Files</string> <string name="export_pics_file">Export Picture Files</string>
<!-- string end --> <!-- string end -->
<string name="error_decode_bitmap">Fail to decode bitmap</string>
<string name="error_image_url_empty">Image url is empty, check replacement rules</string>
</resources> </resources>

@ -996,4 +996,6 @@
<string name="bitmap_cache_size">bitmap cache size</string> <string name="bitmap_cache_size">bitmap cache size</string>
<string name="export_pics_file">Export Picture Files</string> <string name="export_pics_file">Export Picture Files</string>
<!-- string end --> <!-- string end -->
<string name="error_decode_bitmap">Fail to decode bitmap</string>
<string name="error_image_url_empty">Image url is empty, check replacement rules</string>
</resources> </resources>

@ -993,4 +993,6 @@
<string name="bitmap_cache_size">图片绘制缓存</string> <string name="bitmap_cache_size">图片绘制缓存</string>
<string name="export_pics_file">TXT导出图片</string> <string name="export_pics_file">TXT导出图片</string>
<!-- string end --> <!-- string end -->
<string name="error_decode_bitmap">图片解码失败</string>
<string name="error_image_url_empty">图片链接为空,检查替换净化规则</string>
</resources> </resources>

@ -995,4 +995,6 @@
<string name="bitmap_cache_size">圖片繪製快取</string> <string name="bitmap_cache_size">圖片繪製快取</string>
<string name="export_pics_file">TXT匯出圖片</string> <string name="export_pics_file">TXT匯出圖片</string>
<!-- string end --> <!-- string end -->
<string name="error_decode_bitmap">图片解码失败</string>
<string name="error_image_url_empty">图片链接为空,检查替换净化规则</string>
</resources> </resources>

@ -995,4 +995,6 @@
<string name="bitmap_cache_size">图片绘制缓存</string> <string name="bitmap_cache_size">图片绘制缓存</string>
<string name="export_pics_file">TXT导出图片</string> <string name="export_pics_file">TXT导出图片</string>
<!-- string end --> <!-- string end -->
<string name="error_decode_bitmap">图片解码失败</string>
<string name="error_image_url_empty">图片链接为空,检查替换净化规则</string>
</resources> </resources>

@ -996,4 +996,6 @@
<string name="bitmap_cache_size">bitmap cache size</string> <string name="bitmap_cache_size">bitmap cache size</string>
<string name="export_pics_file">Export Picture Files</string> <string name="export_pics_file">Export Picture Files</string>
<!-- string end --> <!-- string end -->
<string name="error_decode_bitmap">Fail to decode bitmap</string>
<string name="error_image_url_empty">Image url is empty, check replacement rules</string>
</resources> </resources>

Loading…
Cancel
Save