Skip to content

Commit

Permalink
Glide error placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
li2 committed Apr 28, 2020
1 parent 24a12fc commit b357591
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions view/src/main/java/me/li2/android/view/image/ImageBindings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ object ImageBindings {
"android:src",
"fallbackImageUrl",
"placeHolder",
"errorPlaceholder",
"centerCrop",
"circleCrop",
"fitCenter"
Expand All @@ -35,6 +36,7 @@ object ImageBindings {
src: String?,
fallbackImageUrl: String?,
placeHolder: Drawable?,
errorPlaceholder: Drawable?,
centerCrop: Boolean?,
circleCrop: Boolean?,
fitCenter: Boolean?) {
Expand All @@ -43,13 +45,16 @@ object ImageBindings {
if (circleCrop.orFalse()) circleCrop()
if (fitCenter.orFalse()) fitCenter()
if (placeHolder != null) placeholder(placeHolder)
if (errorPlaceholder != null) error(errorPlaceholder)
}
if (src != null) {
Glide.with(view.context)
.load(src)
.error(Glide.with(view.context).load(fallbackImageUrl))
.apply(requestOptions)
.into(view)
}
Glide.with(view.context)
.load(src)
.also {
if (fallbackImageUrl != null) {
it.error(Glide.with(view.context).load(fallbackImageUrl))
}
}
.apply(requestOptions)
.into(view)
}
}

0 comments on commit b357591

Please sign in to comment.