NewsResourceCard: Display Title, Bookmark Icon and Description

Screenshot of change: https://screenshot.googleplex.com/957TAnWp96uX8Ea

Bug: 216019530
Change-Id: I58fd1b4fda06b0fb8cc5df2ba5baf7e8ddcd5a1d
pull/2/head
Caren Chang 3 years ago
parent 9f11f6ae8b
commit 8d8e72667b

@ -16,28 +16,83 @@
package com.google.samples.apps.nowinandroid.ui package com.google.samples.apps.nowinandroid.ui
import android.content.res.Configuration import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
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.material.MaterialTheme
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Bookmark import androidx.compose.material.icons.filled.Bookmark
import androidx.compose.material.icons.filled.BookmarkBorder import androidx.compose.material.icons.filled.BookmarkBorder
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.IconToggleButton import androidx.compose.material3.IconToggleButton
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.onClick import androidx.compose.ui.semantics.onClick
import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.compose.ui.unit.dp
import com.google.samples.apps.nowinandroid.R import com.google.samples.apps.nowinandroid.R
import com.google.samples.apps.nowinandroid.data.fake.FakeDataSource
import com.google.samples.apps.nowinandroid.data.model.NewsResource import com.google.samples.apps.nowinandroid.data.model.NewsResource
import com.google.samples.apps.nowinandroid.data.network.NetworkAuthor
import com.google.samples.apps.nowinandroid.data.network.NetworkEpisode
import com.google.samples.apps.nowinandroid.data.network.NetworkTopic
import com.google.samples.apps.nowinandroid.data.network.asEntity
import com.google.samples.apps.nowinandroid.ui.theme.NiaTheme import com.google.samples.apps.nowinandroid.ui.theme.NiaTheme
/** /**
* [com.google.samples.apps.nowinandroid.data.model.NewsResource] card used on the following screens: * [NewsResource] card used on the following screens: For You, Episodes, Saved
* For You, Episodes, Saved
*/ */
@Composable
fun NewsResourceCardExpanded(
newsResource: NewsResource,
isBookmarked: Boolean,
onToggleBookmark: () -> Unit
) {
Column(
modifier = Modifier.padding(16.dp)
) {
Row {
NewsResourceTitle(newsResource.entity.title, modifier = Modifier.fillMaxWidth((.8f)))
Spacer(modifier = Modifier.weight(1f))
BookmarkButton(isBookmarked, onToggleBookmark)
}
Spacer(modifier = Modifier.height(12.dp))
NewsResourceShortDescription(newsResource.entity.content)
}
}
@Composable
fun NewsResourceHeaderImage(
newsResource: NewsResource
) {
TODO()
}
@Composable
fun NewsResourceAuthors(
newsResource: NewsResource
) {
TODO()
}
@Composable
fun NewsResourceTitle(
newsResourceTitle: String,
modifier: Modifier = Modifier
) {
Text(newsResourceTitle, style = MaterialTheme.typography.h4, modifier = modifier)
}
@Composable @Composable
fun BookmarkButton( fun BookmarkButton(
isBookmarked: Boolean, isBookmarked: Boolean,
@ -63,27 +118,6 @@ fun BookmarkButton(
} }
} }
@Composable
fun NewsResourceAuthors(
newsResource: NewsResource
) {
TODO()
}
@Composable
fun NewsResourceHeaderImage(
newsResource: NewsResource
) {
TODO()
}
@Composable
fun NewsResourceTitle(
newsResource: NewsResource
) {
TODO()
}
@Composable @Composable
fun NewsResourceDate( fun NewsResourceDate(
newsResource: NewsResource newsResource: NewsResource
@ -100,9 +134,9 @@ fun NewsResourceLink(
@Composable @Composable
fun NewsResourceShortDescription( fun NewsResourceShortDescription(
newsResource: NewsResource newsResourceShortDescription: String
) { ) {
TODO() Text(newsResourceShortDescription, style = MaterialTheme.typography.body1)
} }
@Composable @Composable
@ -112,11 +146,6 @@ fun NewsResourceTopics(
TODO() TODO()
} }
@Composable
fun NewsResourceCardExpanded() {
TODO()
}
@Preview("Bookmark Button") @Preview("Bookmark Button")
@Composable @Composable
fun BookmarkButtonPreview() { fun BookmarkButtonPreview() {
@ -137,13 +166,43 @@ fun BookmarkButtonBookmarkedPreview() {
} }
} }
@Preview("Expanded resource card")
@Preview("Expanded resource card (dark)", uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable @Composable
fun ExpandedNewsResourcePreview() { fun ExpandedNewsResourcePreview(
@PreviewParameter(NewsResourcePreviewParameterProvider::class) newsResource: NewsResource
) {
NiaTheme { NiaTheme {
Surface { Surface {
NewsResourceCardExpanded() NewsResourceCardExpanded(newsResource, true, {})
} }
} }
} }
class NewsResourcePreviewParameterProvider : PreviewParameterProvider<NewsResource> {
override val values = sequenceOf(
NewsResource(
FakeDataSource.sampleResource.asEntity(),
NetworkEpisode(
id = 1,
name = "Now in Android 40",
alternateVideo = null,
alternateAudio = null,
publishDate = FakeDataSource.sampleResource.publishDate
).asEntity(),
listOf(
NetworkAuthor(
id = 1,
name = "Android",
imageUrl = ""
)
.asEntity()
),
listOf(
NetworkTopic(
id = 3,
name = "Performance",
description = ""
).asEntity()
)
)
)
}

Loading…
Cancel
Save