Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Jan 27, 2025
1 parent 9ef1240 commit 86d424f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions app/src/main/java/io/legado/app/help/glide/ImageLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.annotation.DrawableRes
import androidx.lifecycle.Lifecycle
import com.bumptech.glide.Glide
import com.bumptech.glide.RequestBuilder
import com.bumptech.glide.request.RequestOptions
import io.legado.app.utils.isAbsUrl
import io.legado.app.utils.isContentScheme
import io.legado.app.utils.isDataUrl
Expand Down Expand Up @@ -54,15 +55,17 @@ object ImageLoader {
}

fun loadBitmap(context: Context, path: String?): RequestBuilder<Bitmap> {
val requestManager = Glide.with(context).asBitmap()
.apply(RequestOptions.decodeTypeOf(Any::class.java))
return when {
path.isNullOrEmpty() -> Glide.with(context).asBitmap().load(path)
path.isDataUrl() -> Glide.with(context).asBitmap().load(path)
path.isAbsUrl() -> Glide.with(context).asBitmap().load(path)
path.isContentScheme() -> Glide.with(context).asBitmap().load(Uri.parse(path))
path.isNullOrEmpty() -> requestManager.load(path)
path.isDataUrl() -> requestManager.load(path)
path.isAbsUrl() -> requestManager.load(path)
path.isContentScheme() -> requestManager.load(Uri.parse(path))
else -> kotlin.runCatching {
Glide.with(context).asBitmap().load(File(path))
requestManager.load(File(path))
}.getOrElse {
Glide.with(context).asBitmap().load(path)
requestManager.load(path)
}
}
}
Expand Down

0 comments on commit 86d424f

Please sign in to comment.