api获取封面优化,获取失败返回默认图片

pull/1161/head
gedoor 3 years ago
parent 3cc1db8516
commit 5aada9002e
  1. 12
      app/src/main/java/io/legado/app/api/controller/BookController.kt

@ -1,5 +1,6 @@
package io.legado.app.api.controller package io.legado.app.api.controller
import androidx.core.graphics.drawable.toBitmap
import io.legado.app.R import io.legado.app.R
import io.legado.app.api.ReturnData import io.legado.app.api.ReturnData
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
@ -43,11 +44,12 @@ object BookController {
fun getCover(parameters: Map<String, List<String>>): ReturnData { fun getCover(parameters: Map<String, List<String>>): ReturnData {
val returnData = ReturnData() val returnData = ReturnData()
val coverPath = parameters["path"]?.firstOrNull() val coverPath = parameters["path"]?.firstOrNull()
val ftBitmap = ImageLoader.loadBitmap(appCtx, coverPath) val ftBitmap = ImageLoader.loadBitmap(appCtx, coverPath).submit()
.placeholder(CoverImageView.defaultDrawable) return try {
.error(CoverImageView.defaultDrawable) returnData.setData(ftBitmap.get())
.submit() } catch (e: Exception) {
return returnData.setData(ftBitmap.get()) returnData.setData(CoverImageView.defaultDrawable.toBitmap())
}
} }
/** /**

Loading…
Cancel
Save