mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-22 13:48:55 +00:00
set ImageView's bitmap to null before setting the new bitmap in there and handle image loading errors
This commit is contained in:
parent
69bb7ead66
commit
2343ebf5ed
1 changed files with 31 additions and 15 deletions
|
|
@ -27,19 +27,27 @@ fun PixelArtView.loadImage(imageName: String?, imageFormat: String? = null) {
|
|||
}
|
||||
tag = fullname
|
||||
setImageDrawable(null)
|
||||
DataBindingUtils.loadImage(context, imageName, imageFormat) {
|
||||
if (tag == fullname) {
|
||||
bitmap = if (fullname.endsWith("gif")) {
|
||||
setImageDrawable(it)
|
||||
if (it is Animatable) {
|
||||
it.start()
|
||||
bitmap = null
|
||||
DataBindingUtils.loadImage(context, imageName, imageFormat,
|
||||
imageResult ={
|
||||
if (tag == fullname) {
|
||||
bitmap = if (fullname.endsWith("gif")) {
|
||||
setImageDrawable(it)
|
||||
if (it is Animatable) {
|
||||
it.start()
|
||||
}
|
||||
null
|
||||
} else {
|
||||
it.toBitmap()
|
||||
}
|
||||
null
|
||||
} else {
|
||||
it.toBitmap()
|
||||
}
|
||||
},
|
||||
imageError = {
|
||||
tag = null
|
||||
setImageDrawable(null)
|
||||
bitmap = null
|
||||
}
|
||||
}
|
||||
)
|
||||
} else {
|
||||
tag = null
|
||||
setImageDrawable(null)
|
||||
|
|
@ -56,14 +64,22 @@ object DataBindingUtils {
|
|||
context: Context,
|
||||
imageName: String,
|
||||
imageFormat: String?,
|
||||
imageResult: (Drawable) -> Unit
|
||||
imageResult: (Drawable) -> Unit,
|
||||
imageError:()->Unit = { }
|
||||
) {
|
||||
val request = ImageRequest.Builder(context)
|
||||
.data(BASE_IMAGE_URL + getFullFilename(imageName, imageFormat))
|
||||
.target()
|
||||
.target {
|
||||
imageResult(it)
|
||||
}
|
||||
.target(
|
||||
onStart = { _ ->
|
||||
|
||||
},
|
||||
onSuccess = {
|
||||
imageResult(it)
|
||||
},
|
||||
onError = {
|
||||
imageError()
|
||||
}
|
||||
)
|
||||
.build()
|
||||
context.imageLoader.enqueue(request)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue