pavi2410
07/20/2019, 11:04 AMfun ImageView.loadImage(
url: String?,
@DrawableRes placeholder: Int? = null,
circular: Boolean = false,
roundedCorners: Int = 0
) {
Glide.with(context)
.load(url)
.apply {
placeholder?.let { apply(RequestOptions().placeholder(it)) }
if (circular) {
apply(RequestOptions.circleCropTransform())
} else if (roundedCorners != 0) {
apply(RequestOptions.bitmapTransform(RoundedCorners(context.dip(roundedCorners))))
}
}
.into(this)
}
I would love to get any suggestions/improvements to this function.Dominaezzz
07/20/2019, 11:19 AMfun ImageView.loadImage(
url: String?,
@DrawableRes placeholder: Int? = null,
circular: Boolean = false,
roundedCorners: Int = 0
) {
with(Glide.with(context)) {
load(url)
placeholder?.let { apply(RequestOptions().placeholder(it)) }
if (circular) {
apply(RequestOptions.circleCropTransform())
} else if (roundedCorners != 0) {
apply(RequestOptions.bitmapTransform(RoundedCorners(context.dip(roundedCorners))))
}
into(this@loadImage)
}
}
Dominaezzz
07/20/2019, 11:21 AMpavi2410
07/20/2019, 1:38 PMthis@loadImage
though ๐ฃDominaezzz
07/20/2019, 2:03 PMfun ImageView.loadImage(
url: String?,
@DrawableRes placeholder: Int? = null,
circular: Boolean = false,
roundedCorners: Int = 0
) {
with(Glide.with(context)) {
load(url)
placeholder?.let { apply(RequestOptions().placeholder(it)) }
if (circular) {
apply(RequestOptions.circleCropTransform())
} else if (roundedCorners != 0) {
apply(RequestOptions.bitmapTransform(RoundedCorners(context.dip(roundedCorners))))
}
}.into(this)
}
Dominaezzz
07/20/2019, 2:03 PMKindRoacher
07/21/2019, 8:19 AMJacob Applin
07/21/2019, 2:11 PMpavi2410
07/21/2019, 6:57 PMDominaezzz
07/21/2019, 7:00 PMKirill Grouchnikov
07/21/2019, 11:32 PMKirill Grouchnikov
07/21/2019, 11:34 PMprasham.h.trivedi
07/22/2019, 6:08 AMGlide.with(context)
directly. If you can, generate RequestManager
using Glide.with(this)
in your Activities
or Fragments
. This step will help you a lot to reclaim memory when your fragment or activity is out of lifecycle.