Last active
March 6, 2019 14:29
-
-
Save markcadag/a88a11bb297537491f9b92a46be719d4 to your computer and use it in GitHub Desktop.
Enable pause and play gif using glide 4.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Glide.with(holder.itemView) | |
.asBitmap() | |
.load("http://i.imgur.com/VuItY0T.gif") | |
.into(holder.imageContent) | |
val playPauseGif = PlayPauseGif(holder.imageContent) | |
holder.imageContent.setOnClickListener{ | |
if (playPauseGif.isPlaying()) { | |
Log.e(TAG, "pausing") | |
playPauseGif.pause() | |
} else { | |
Log.e(TAG, "playing") | |
playPauseGif.play() | |
Glide.with(holder.itemView) | |
.load("http://i.imgur.com/VuItY0T.gif") | |
.into(playPauseGif) | |
} | |
} | |
class PlayPauseGif(view: ImageView ? ): DrawableImageViewTarget(view) { | |
var gif: GifDrawable ? = null | |
override fun onResourceReady(resource: Drawable, transition: Transition < in Drawable > ? ) { | |
if (resource is GifDrawable) { | |
gif = resource | |
} | |
super.onResourceReady(resource, transition) | |
} | |
fun isPlaying(): Boolean { | |
gif?.let { | |
return it.isRunning | |
} | |
return false | |
} | |
fun play() { | |
gif?.start() | |
} | |
fun pause() { | |
gif?.stop() | |
} | |
} | |
not working, onResourceReady never called
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so my good sir.