Last active
March 7, 2021 23:11
-
-
Save rpandey1234/6f764ce2c821dd1c9023c11ca04f79a8 to your computer and use it in GitHub Desktop.
Video explainer: https://youtu.be/Yb0I33ZSKwY
This file contains hidden or 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 android.content.Context | |
| import android.widget.ImageView | |
| import android.widget.Toast | |
| import com.bumptech.glide.Glide | |
| // From the Kotlin docs | |
| fun <T> MutableList<T>?.swap(index1: Int, index2: Int) { | |
| if (this == null) return | |
| val tmp = this[index1] // 'this' corresponds to the list | |
| this[index1] = this[index2] | |
| this[index2] = tmp | |
| } | |
| // Useful Android extensions | |
| // https://www.raywenderlich.com/10986797-extension-functions-and-properties-in-kotlin | |
| // Usage: context.showToast("hello world") | |
| fun Context.showToast(message: String, length: Int = Toast.LENGTH_LONG) { | |
| Toast.makeText(this, message, length).show() | |
| } | |
| // Before: Glide.with(this).load(IMAGE_URL).into(ivDetailImage) | |
| // After: ivDetailImage.loadImage(IMAGE_URL) | |
| fun ImageView.loadImage(imageUrl: String) { | |
| Glide.with(this).load(imageUrl).into(this) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment