Skip to content

Instantly share code, notes, and snippets.

@babedev
Last active February 16, 2018 12:15
Show Gist options
  • Save babedev/60f0d78732bae7a3ec5e6ce859e8ca70 to your computer and use it in GitHub Desktop.
Save babedev/60f0d78732bae7a3ec5e6ce859e8ca70 to your computer and use it in GitHub Desktop.
Show image with Glide and start intent with Anko
fun ImageView.show(imageUrl: String = "") {
if (imageUrl.isBlank()) return
if (context == null) return
if (context is Activity && ((context as Activity).isFinishing || (context as Activity).isDestroyed)) return
Glide.with(context)
.load(imageUrl)
.crossFade()
.signature(StringSignature(UUID.randomUUID().toString()))
.into(this)
}
fun ImageView.show(imageUri: Uri) {
if (context == null) return
if (context is Activity && ((context as Activity).isFinishing || (context as Activity).isDestroyed)) return
Glide.with(context)
.load(imageUri)
.crossFade()
.signature(StringSignature(UUID.randomUUID().toString()))
.into(this)
}
fun View.callOnClick(phoneNumber: String) {
setOnClickListener { context.call(phoneNumber) }
}
fun View.browseOnClick(webUrl: String) {
setOnClickListener { context.browse(webUrl) }
}
@babedev
Copy link
Author

babedev commented May 4, 2017

sample_imageview.show("http://someimageurl.com/123")

@babedev
Copy link
Author

babedev commented May 4, 2017

sample_button.callOnClick("01123342")

sample_button.browseOnClick("http://www.google.com")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment