Skip to content

Commit

Permalink
#4 - Working with Text
Browse files Browse the repository at this point in the history
  • Loading branch information
jhg3410 committed Feb 5, 2023
1 parent 99f9082 commit 4af1bf3
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.heading
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.codelab.theming.R
Expand All @@ -46,9 +47,7 @@ import java.util.*
fun Home() {
val featured = remember { PostRepo.getFeaturedPost() }
val posts = remember { PostRepo.getPosts() }
JetnewsTheme(
darkTheme = true
) {
JetnewsTheme {
Scaffold(
topBar = { AppBar() }
) { innerPadding ->
Expand Down Expand Up @@ -103,6 +102,7 @@ fun Header(
) {
Text(
text = text,
style = MaterialTheme.typography.subtitle2,
modifier = Modifier
.fillMaxWidth()
.semantics { heading() }
Expand Down Expand Up @@ -135,10 +135,12 @@ fun FeaturedPost(
val padding = Modifier.padding(horizontal = 16.dp)
Text(
text = post.title,
style = MaterialTheme.typography.h6,
modifier = padding
)
Text(
text = post.metadata.author.name,
style = MaterialTheme.typography.body2,
modifier = padding
)
PostMetadata(post, padding)
Expand All @@ -154,6 +156,9 @@ private fun PostMetadata(
) {
val divider = ""
val tagDivider = " "
val tagStyle = MaterialTheme.typography.overline.toSpanStyle().copy(
background = MaterialTheme.colors.primary.copy(alpha = 0.1f)
)
val text = buildAnnotatedString {
append(post.metadata.date)
append(divider)
Expand All @@ -163,12 +168,15 @@ private fun PostMetadata(
if (index != 0) {
append(tagDivider)
}
append(" ${tag.uppercase(Locale.getDefault())} ")
withStyle(tagStyle) {
append(" ${tag.uppercase(Locale.getDefault())} ")
}
}
}
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) {
Text(
text = text,
style = MaterialTheme.typography.body2,
modifier = modifier
)
}
Expand Down

0 comments on commit 4af1bf3

Please sign in to comment.