Display authors for Card UI

Bug: 216019530
Change-Id: Icc94cee83eb8f1375d9100037861217435b4d4ec
pull/2/head
Caren Chang 3 years ago
parent 89f54c23d6
commit 65785181ac

@ -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

@ -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<Author>
) {
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(

@ -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" }

Loading…
Cancel
Save