Skip to content

Commit

Permalink
Merge pull request android#280 from yrezgui/dev_alpha07
Browse files Browse the repository at this point in the history
[JetNews] Bump to alpha07
  • Loading branch information
yrezgui authored Nov 11, 2020
2 parents a68a925 + 00a472b commit 8534fc2
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 101 deletions.
5 changes: 5 additions & 0 deletions JetNews/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ android {
kotlinCompilerVersion kotlin_version
kotlinCompilerExtensionVersion compose_version
}

packagingOptions {
excludes += "/META-INF/AL2.0"
excludes += "/META-INF/LGPL2.1"
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import androidx.compose.material.SnackbarHostState
import androidx.compose.material.rememberScaffoldState
import androidx.compose.runtime.ExperimentalComposeApi
import androidx.compose.runtime.snapshots.snapshotFlow
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.onNodeWithText
import androidx.test.platform.app.InstrumentationRegistry
import androidx.ui.test.assertIsDisplayed
import androidx.ui.test.createComposeRule
import androidx.ui.test.onNodeWithText
import com.example.jetnews.ui.home.HomeScreen
import com.example.jetnews.ui.state.UiState
import kotlinx.coroutines.flow.filterNotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

package com.example.jetnews

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasSubstring
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.filters.MediumTest
import androidx.test.platform.app.InstrumentationRegistry
import androidx.ui.test.assertIsDisplayed
import androidx.ui.test.createComposeRule
import androidx.ui.test.hasSubstring
import androidx.ui.test.onNodeWithText
import androidx.ui.test.performClick
import org.junit.Before
import org.junit.Ignore
import org.junit.Rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ package com.example.jetnews

import android.content.Context
import androidx.compose.runtime.remember
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.lifecycle.SavedStateHandle
import androidx.ui.test.ComposeTestRuleJUnit
import com.example.jetnews.ui.JetnewsApp
import com.example.jetnews.ui.NavigationViewModel

/**
* Launches the app from a test context
*/
fun ComposeTestRuleJUnit.launchJetNewsApp(context: Context) {
fun ComposeTestRule.launchJetNewsApp(context: Context) {
setContent {
JetnewsApp(
TestAppContainer(context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package com.example.jetnews.ui

import androidx.compose.animation.Crossfade
import androidx.compose.foundation.Image
import androidx.compose.foundation.Text
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand All @@ -31,6 +30,7 @@ import androidx.compose.foundation.layout.preferredWidth
import androidx.compose.material.Divider
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Home
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ package com.example.jetnews.ui.article

import android.content.Context
import android.content.Intent
import androidx.compose.foundation.AmbientContentColor
import androidx.compose.foundation.Text
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.preferredHeight
import androidx.compose.material.AlertDialog
import androidx.compose.material.AmbientContentColor
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.material.TopAppBar
import androidx.compose.material.icons.Icons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

package com.example.jetnews.ui.article

import androidx.compose.foundation.AmbientContentColor
import androidx.compose.foundation.Image
import androidx.compose.foundation.ScrollableColumn
import androidx.compose.foundation.Text
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand All @@ -32,21 +30,24 @@ import androidx.compose.foundation.layout.preferredHeight
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.foundation.layout.preferredWidth
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.text.FirstBaseline
import androidx.compose.material.AmbientEmphasisLevels
import androidx.compose.material.AmbientContentAlpha
import androidx.compose.material.AmbientContentColor
import androidx.compose.material.Colors
import androidx.compose.material.ContentAlpha
import androidx.compose.material.MaterialTheme
import androidx.compose.material.ProvideEmphasis
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.Typography
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccountCircle
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Providers
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.layout.FirstBaseline
import androidx.compose.ui.platform.DensityAmbient
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.ParagraphStyle
Expand Down Expand Up @@ -82,7 +83,7 @@ fun PostContent(post: Post, modifier: Modifier = Modifier) {
Text(text = post.title, style = MaterialTheme.typography.h4)
Spacer(Modifier.preferredHeight(8.dp))
post.subtitle?.let { subtitle ->
ProvideEmphasis(AmbientEmphasisLevels.current.medium) {
Providers(AmbientContentAlpha provides ContentAlpha.medium) {
Text(
text = subtitle,
style = MaterialTheme.typography.body2,
Expand Down Expand Up @@ -122,14 +123,13 @@ private fun PostMetadata(metadata: Metadata) {
)
Spacer(Modifier.preferredWidth(8.dp))
Column {
ProvideEmphasis(AmbientEmphasisLevels.current.high) {
Text(
text = metadata.author.name,
style = typography.caption,
modifier = Modifier.padding(top = 4.dp)
)
}
ProvideEmphasis(AmbientEmphasisLevels.current.medium) {
Text(
text = metadata.author.name,
style = typography.caption,
modifier = Modifier.padding(top = 4.dp)
)

Providers(AmbientContentAlpha provides ContentAlpha.medium) {
Text(
text = "${metadata.date}${metadata.readTimeMinutes} min read",
style = typography.caption
Expand Down
33 changes: 14 additions & 19 deletions JetNews/app/src/main/java/com/example/jetnews/ui/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package com.example.jetnews.ui.home

import androidx.compose.foundation.ScrollableColumn
import androidx.compose.foundation.ScrollableRow
import androidx.compose.foundation.Text
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand All @@ -27,25 +26,24 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.AmbientEmphasisLevels
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Divider
import androidx.compose.material.DrawerValue
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.MaterialTheme
import androidx.compose.material.ProvideEmphasis
import androidx.compose.material.Scaffold
import androidx.compose.material.ScaffoldState
import androidx.compose.material.SnackbarResult
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.material.TopAppBar
import androidx.compose.material.rememberDrawerState
import androidx.compose.material.rememberScaffoldState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedTask
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
Expand Down Expand Up @@ -139,7 +137,7 @@ fun HomeScreen(
// Show snackbar using a coroutine, when the coroutine is cancelled the snackbar will
// automatically dismiss. This coroutine will cancel whenever posts.hasError changes, and
// only start when posts.hasError is true (due to the above if-check).
LaunchedTask(posts.hasError) {
LaunchedEffect(posts.hasError) {
val snackbarResult = scaffoldState.snackbarHostState.showSnackbar(
message = errorMessage,
actionLabel = retryMessage
Expand Down Expand Up @@ -313,13 +311,11 @@ private fun FullScreenLoading() {
*/
@Composable
private fun PostListTopSection(post: Post, navigateTo: (Screen) -> Unit) {
ProvideEmphasis(AmbientEmphasisLevels.current.high) {
Text(
modifier = Modifier.padding(start = 16.dp, top = 16.dp, end = 16.dp),
text = "Top stories for you",
style = MaterialTheme.typography.subtitle1
)
}
Text(
modifier = Modifier.padding(start = 16.dp, top = 16.dp, end = 16.dp),
text = "Top stories for you",
style = MaterialTheme.typography.subtitle1
)
PostCardTop(
post = post,
modifier = Modifier.clickable(onClick = { navigateTo(Screen.Article(post.id)) })
Expand Down Expand Up @@ -365,13 +361,12 @@ private fun PostListPopularSection(
navigateTo: (Screen) -> Unit
) {
Column {
ProvideEmphasis(AmbientEmphasisLevels.current.high) {
Text(
modifier = Modifier.padding(16.dp),
text = "Popular on Jetnews",
style = MaterialTheme.typography.subtitle1
)
}
Text(
modifier = Modifier.padding(16.dp),
text = "Popular on Jetnews",
style = MaterialTheme.typography.subtitle1
)

ScrollableRow(modifier = Modifier.padding(end = 16.dp)) {
posts.forEach { post ->
PostCardPopular(post, navigateTo, Modifier.padding(start = 16.dp, bottom = 16.dp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@
package com.example.jetnews.ui.home

import androidx.compose.foundation.Image
import androidx.compose.foundation.Text
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.preferredHeight
import androidx.compose.material.AmbientEmphasisLevels
import androidx.compose.material.AmbientContentAlpha
import androidx.compose.material.ContentAlpha
import androidx.compose.material.MaterialTheme
import androidx.compose.material.ProvideEmphasis
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Providers
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
Expand All @@ -54,18 +55,16 @@ fun PostCardTop(post: Post, modifier: Modifier = Modifier) {
}
Spacer(Modifier.preferredHeight(16.dp))

val emphasisLevels = AmbientEmphasisLevels.current
ProvideEmphasis(emphasisLevels.high) {
Text(
text = post.title,
style = typography.h6
)
Text(
text = post.metadata.author.name,
style = typography.body2
)
}
ProvideEmphasis(emphasisLevels.medium) {
Text(
text = post.title,
style = typography.h6
)
Text(
text = post.metadata.author.name,
style = typography.body2
)

Providers(AmbientContentAlpha provides ContentAlpha.medium) {
Text(
text = "${post.metadata.date} - ${post.metadata.readTimeMinutes} min read",
style = typography.body2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@
package com.example.jetnews.ui.home

import androidx.compose.foundation.Image
import androidx.compose.foundation.Text
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.preferredHeight
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.material.AmbientEmphasisLevels
import androidx.compose.material.Card
import androidx.compose.material.MaterialTheme
import androidx.compose.material.ProvideEmphasis
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
Expand Down Expand Up @@ -62,28 +60,24 @@ fun PostCardPopular(
.fillMaxWidth()
)
Column(modifier = Modifier.padding(16.dp)) {
val emphasisLevels = AmbientEmphasisLevels.current
ProvideEmphasis(emphasisLevels.high) {
Text(
text = post.title,
style = MaterialTheme.typography.h6,
maxLines = 2,
overflow = TextOverflow.Ellipsis
)
Text(
text = post.metadata.author.name,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = MaterialTheme.typography.body2
)
}
ProvideEmphasis(emphasisLevels.high) {
Text(
text = "${post.metadata.date} - " +
"${post.metadata.readTimeMinutes} min read",
style = MaterialTheme.typography.body2
)
}
Text(
text = post.title,
style = MaterialTheme.typography.h6,
maxLines = 2,
overflow = TextOverflow.Ellipsis
)
Text(
text = post.metadata.author.name,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = MaterialTheme.typography.body2
)

Text(
text = "${post.metadata.date} - " +
"${post.metadata.readTimeMinutes} min read",
style = MaterialTheme.typography.body2
)
}
}
}
Expand Down
Loading

0 comments on commit 8534fc2

Please sign in to comment.