Created
April 5, 2018 10:37
-
-
Save Nonda95/29a4904be147ddb3466a628c649a88c3 to your computer and use it in GitHub Desktop.
Postpone Shared Element Transition
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
override fun onCreate(savedInstanceState: Bundle?) { | |
... | |
supportPostponeEnterTransition() | |
detailImage.load(url) { | |
supportStartPostponedEnterTransition() | |
} | |
} |
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
fun ImageView.load(url: String, onLoadingFinished: () -> Unit = {}) { | |
val listener = object : RequestListener<Drawable> { | |
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean { | |
onLoadingFinished() | |
return false | |
} | |
override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean { | |
onLoadingFinished() | |
return false | |
} | |
} | |
Glide.with(this) | |
.load(url) | |
.apply(RequestOptions.placeholderOf(R.drawable.placeholder)) | |
.listener(listener) | |
.into(this) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment