chinwag-android/app/src/main/java/com/keylesspalace/tusky/util/ImageLoadingHelper.kt
Ivan Kupalov 7623962a0d Use blurhash as image preview and as sensitive media cover, close #1571 (#1581)
* Use blurhash as image preview and as sensitive media cover, close #1571

* Fix focal point for blurhashes

* Fix video indicator overlapping sensitive media indicator

* Add a preference for blurhash

* Add blurhash to report UI.

* Introduce StatusDisplayOptions
2019-12-30 21:37:20 +01:00

51 lines
No EOL
1.6 KiB
Kotlin

@file:JvmName("ImageLoadingHelper")
package com.keylesspalace.tusky.util
import android.content.Context
import android.graphics.drawable.BitmapDrawable
import android.widget.ImageView
import androidx.annotation.Px
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.keylesspalace.tusky.R
private val centerCropTransformation = CenterCrop()
fun loadAvatar(url: String?, imageView: ImageView, @Px radius: Int, animate: Boolean) {
if (url.isNullOrBlank()) {
Glide.with(imageView)
.load(R.drawable.avatar_default)
.into(imageView)
} else {
if (animate) {
Glide.with(imageView)
.load(url)
.transform(
centerCropTransformation,
RoundedCorners(radius)
)
.placeholder(R.drawable.avatar_default)
.into(imageView)
} else {
Glide.with(imageView)
.asBitmap()
.load(url)
.transform(
centerCropTransformation,
RoundedCorners(radius)
)
.placeholder(R.drawable.avatar_default)
.into(imageView)
}
}
}
fun decodeBlurHash(context: Context, blurhash: String): BitmapDrawable {
return BitmapDrawable(context.resources, BlurHashDecoder.decode(blurhash, 32, 32, 1f))
}