Glide and Image Display Codelab Flashcards
What four things does Glide do with an image?
What two things does Glide need?
Glide is used to
- download
- buffer
- decode
- cache images.
Glide needs
- the url of the image
- an ImageView to display the image
What is the implementation for the Glide dependency?
implementation “com.github.bumptech.glide:glide:$version_glide”
Define a function that loads an image from its url to an ImageView
fun bindImage(imgView: ImageView, imgUrl: String?) {
imgUrl?.let {
val imgUri = imgUrl.toUri().buildUpon().scheme(“https”).build()
Glide.with(imgView.context)
.load(imgUri)
.apply(RequestOptions()
.placeholder(R.drawable.loading_animation)
.error(R.drawable.ic_broken_image)
)
.into(imgView)
}
}
What is the codelabs strategy for handling loading / error states on the UI?
- Create an enum for LOADING, ERROR, DONE
- Use a LiveData to track the status
- Update the network calls in the ViewModel to set the LiveData when the status changes
- Create a binding adapter that changes an ImageView based on the status
- Add an ImageView that can be substituted in for the RecyclerView when in LOADING / ERROR state.
In addition to ^variable^, what needs to go in the data element of a layout xml in order to perform logic using another class (e.g. set a view to View.VISIBLE or View.GONE)?
How do you then define the View’s visibility value in the xml?
^data^
^variable
name=”property”
type=”com.example.android.marsrealestate.network.MarsProperty” /^
^import type=”android.view.View” /^
^/data^
android:visibility=”@{property.rental ? View.GONE : View.VISIBLE}”
How can you display one ImageView over the top of another?
Wrap both in a FrameLayout.
The topmost ImageView in code will appear as the bottommost layer.
What parameter can be passed to a CRUD function calling an endpoint that applies “?filter=value”?
@Query(“filter”) type:String
type can be an enum value based on available endpoint filters