优化dataUri处理

pull/1713/head
kunfei 3 years ago
parent 1bce739d03
commit a957714de5
  1. 11
      app/src/main/java/io/legado/app/help/glide/ImageLoader.kt
  2. 7
      app/src/main/java/io/legado/app/model/webBook/BookInfo.kt
  3. 8
      app/src/main/java/io/legado/app/model/webBook/BookList.kt

@ -4,7 +4,6 @@ import android.content.Context
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.net.Uri
import android.util.Base64
import androidx.annotation.DrawableRes
import com.bumptech.glide.RequestBuilder
import io.legado.app.constant.AppPattern.dataUriRegex
@ -20,16 +19,12 @@ object ImageLoader {
* 自动判断path类型
*/
fun load(context: Context, path: String?): RequestBuilder<Drawable> {
val dataUriFindResult = dataUriRegex.find(path ?: "")
return when {
path.isNullOrEmpty() -> GlideApp.with(context).load(path)
dataUriFindResult != null -> kotlin.runCatching {
val dataUriBase64 = dataUriFindResult.groupValues[1]
val byteArray = Base64.decode(dataUriBase64, Base64.DEFAULT)
GlideApp.with(context).load(byteArray)
}.getOrDefault(
dataUriRegex.find(path) != null -> {
//glide内部已经实现dataUri解析
GlideApp.with(context).load(path)
)
}
path.isAbsUrl() -> {
kotlin.runCatching {
val url = AnalyzeUrl(path).getGlideUrl()

@ -127,7 +127,12 @@ object BookInfo {
Debug.log(bookSource.bookSourceUrl, "┌获取封面链接")
try {
analyzeRule.getString(infoRule.coverUrl).let {
if (it.isNotEmpty()) book.coverUrl = NetworkUtils.getAbsoluteURL(redirectUrl, it)
if (it.startsWith("data:")) {
book.coverUrl = it
} else if (it.isNotEmpty()) {
book.coverUrl =
NetworkUtils.getAbsoluteURL(baseUrl, it)
}
Debug.log(bookSource.bookSourceUrl, "${it}")
}
} catch (e: Exception) {

@ -229,8 +229,12 @@ object BookList {
Debug.log(bookSource.bookSourceUrl, "┌获取封面链接", log)
try {
analyzeRule.getString(ruleCoverUrl).let {
if (it.isNotEmpty()) searchBook.coverUrl =
NetworkUtils.getAbsoluteURL(baseUrl, it)
if (it.startsWith("data:")) {
searchBook.coverUrl = it
} else if (it.isNotEmpty()) {
searchBook.coverUrl =
NetworkUtils.getAbsoluteURL(baseUrl, it)
}
}
Debug.log(bookSource.bookSourceUrl, "${searchBook.coverUrl}", log)
} catch (e: java.lang.Exception) {

Loading…
Cancel
Save