feat(ImageProvider): toast when image url is empty

This commit is contained in:
Xwite
2022-06-01 18:02:29 +08:00
parent 99835dfc17
commit 2f4f7f46b7
8 changed files with 20 additions and 3 deletions
@@ -13,8 +13,7 @@ import io.legado.app.help.BookHelp
import io.legado.app.help.config.AppConfig
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.localBook.EpubFile
import io.legado.app.utils.BitmapUtils
import io.legado.app.utils.FileUtils
import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.withContext
import splitties.init.appCtx
@@ -113,6 +112,10 @@ object ImageProvider {
width: Int,
height: Int? = null
): Bitmap {
//src为空白时 可能被净化替换掉了 或者规则失效
if (book.getUseReplaceRule() && src.isBlank()) {
appCtx.toastOnUi(R.string.error_image_url_empty)
}
val vFile = BookHelp.getImage(book, src)
if (!vFile.exists()) return errorBitmap
//epub文件提供图片链接是相对链接,同时阅读多个epub文件,缓存命中错误
@@ -122,7 +125,7 @@ object ImageProvider {
@Suppress("BlockingMethodInNonBlockingContext")
return kotlin.runCatching {
val bitmap = BitmapUtils.decodeBitmap(vFile.absolutePath, width, height)
?: throw NoStackTraceException("解析图片失败")
?: throw NoStackTraceException(appCtx.getString(R.string.error_decode_bitmap))
bitmapLruCache.put(vFile.absolutePath, bitmap)
bitmap
}.onFailure {
@@ -993,4 +993,6 @@
<string name="bitmap_cache_size">bitmap cache size</string>
<string name="export_pics_file">Export Picture Files</string>
<!-- 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>
@@ -996,4 +996,6 @@
<string name="bitmap_cache_size">bitmap cache size</string>
<string name="export_pics_file">Export Picture Files</string>
<!-- 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>
@@ -996,4 +996,6 @@
<string name="bitmap_cache_size">bitmap cache size</string>
<string name="export_pics_file">Export Picture Files</string>
<!-- 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>
@@ -993,4 +993,6 @@
<string name="bitmap_cache_size">图片绘制缓存</string>
<string name="export_pics_file">TXT导出图片</string>
<!-- string end -->
<string name="error_decode_bitmap">图片解码失败</string>
<string name="error_image_url_empty">图片链接为空,检查替换净化规则</string>
</resources>
@@ -995,4 +995,6 @@
<string name="bitmap_cache_size">圖片繪製快取</string>
<string name="export_pics_file">TXT匯出圖片</string>
<!-- string end -->
<string name="error_decode_bitmap">图片解码失败</string>
<string name="error_image_url_empty">图片链接为空,检查替换净化规则</string>
</resources>
+2
View File
@@ -995,4 +995,6 @@
<string name="bitmap_cache_size">图片绘制缓存</string>
<string name="export_pics_file">TXT导出图片</string>
<!-- string end -->
<string name="error_decode_bitmap">图片解码失败</string>
<string name="error_image_url_empty">图片链接为空,检查替换净化规则</string>
</resources>
+2
View File
@@ -996,4 +996,6 @@
<string name="bitmap_cache_size">bitmap cache size</string>
<string name="export_pics_file">Export Picture Files</string>
<!-- 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>