-
Notifications
You must be signed in to change notification settings - Fork 120
/
GlideImageViewExtensions.kt
58 lines (50 loc) 路 1.72 KB
/
GlideImageViewExtensions.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package io.armcha.ribble.presentation.utils.glide
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.widget.ImageView
import com.bumptech.glide.load.Transformation
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.target.DrawableImageViewTarget
/**
* Created by Chatikyan on 28.08.2017.
*/
private val DEFAULT_DURATION_MS = 200
fun ImageView.load(url: String?) {
load(this, url)
}
fun ImageView.load(url: String?, transformationType: TransformationType) {
load(this, url, transformationType)
}
@JvmName("privateLoad")
private fun load(view: ImageView,
url: String?,
transformationType: TransformationType = TransformationType.NOTHING) {
val glideRequest: GlideRequest<Drawable> = GlideApp.with(view.context)
.load(url)
.transition(DrawableTransitionOptions.withCrossFade(DEFAULT_DURATION_MS))
.centerCrop()
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
if (transformationType != TransformationType.NOTHING) {
glideRequest.transform(transformationType.getTransformation())
}
glideRequest.into(DrawableImageViewTarget(view))
}
fun ImageView.clear() {
GlideApp.with(context)
.clear(this)
}
enum class TransformationType {
CIRCLE,
ROUND,
NOTHING;
fun getTransformation(): Transformation<Bitmap> = when (this) {
CIRCLE -> CircleCrop()
ROUND -> RoundedCorners(20)
else -> {
TODO()
}
}
}