Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun ImageView.loadImageOrInitial(
- url: String?,
- text: String?,
- textSize: Float = 16F,
- textColor: Int = Color.BLACK,
- backgroundColor: Int = Color.TRANSPARENT,
- maxChar: Int = 2,
- allCaps: Boolean = true,
- progressStroke: Float = 5F,
- progressRadius: Float = 30F,
- ) {
- val progressDrawable = CircularProgressDrawable(context)
- progressDrawable.strokeWidth = progressStroke.dp
- progressDrawable.centerRadius = progressRadius.dp
- progressDrawable.start()
- Glide.with(this)
- .load(url)
- .placeholder(progressDrawable)
- .addListener(object : RequestListener<Drawable> {
- override fun onLoadFailed(
- e: GlideException?,
- model: Any?,
- target: Target<Drawable>?,
- isFirstResource: Boolean
- ): Boolean {
- val context = this@loadImageOrInitial.context
- val textDrawable = InitialsDrawable(
- context,
- text ?: "",
- textSize,
- textColor,
- backgroundColor,
- maxChar,
- allCaps,
- )
- textDrawable.setBounds(0, 0, 40, 40)
- this@loadImageOrInitial.setImageDrawable(textDrawable)
- return true
- }
- override fun onResourceReady(
- resource: Drawable?,
- model: Any?,
- target: Target<Drawable>?,
- dataSource: DataSource?,
- isFirstResource: Boolean
- ): Boolean {
- return false
- }
- })
- .into(this)
- }
Advertisement
Add Comment
Please, Sign In to add comment