diff --git a/JetNews/app/build.gradle b/JetNews/app/build.gradle index ae89f0abcd..9b6c553779 100644 --- a/JetNews/app/build.gradle +++ b/JetNews/app/build.gradle @@ -68,6 +68,11 @@ android { kotlinCompilerVersion kotlin_version kotlinCompilerExtensionVersion compose_version } + + packagingOptions { + excludes += "/META-INF/AL2.0" + excludes += "/META-INF/LGPL2.1" + } } dependencies { diff --git a/JetNews/app/src/androidTest/java/com/example/jetnews/HomeScreenSnackbarTest.kt b/JetNews/app/src/androidTest/java/com/example/jetnews/HomeScreenSnackbarTest.kt index 1cbeecc096..b04675a3d2 100644 --- a/JetNews/app/src/androidTest/java/com/example/jetnews/HomeScreenSnackbarTest.kt +++ b/JetNews/app/src/androidTest/java/com/example/jetnews/HomeScreenSnackbarTest.kt @@ -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 diff --git a/JetNews/app/src/androidTest/java/com/example/jetnews/JetnewsUiTest.kt b/JetNews/app/src/androidTest/java/com/example/jetnews/JetnewsUiTest.kt index 5aceada18f..e6790eeea2 100644 --- a/JetNews/app/src/androidTest/java/com/example/jetnews/JetnewsUiTest.kt +++ b/JetNews/app/src/androidTest/java/com/example/jetnews/JetnewsUiTest.kt @@ -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 diff --git a/JetNews/app/src/androidTest/java/com/example/jetnews/TestHelper.kt b/JetNews/app/src/androidTest/java/com/example/jetnews/TestHelper.kt index 4dbc614267..e704c7bcb3 100644 --- a/JetNews/app/src/androidTest/java/com/example/jetnews/TestHelper.kt +++ b/JetNews/app/src/androidTest/java/com/example/jetnews/TestHelper.kt @@ -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), diff --git a/JetNews/app/src/main/java/com/example/jetnews/ui/JetnewsApp.kt b/JetNews/app/src/main/java/com/example/jetnews/ui/JetnewsApp.kt index c718f42b94..aee94dc6b6 100644 --- a/JetNews/app/src/main/java/com/example/jetnews/ui/JetnewsApp.kt +++ b/JetNews/app/src/main/java/com/example/jetnews/ui/JetnewsApp.kt @@ -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 @@ -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 diff --git a/JetNews/app/src/main/java/com/example/jetnews/ui/article/ArticleScreen.kt b/JetNews/app/src/main/java/com/example/jetnews/ui/article/ArticleScreen.kt index 110ae4cac7..6f950e0c8c 100644 --- a/JetNews/app/src/main/java/com/example/jetnews/ui/article/ArticleScreen.kt +++ b/JetNews/app/src/main/java/com/example/jetnews/ui/article/ArticleScreen.kt @@ -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 diff --git a/JetNews/app/src/main/java/com/example/jetnews/ui/article/PostContent.kt b/JetNews/app/src/main/java/com/example/jetnews/ui/article/PostContent.kt index 605d8fc958..d07bf94f03 100644 --- a/JetNews/app/src/main/java/com/example/jetnews/ui/article/PostContent.kt +++ b/JetNews/app/src/main/java/com/example/jetnews/ui/article/PostContent.kt @@ -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 @@ -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 @@ -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, @@ -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 diff --git a/JetNews/app/src/main/java/com/example/jetnews/ui/home/HomeScreen.kt b/JetNews/app/src/main/java/com/example/jetnews/ui/home/HomeScreen.kt index 2b63d478f8..8b9fabae99 100644 --- a/JetNews/app/src/main/java/com/example/jetnews/ui/home/HomeScreen.kt +++ b/JetNews/app/src/main/java/com/example/jetnews/ui/home/HomeScreen.kt @@ -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 @@ -27,7 +26,6 @@ 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 @@ -35,17 +33,17 @@ 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 @@ -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 @@ -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)) }) @@ -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)) diff --git a/JetNews/app/src/main/java/com/example/jetnews/ui/home/PostCardTop.kt b/JetNews/app/src/main/java/com/example/jetnews/ui/home/PostCardTop.kt index 0f44728468..036b2fc7db 100644 --- a/JetNews/app/src/main/java/com/example/jetnews/ui/home/PostCardTop.kt +++ b/JetNews/app/src/main/java/com/example/jetnews/ui/home/PostCardTop.kt @@ -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 @@ -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 diff --git a/JetNews/app/src/main/java/com/example/jetnews/ui/home/PostCardYourNetwork.kt b/JetNews/app/src/main/java/com/example/jetnews/ui/home/PostCardYourNetwork.kt index c04c08cef1..7c71a43980 100644 --- a/JetNews/app/src/main/java/com/example/jetnews/ui/home/PostCardYourNetwork.kt +++ b/JetNews/app/src/main/java/com/example/jetnews/ui/home/PostCardYourNetwork.kt @@ -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 @@ -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 + ) } } } diff --git a/JetNews/app/src/main/java/com/example/jetnews/ui/home/PostCards.kt b/JetNews/app/src/main/java/com/example/jetnews/ui/home/PostCards.kt index f33c643d44..8d75d921cf 100644 --- a/JetNews/app/src/main/java/com/example/jetnews/ui/home/PostCards.kt +++ b/JetNews/app/src/main/java/com/example/jetnews/ui/home/PostCards.kt @@ -17,23 +17,24 @@ 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.Row import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.preferredSize -import androidx.compose.material.AmbientEmphasisLevels +import androidx.compose.material.AmbientContentAlpha +import androidx.compose.material.ContentAlpha import androidx.compose.material.Icon import androidx.compose.material.IconToggleButton import androidx.compose.material.MaterialTheme -import androidx.compose.material.ProvideEmphasis import androidx.compose.material.Surface +import androidx.compose.material.Text import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Bookmark import androidx.compose.material.icons.filled.BookmarkBorder import androidx.compose.material.icons.filled.MoreVert 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.res.imageResource @@ -51,7 +52,7 @@ fun AuthorAndReadTime( modifier: Modifier = Modifier ) { Row(modifier) { - ProvideEmphasis(AmbientEmphasisLevels.current.medium) { + Providers(AmbientContentAlpha provides ContentAlpha.medium) { val textStyle = MaterialTheme.typography.body2 Text( text = post.metadata.author.name, @@ -78,9 +79,7 @@ fun PostImage(post: Post, modifier: Modifier = Modifier) { @Composable fun PostTitle(post: Post) { - ProvideEmphasis(AmbientEmphasisLevels.current.high) { - Text(post.title, style = MaterialTheme.typography.subtitle1) - } + Text(post.title, style = MaterialTheme.typography.subtitle1) } @Composable @@ -117,7 +116,7 @@ fun PostCardHistory(post: Post, navigateTo: (Screen) -> Unit) { modifier = Modifier.padding(end = 16.dp) ) Column(Modifier.weight(1f)) { - ProvideEmphasis(AmbientEmphasisLevels.current.medium) { + Providers(AmbientContentAlpha provides ContentAlpha.medium) { Text( text = "BASED ON YOUR HISTORY", style = MaterialTheme.typography.overline @@ -129,7 +128,7 @@ fun PostCardHistory(post: Post, navigateTo: (Screen) -> Unit) { modifier = Modifier.padding(top = 4.dp) ) } - ProvideEmphasis(AmbientEmphasisLevels.current.medium) { + Providers(AmbientContentAlpha provides ContentAlpha.medium) { Icon(Icons.Filled.MoreVert) } } diff --git a/JetNews/app/src/main/java/com/example/jetnews/ui/interests/InterestsScreen.kt b/JetNews/app/src/main/java/com/example/jetnews/ui/interests/InterestsScreen.kt index 313c6c59be..409e3b7987 100644 --- a/JetNews/app/src/main/java/com/example/jetnews/ui/interests/InterestsScreen.kt +++ b/JetNews/app/src/main/java/com/example/jetnews/ui/interests/InterestsScreen.kt @@ -18,7 +18,6 @@ package com.example.jetnews.ui.interests import androidx.compose.foundation.Image import androidx.compose.foundation.ScrollableColumn -import androidx.compose.foundation.Text import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -36,6 +35,7 @@ import androidx.compose.material.Scaffold import androidx.compose.material.ScaffoldState import androidx.compose.material.Tab import androidx.compose.material.TabRow +import androidx.compose.material.Text import androidx.compose.material.TopAppBar import androidx.compose.material.rememberDrawerState import androidx.compose.material.rememberScaffoldState diff --git a/JetNews/app/src/main/java/com/example/jetnews/ui/interests/SelectTopicButton.kt b/JetNews/app/src/main/java/com/example/jetnews/ui/interests/SelectTopicButton.kt index 9916dd5f30..b4271b2837 100644 --- a/JetNews/app/src/main/java/com/example/jetnews/ui/interests/SelectTopicButton.kt +++ b/JetNews/app/src/main/java/com/example/jetnews/ui/interests/SelectTopicButton.kt @@ -19,10 +19,8 @@ package com.example.jetnews.ui.interests import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.preferredSize import androidx.compose.foundation.shape.CircleShape -import androidx.compose.material.AmbientEmphasisLevels import androidx.compose.material.Icon import androidx.compose.material.MaterialTheme -import androidx.compose.material.ProvideEmphasis import androidx.compose.material.Surface import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Add @@ -49,9 +47,7 @@ fun SelectTopicButton( shape = CircleShape, modifier = modifier.preferredSize(36.dp, 36.dp) ) { - ProvideEmphasis(AmbientEmphasisLevels.current.high) { - Icon(icon) - } + Icon(icon) } } diff --git a/JetNews/build.gradle b/JetNews/build.gradle index ff6a558e49..f7cf7eefa1 100644 --- a/JetNews/build.gradle +++ b/JetNews/build.gradle @@ -16,7 +16,7 @@ buildscript { ext.kotlin_version = '1.4.10' - ext.compose_version = '1.0.0-alpha06' + ext.compose_version = '1.0.0-SNAPSHOT' repositories { google() @@ -24,7 +24,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:4.2.0-alpha15' + classpath 'com.android.tools.build:gradle:4.2.0-alpha16' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } @@ -35,6 +35,10 @@ plugins { subprojects { repositories { + maven { + def snapshot = "6961312" + url "https://androidx.dev/snapshots/builds/$snapshot/artifacts/repository/" + } google() jcenter() }