优化dataUri处理
This commit is contained in:
@@ -4,7 +4,6 @@ import android.content.Context
|
|||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.util.Base64
|
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
import com.bumptech.glide.RequestBuilder
|
import com.bumptech.glide.RequestBuilder
|
||||||
import io.legado.app.constant.AppPattern.dataUriRegex
|
import io.legado.app.constant.AppPattern.dataUriRegex
|
||||||
@@ -20,16 +19,12 @@ object ImageLoader {
|
|||||||
* 自动判断path类型
|
* 自动判断path类型
|
||||||
*/
|
*/
|
||||||
fun load(context: Context, path: String?): RequestBuilder<Drawable> {
|
fun load(context: Context, path: String?): RequestBuilder<Drawable> {
|
||||||
val dataUriFindResult = dataUriRegex.find(path ?: "")
|
|
||||||
return when {
|
return when {
|
||||||
path.isNullOrEmpty() -> GlideApp.with(context).load(path)
|
path.isNullOrEmpty() -> GlideApp.with(context).load(path)
|
||||||
dataUriFindResult != null -> kotlin.runCatching {
|
dataUriRegex.find(path) != null -> {
|
||||||
val dataUriBase64 = dataUriFindResult.groupValues[1]
|
//glide内部已经实现dataUri解析
|
||||||
val byteArray = Base64.decode(dataUriBase64, Base64.DEFAULT)
|
|
||||||
GlideApp.with(context).load(byteArray)
|
|
||||||
}.getOrDefault(
|
|
||||||
GlideApp.with(context).load(path)
|
GlideApp.with(context).load(path)
|
||||||
)
|
}
|
||||||
path.isAbsUrl() -> {
|
path.isAbsUrl() -> {
|
||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
val url = AnalyzeUrl(path).getGlideUrl()
|
val url = AnalyzeUrl(path).getGlideUrl()
|
||||||
|
|||||||
@@ -127,7 +127,12 @@ object BookInfo {
|
|||||||
Debug.log(bookSource.bookSourceUrl, "┌获取封面链接")
|
Debug.log(bookSource.bookSourceUrl, "┌获取封面链接")
|
||||||
try {
|
try {
|
||||||
analyzeRule.getString(infoRule.coverUrl).let {
|
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}")
|
Debug.log(bookSource.bookSourceUrl, "└${it}")
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|||||||
@@ -229,8 +229,12 @@ object BookList {
|
|||||||
Debug.log(bookSource.bookSourceUrl, "┌获取封面链接", log)
|
Debug.log(bookSource.bookSourceUrl, "┌获取封面链接", log)
|
||||||
try {
|
try {
|
||||||
analyzeRule.getString(ruleCoverUrl).let {
|
analyzeRule.getString(ruleCoverUrl).let {
|
||||||
if (it.isNotEmpty()) searchBook.coverUrl =
|
if (it.startsWith("data:")) {
|
||||||
NetworkUtils.getAbsoluteURL(baseUrl, it)
|
searchBook.coverUrl = it
|
||||||
|
} else if (it.isNotEmpty()) {
|
||||||
|
searchBook.coverUrl =
|
||||||
|
NetworkUtils.getAbsoluteURL(baseUrl, it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Debug.log(bookSource.bookSourceUrl, "└${searchBook.coverUrl}", log)
|
Debug.log(bookSource.bookSourceUrl, "└${searchBook.coverUrl}", log)
|
||||||
} catch (e: java.lang.Exception) {
|
} catch (e: java.lang.Exception) {
|
||||||
|
|||||||
Reference in New Issue
Block a user