Commit 6ff4aa22 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Add FrescoAvatarHelper.kt

parent 2b5ecfbe
package chat.rocket.android.widget.helper
import android.net.Uri
import android.support.graphics.drawable.VectorDrawableCompat
import chat.rocket.android.widget.R
import com.facebook.drawee.backends.pipeline.Fresco
import com.facebook.drawee.drawable.ProgressBarDrawable
import com.facebook.drawee.view.SimpleDraweeView
class FrescoAvatarHelper {
companion object {
@JvmStatic fun setupDraweeAndLoadImage(draweeView: SimpleDraweeView, imageUrl: String) {
FrescoAvatarHelper.setupDrawee(draweeView)
FrescoAvatarHelper.loadImage(imageUrl, draweeView)
}
@JvmStatic fun setupDrawee(draweeView: SimpleDraweeView) {
val hierarchy = draweeView.hierarchy
hierarchy.setPlaceholderImage(VectorDrawableCompat.create(draweeView.resources, R.drawable.ic_avatar_placeholder, null))
hierarchy.setFailureImage(VectorDrawableCompat.create(draweeView.resources, R.drawable.ic_avatar_failure, null))
hierarchy.setProgressBarImage(ProgressBarDrawable())
}
@JvmStatic fun loadImage(imageUrl: String, draweeView: SimpleDraweeView) {
val controller = Fresco.newDraweeControllerBuilder()
.setUri(Uri.parse(imageUrl))
.setAutoPlayAnimations(true)
.setTapToRetryEnabled(true)
.build()
draweeView.controller = controller
}
@JvmStatic fun showFailureImage(draweeView: SimpleDraweeView) {
val hierarchy = draweeView.hierarchy
hierarchy.setPlaceholderImage(VectorDrawableCompat.create(draweeView.resources, R.drawable.ic_avatar_failure, null))
hierarchy.setFailureImage(VectorDrawableCompat.create(draweeView.resources, R.drawable.ic_avatar_failure, null))
val controller = Fresco.newDraweeControllerBuilder()
.setAutoPlayAnimations(true)
.build()
draweeView.controller = controller
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment