Skip to content

Commit 7dd980f

Browse files
committed
add displaying a single image
1 parent c3ed96d commit 7dd980f

15 files changed

+123
-10
lines changed

10-mars-photos/.idea/deploymentTargetDropDown.xml

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

10-mars-photos/.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

10-mars-photos/.idea/libraries/Gradle__com_github_bumptech_glide_annotations_4_8_0.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

10-mars-photos/.idea/libraries/Gradle__com_github_bumptech_glide_disklrucache_4_8_0.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

10-mars-photos/.idea/libraries/Gradle__com_github_bumptech_glide_gifdecoder_4_8_0_aar.xml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

10-mars-photos/.idea/libraries/Gradle__com_github_bumptech_glide_glide_4_8_0_aar.xml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

10-mars-photos/.idea/misc.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

10-mars-photos/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@ An app to learn how to get data from an API, using Retrofit to make REST request
1212
- implementing a network layer for the app using the Retrofit library.
1313
- parsing the JSON response into the app's LiveData objects with the Moshi library.
1414
- using Retrofit's support for coroutines to simplify the code.
15+
- using the Glide library to load and display an image from a web URL.
16+
- adding a loading animation and error icon.
17+
- displaying a grid of images with a RecyclerView.
18+
- handling potential errors.
1519

1620
Based on [Get data from the internet](https://developer.android.com/codelabs/basic-android-kotlin-training-getting-data-internet) by Google Codelabs (2022).

10-mars-photos/app/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ dependencies {
7070
// Retrofit with Moshi Converter
7171
implementation 'com.squareup.retrofit2:converter-moshi:2.9.0'
7272

73+
// Glide
74+
implementation 'com.github.bumptech.glide:glide:4.8.0'
75+
7376
implementation 'com.google.android.material:material:1.4.0'
7477
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
7578
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.example.android.marsphotos
2+
3+
import android.widget.ImageView
4+
import androidx.core.net.toUri
5+
import androidx.databinding.BindingAdapter
6+
import com.bumptech.glide.Glide
7+
import com.bumptech.glide.request.RequestOptions
8+
9+
@BindingAdapter("imageUrl")
10+
fun bindImage(imgView: ImageView, imgUrl: String?) {
11+
imgUrl?.let {
12+
val imgUri = imgUrl.toUri().buildUpon().scheme("https").build()
13+
Glide.with(imgView.context)
14+
.load(imgUri)
15+
.apply(RequestOptions()
16+
.placeholder(R.drawable.loading_animation)
17+
.error(R.drawable.ic_broken_image))
18+
.into(imgView)
19+
}
20+
}

0 commit comments

Comments
 (0)