|
|
@ -13,8 +13,9 @@ import io.legado.app.help.glide.ImageLoader |
|
|
|
import io.legado.app.model.localBook.EpubFile |
|
|
|
import io.legado.app.model.localBook.EpubFile |
|
|
|
import io.legado.app.utils.FileUtils |
|
|
|
import io.legado.app.utils.FileUtils |
|
|
|
import io.legado.app.utils.isXml |
|
|
|
import io.legado.app.utils.isXml |
|
|
|
import kotlinx.coroutines.runBlocking |
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
import kotlinx.coroutines.suspendCancellableCoroutine |
|
|
|
import kotlinx.coroutines.suspendCancellableCoroutine |
|
|
|
|
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
import splitties.init.appCtx |
|
|
|
import splitties.init.appCtx |
|
|
|
import java.io.File |
|
|
|
import java.io.File |
|
|
|
import java.io.FileOutputStream |
|
|
|
import java.io.FileOutputStream |
|
|
@ -66,23 +67,23 @@ object ImageProvider { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun getImage( |
|
|
|
suspend fun getImage( |
|
|
|
book: Book, |
|
|
|
book: Book, |
|
|
|
src: String, |
|
|
|
src: String, |
|
|
|
bookSource: BookSource?, |
|
|
|
bookSource: BookSource?, |
|
|
|
width: Int, |
|
|
|
width: Int, |
|
|
|
height: Int |
|
|
|
height: Int |
|
|
|
): Bitmap? { |
|
|
|
): Bitmap { |
|
|
|
val vFile = runBlocking { |
|
|
|
return withContext(IO) { |
|
|
|
cacheImage(book, src, bookSource) |
|
|
|
val vFile = cacheImage(book, src, bookSource) |
|
|
|
} |
|
|
|
try { |
|
|
|
return try { |
|
|
|
@Suppress("BlockingMethodInNonBlockingContext") |
|
|
|
ImageLoader.loadBitmap(appCtx, vFile.absolutePath) |
|
|
|
ImageLoader.loadBitmap(appCtx, vFile.absolutePath) |
|
|
|
.submit(width, height) |
|
|
|
.submit(width, height) |
|
|
|
.get() |
|
|
|
.get() |
|
|
|
} catch (e: Exception) { |
|
|
|
} catch (e: Exception) { |
|
|
|
Coroutine.async { |
|
|
|
Coroutine.async { |
|
|
|
putDebug("${vFile.absolutePath} 解码失败\n${e.toString()}", e) |
|
|
|
putDebug("${vFile.absolutePath} 解码失败\n$e", e) |
|
|
|
if (FileUtils.readText(vFile.absolutePath).isXml()) { |
|
|
|
if (FileUtils.readText(vFile.absolutePath).isXml()) { |
|
|
|
putDebug("${vFile.absolutePath}为xml,自动删除") |
|
|
|
putDebug("${vFile.absolutePath}为xml,自动删除") |
|
|
|
vFile.delete() |
|
|
|
vFile.delete() |
|
|
@ -91,22 +92,23 @@ object ImageProvider { |
|
|
|
errorBitmap |
|
|
|
errorBitmap |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun getImage( |
|
|
|
suspend fun getImage( |
|
|
|
book: Book, |
|
|
|
book: Book, |
|
|
|
src: String, |
|
|
|
src: String, |
|
|
|
bookSource: BookSource? |
|
|
|
bookSource: BookSource? |
|
|
|
): Bitmap? { |
|
|
|
): Bitmap { |
|
|
|
val vFile = runBlocking { |
|
|
|
return withContext(IO) { |
|
|
|
cacheImage(book, src, bookSource) |
|
|
|
val vFile = cacheImage(book, src, bookSource) |
|
|
|
} |
|
|
|
try { |
|
|
|
return try { |
|
|
|
@Suppress("BlockingMethodInNonBlockingContext") |
|
|
|
ImageLoader.loadBitmap(appCtx, vFile.absolutePath) |
|
|
|
ImageLoader.loadBitmap(appCtx, vFile.absolutePath) |
|
|
|
.submit(ChapterProvider.visibleWidth, ChapterProvider.visibleHeight) |
|
|
|
.submit(ChapterProvider.visibleWidth, ChapterProvider.visibleHeight) |
|
|
|
.get() |
|
|
|
.get() |
|
|
|
} catch (e: Exception) { |
|
|
|
} catch (e: Exception) { |
|
|
|
Coroutine.async { |
|
|
|
Coroutine.async { |
|
|
|
putDebug("${vFile.absolutePath} 解码失败\n${e.toString()}", e) |
|
|
|
putDebug("${vFile.absolutePath} 解码失败\n$e", e) |
|
|
|
if (FileUtils.readText(vFile.absolutePath).isXml()) { |
|
|
|
if (FileUtils.readText(vFile.absolutePath).isXml()) { |
|
|
|
putDebug("${vFile.absolutePath}为xml,自动删除") |
|
|
|
putDebug("${vFile.absolutePath}为xml,自动删除") |
|
|
|
vFile.delete() |
|
|
|
vFile.delete() |
|
|
@ -115,5 +117,6 @@ object ImageProvider { |
|
|
|
errorBitmap |
|
|
|
errorBitmap |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|