diff --git a/core-ui/build.gradle b/core-ui/build.gradle index 4e40909e8..fd5858dc8 100644 --- a/core-ui/build.gradle +++ b/core-ui/build.gradle @@ -44,6 +44,8 @@ dependencies { implementation project(':core-model') implementation libs.androidx.core.ktx + implementation libs.coil.kt + implementation libs.coil.kt.compose implementation libs.kotlinx.datetime api libs.androidx.compose.foundation.layout diff --git a/core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt b/core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt index 313754132..2d7c529e0 100644 --- a/core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt +++ b/core-ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt @@ -22,6 +22,9 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.shape.CircleShape import androidx.compose.material.MaterialTheme import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Bookmark @@ -31,12 +34,18 @@ import androidx.compose.material3.IconToggleButton import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.onClick import androidx.compose.ui.semantics.semantics import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import androidx.core.os.ConfigurationCompat +import coil.compose.AsyncImage import com.google.samples.apps.nowinandroid.core.model.data.Author import com.google.samples.apps.nowinandroid.core.model.data.NewsResource import com.google.samples.apps.nowinandroid.core.model.data.NewsResourceType.Article @@ -57,6 +66,10 @@ fun NewsResourceCardExpanded( Column( modifier = Modifier.padding(16.dp) ) { + Row { + NewsResourceAuthors(newsResource.authors) + } + Spacer(modifier = Modifier.height(12.dp)) Row { NewsResourceTitle(newsResource.title, modifier = Modifier.fillMaxWidth((.8f))) Spacer(modifier = Modifier.weight(1f)) @@ -76,9 +89,27 @@ fun NewsResourceHeaderImage( @Composable fun NewsResourceAuthors( - newsResource: NewsResource + authors: List ) { - TODO() + if (authors.isNotEmpty()) { + // Only display first author for now + val author = authors[0] + val authorNameFormatted = + author.name.uppercase(ConfigurationCompat.getLocales(LocalConfiguration.current).get(0)) + + Row(verticalAlignment = Alignment.CenterVertically) { + AsyncImage( + modifier = Modifier + .clip(CircleShape) + .size(24.dp), + contentScale = ContentScale.Crop, + model = author.imageUrl, + contentDescription = null // decorative image + ) + Spacer(modifier = Modifier.width(8.dp)) + Text(authorNameFormatted, style = MaterialTheme.typography.body2) + } + } } @Composable @@ -184,7 +215,7 @@ private val newsResource = NewsResource( Author( id = 1, name = "Name", - imageUrl = "imageUrl" + imageUrl = "https://source.unsplash.com/Yc5sL-ejk6U" ) ), topics = listOf( diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6ffcdf222..077c6be22 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -14,6 +14,7 @@ androidxLifecycle = "2.4.0" androidxNavigation = "2.4.0-rc01" androidxTest = "1.4.0" androidxTestExt = "1.1.2" +coil = "2.0.0-rc01" hilt = "2.41" jacoco = "0.8.7" junit4 = "4.13" @@ -60,6 +61,8 @@ androidx-test-core = { group = "androidx.test", name = "core", version.ref = "an androidx-test-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "androidxEspresso" } androidx-test-runner = { group = "androidx.test", name = "runner", version.ref = "androidxTest" } androidx-test-rules = { group = "androidx.test", name = "rules", version.ref = "androidxTest" } +coil-kt = { group = "io.coil-kt", name = "coil", version.ref = "coil"} +coil-kt-compose = { group = "io.coil-kt", name = "coil-compose", version.ref = "coil"} hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt" } hilt-compiler = { group = "com.google.dagger", name = "hilt-android-compiler", version.ref = "hilt" } hilt-android-testing = { group = "com.google.dagger", name = "hilt-android-testing", version.ref = "hilt" }