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
import kotlinx.coroutines.* | |
private val deferreds = mutableMapOf<String, Deferred<*>>() | |
@Suppress("UNCHECKED_CAST") | |
fun <T> doAsync(key: String, action: suspend () -> T): Deferred<T> { | |
val deferredResult = deferreds[key]?.takeIf { it.isActive } | |
?: GlobalScope.async { action() }.also { deferreds[key] = it } | |
return deferredResult as Deferred<T> | |
} |
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?) { | |
... | |
window.sharedElementEnterTransition = TransitionSet() | |
.addTransition(ChangeImageTransform()) | |
.addTransition(ChangeBounds()) | |
.apply { | |
doOnEnd { detailImage.load(url) } | |
} | |
} |
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?) { | |
... | |
detailImage.load(url, loadOnlyFromCache = true) { | |
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 requestOptions = RequestOptions.placeholderOf(R.drawable.placeholder) | |
.dontTransform() | |
Glide.with(this) | |
.load(url) | |
.apply(requestOptions) | |
.listener(listener) | |
.into(this) | |
} |
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
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_detail) | |
val url = intent.getStringExtra(IMAGE_URL_KEY) | |
detailImage.transitionName = url | |
detailImage.load(url) | |
} |
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 goToDetails(url: String, imageView: View) { | |
val options = ActivityOptionsCompat.makeSceneTransitionAnimation(this, imageView, imageView.transitionName).toBundle() | |
Intent(this, DetailActivity::class.java) | |
.putExtra(IMAGE_URL_KEY, url) | |
.let { | |
startActivity(it, options) | |
} | |
} |
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) { | |
Glide.with(this) | |
.load(url) | |
.apply(RequestOptions.placeholderOf(R.drawable.placeholder)) | |
.into(this) | |
} |