Skip to content

Commit

Permalink
Fixed obsolete images for releases
Browse files Browse the repository at this point in the history
  • Loading branch information
Faltenreich committed Sep 28, 2020
1 parent b39331a commit 98ee7c5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
package com.faltenreich.release.domain.release

import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.widget.ImageView
import androidx.core.content.ContextCompat
import com.faltenreich.release.data.model.Release
import com.faltenreich.release.framework.glide.setImageAsync


private fun ImageView.setImage(
url: String?,
callback: ((Drawable?) -> Unit)?
) {
// FIXME: Missing fallback
val placeholder = ColorDrawable(ContextCompat.getColor(context, android.R.color.transparent))
url?.let {
setImageAsync(url, null, callback)
} ?: callback?.invoke(null)
setImageAsync(url, placeholder) { drawable ->
if (drawable == null) {
onImageNotFound(placeholder, callback)
} else {
callback?.invoke(drawable)
}
}
} ?: onImageNotFound(placeholder, callback)
}

private fun ImageView.onImageNotFound(
placeholder: Drawable,
callback: ((Drawable?) -> Unit)?
) {
setImageDrawable(placeholder)
callback?.invoke(null)
}

fun ImageView.setWallpaper(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fun ImageView.setImageAsync(
GlideApp
.with(this)
.load(url)
.run { placeholder?.let { placeholder(it) } ?: this }
.placeholder(placeholder)
.listener(object : RequestListener<Drawable> {

override fun onResourceReady(
Expand Down

0 comments on commit 98ee7c5

Please sign in to comment.