Skip to content

Commit 635b3fd

Browse files
committed
Rename 'article' functions and variables to use 'post' instead. Update KDocs and README
1 parent bc33dd8 commit 635b3fd

11 files changed

Lines changed: 94 additions & 83 deletions

File tree

JetNews/README.md

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,28 @@ project from Android Studio following the steps
1515

1616
## Features
1717

18-
This sample contains three screens: a list of articles, a detail page for articles, and a page to
19-
subscribe to topics of interest. The navigation from the the list of articles to the interests
18+
This sample contains three screens: a list of posts, a detail page for a post, and a page to
19+
subscribe to topics of interest. The navigation from the list of posts to the interests
2020
screen uses a navigation drawer.
2121

2222
### App scaffolding
2323

2424
Package [`com.example.jetnews.ui`][1]
2525

26-
[`JetnewsApp.kt`][2] arranges the different screens in the `NavDrawerLayout`.
26+
[`JetnewsApp.kt`][2] sets up the app's navigation state and the modal drawer used for navigation
27+
on smaller windows.
2728

28-
[`JetnewsNavGraph.kt`][3] configures the navigation routes and actions in the app.
29+
[`JetnewsNavDisplay.kt`][3] displays the primary content of the app: the list of posts, the
30+
posts themselves, and the interests page. It uses a list-detail scene strategy to adaptively
31+
display more or less content depending on the window size.
32+
33+
<img src="screenshots/jetnews_all_screens.png" alt="Screenshot">
2934

3035
[1]: app/src/main/java/com/example/jetnews/ui
3136
[2]: app/src/main/java/com/example/jetnews/ui/JetnewsApp.kt
32-
[3]: app/src/main/java/com/example/jetnews/ui/JetnewsNavGraph.kt
37+
[3]: app/src/main/java/com/example/jetnews/ui/JetnewsNavDisplay.kt
3338

34-
### Main article list
39+
### Main post list
3540

3641
Package [`com.example.jetnews.ui.home`][4]
3742

@@ -47,14 +52,14 @@ See how to:
4752

4853
[4]: app/src/main/java/com/example/jetnews/ui/home
4954

50-
### Article detail
55+
### Post detail
5156

52-
Package [`com.example.jetnews.ui.article`][5]
57+
Package [`com.example.jetnews.ui.post`][5]
5358

5459
This screen dives into the Text API, showing how to use different fonts than the ones defined in
5560
[`Typography`][6]. It also adds a bottom app bar, with custom actions.
5661

57-
[5]: app/src/main/java/com/example/jetnews/ui/article
62+
[5]: app/src/main/java/com/example/jetnews/ui/post
5863
[6]: app/src/main/java/com/example/jetnews/ui/theme/Type.kt
5964

6065
### Interests screen
@@ -99,20 +104,6 @@ UI tests can be run on device/emulators or on JVM with Robolectric.
99104
* To run Instrumented tests use the "Instrumented tests" run configuration or run the `./gradlew connectedCheck` command.
100105
* To run tests with Robolectric use the "Robolectric tests" run configuration or run the `./gradlew testDebug` command.
101106

102-
## Jetnews for every screen
103-
104-
<img src="screenshots/jetnews_all_screens.png" alt="Screenshot">
105-
106-
We recently updated Jetnews to enhance its behavior across all mobile devices, both big and small.
107-
Jetnews already had support for “traditional” mobile screens, so it was tempting to describe all of
108-
our changes as “adding large screen support.” While that is true, it misses the point of having
109-
adaptive UI. For example, if your app is running in split screen mode on a tablet, it shouldn't try
110-
to display “tablet UI” unless it actually has enough space for it. With all of these changes,
111-
Jetnews is working better than ever on large screens, but also on small screens too.
112-
113-
Check out the blog post that explains all the changes in more details:
114-
https://medium.com/androiddevelopers/jetnews-for-every-screen-4d8e7927752
115-
116107
## License
117108

118109
```

JetNews/app/src/androidTest/java/com/example/jetnews/JetnewsTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class JetnewsTests {
5353
}
5454

5555
@Test
56-
fun app_opensArticle() {
56+
fun app_opensPost() {
5757
composeTestRule.onAllNodes(hasText(manuel.name, substring = true))[0]
5858
.performScrollTo()
5959
.performClick()

JetNews/app/src/main/java/com/example/jetnews/ui/home/HomeRoute.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ import androidx.compose.runtime.getValue
3030
import androidx.compose.runtime.remember
3131
import androidx.compose.ui.Alignment
3232
import androidx.compose.ui.Modifier
33+
import androidx.compose.ui.res.stringResource
3334
import androidx.compose.ui.unit.dp
3435
import androidx.lifecycle.compose.collectAsStateWithLifecycle
3536
import androidx.lifecycle.viewmodel.compose.viewModel
3637
import androidx.navigation3.runtime.EntryProviderScope
3738
import androidx.navigation3.runtime.NavKey
39+
import com.example.jetnews.R
3840
import com.example.jetnews.data.posts.PostsRepository
3941
import com.example.jetnews.ui.navigation.ListDetailScene
4042
import kotlinx.serialization.Serializable
@@ -56,7 +58,7 @@ fun EntryProviderScope<NavKey>.homeEntry(
5658
Surface(modifier = Modifier.fillMaxSize()) {
5759
Box(contentAlignment = Alignment.Center) {
5860
Text(
59-
"Select an article",
61+
stringResource(R.string.home_detail_placeholder),
6062
style = MaterialTheme.typography.labelLarge,
6163
)
6264
}
@@ -85,6 +87,7 @@ fun EntryProviderScope<NavKey>.homeEntry(
8587
* @param homeViewModel ViewModel that handles the business logic of this screen
8688
* @param isExpandedScreen (state) whether the screen is expanded
8789
* @param openDrawer (event) request opening the app drawer
90+
* @param navigateToPost (event) request navigation to Post screen
8891
* @param snackbarHostState (state) state for the [Scaffold] component on this screen
8992
*/
9093
@Composable

JetNews/app/src/main/java/com/example/jetnews/ui/home/HomeScreens.kt

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ import com.example.jetnews.ui.theme.JetnewsTheme
9393
import kotlinx.coroutines.runBlocking
9494

9595
/**
96-
* The home screen displaying just the article feed.
96+
* The home screen displaying just the post feed.
9797
*/
9898
@Composable
9999
fun HomeFeedScreen(
@@ -123,7 +123,7 @@ fun HomeFeedScreen(
123123
postsFeed = hasPostsUiState.postsFeed,
124124
favorites = hasPostsUiState.favorites,
125125
showExpandedSearch = !showTopAppBar,
126-
onArticleTapped = onSelectPost,
126+
onPostTapped = onSelectPost,
127127
onToggleFavorite = onToggleFavorite,
128128
contentPadding = contentPadding,
129129
modifier = contentModifier,
@@ -289,18 +289,25 @@ private fun LoadingContent(
289289
/**
290290
* Display a feed of posts.
291291
*
292-
* When a post is clicked on, [onArticleTapped] will be called.
292+
* When a post is clicked on, [onPostTapped] will be called.
293293
*
294294
* @param postsFeed (state) the feed to display
295-
* @param onArticleTapped (event) request navigation to Article screen
295+
* @param favorites (state) a set of favorite posts
296+
* @param showExpandedSearch (state) whether the expanded search is shown
297+
* @param onPostTapped (event) request navigation to Post screen
298+
* @param onToggleFavorite (event) request that this post toggle its favorite state
296299
* @param modifier modifier for the root element
300+
* @param contentPadding the padding to apply to the content
301+
* @param state the state object to be used to control or observe the list's state
302+
* @param searchInput (state) the search input
303+
* @param onSearchInputChanged (event) request that the search input changed
297304
*/
298305
@Composable
299306
private fun PostList(
300307
postsFeed: PostsFeed,
301308
favorites: Set<String>,
302309
showExpandedSearch: Boolean,
303-
onArticleTapped: (postId: String) -> Unit,
310+
onPostTapped: (postId: String) -> Unit,
304311
onToggleFavorite: (String) -> Unit,
305312
modifier: Modifier = Modifier,
306313
contentPadding: PaddingValues = PaddingValues(0.dp),
@@ -322,12 +329,12 @@ private fun PostList(
322329
)
323330
}
324331
}
325-
item { PostListTopSection(postsFeed.highlightedPost, onArticleTapped) }
332+
item { PostListTopSection(postsFeed.highlightedPost, onPostTapped) }
326333
if (postsFeed.recommendedPosts.isNotEmpty()) {
327334
item {
328335
PostListSimpleSection(
329336
postsFeed.recommendedPosts,
330-
onArticleTapped,
337+
onPostTapped,
331338
favorites,
332339
onToggleFavorite,
333340
)
@@ -336,12 +343,12 @@ private fun PostList(
336343
if (postsFeed.popularPosts.isNotEmpty() && !showExpandedSearch) {
337344
item {
338345
PostListPopularSection(
339-
postsFeed.popularPosts, onArticleTapped,
346+
postsFeed.popularPosts, onPostTapped,
340347
)
341348
}
342349
}
343350
if (postsFeed.recentPosts.isNotEmpty()) {
344-
item { PostListHistorySection(postsFeed.recentPosts, onArticleTapped) }
351+
item { PostListHistorySection(postsFeed.recentPosts, onPostTapped) }
345352
}
346353
}
347354
}
@@ -364,18 +371,18 @@ private fun FullScreenLoading() {
364371
* Top section of [PostList]
365372
*
366373
* @param post (state) highlighted post to display
367-
* @param navigateToArticle (event) request navigation to Article screen
374+
* @param navigateToPost (event) request navigation to Post screen
368375
*/
369376
@Composable
370-
private fun PostListTopSection(post: Post, navigateToArticle: (String) -> Unit) {
377+
private fun PostListTopSection(post: Post, navigateToPost: (String) -> Unit) {
371378
Text(
372379
modifier = Modifier.padding(start = 16.dp, top = 16.dp, end = 16.dp),
373380
text = stringResource(id = R.string.home_top_section_title),
374381
style = MaterialTheme.typography.titleMedium,
375382
)
376383
PostCardTop(
377384
post = post,
378-
modifier = Modifier.clickable(onClick = { navigateToArticle(post.id) }),
385+
modifier = Modifier.clickable(onClick = { navigateToPost(post.id) }),
379386
)
380387
PostListDivider()
381388
}
@@ -384,20 +391,22 @@ private fun PostListTopSection(post: Post, navigateToArticle: (String) -> Unit)
384391
* Full-width list items for [PostList]
385392
*
386393
* @param posts (state) to display
387-
* @param navigateToArticle (event) request navigation to Article screen
394+
* @param navigateToPost (event) request navigation to Post screen
395+
* @param favorites (state) a set of favorite posts
396+
* @param onToggleFavorite (event) request that this post toggle its favorite state
388397
*/
389398
@Composable
390399
private fun PostListSimpleSection(
391400
posts: List<Post>,
392-
navigateToArticle: (String) -> Unit,
401+
navigateToPost: (String) -> Unit,
393402
favorites: Set<String>,
394403
onToggleFavorite: (String) -> Unit,
395404
) {
396405
Column {
397406
posts.forEach { post ->
398407
PostCardSimple(
399408
post = post,
400-
navigateToArticle = navigateToArticle,
409+
navigateToPost = navigateToPost,
401410
isFavorite = favorites.contains(post.id),
402411
onToggleFavorite = { onToggleFavorite(post.id) },
403412
)
@@ -410,10 +419,10 @@ private fun PostListSimpleSection(
410419
* Horizontal scrolling cards for [PostList]
411420
*
412421
* @param posts (state) to display
413-
* @param navigateToArticle (event) request navigation to Article screen
422+
* @param navigateToPost (event) request navigation to Post screen
414423
*/
415424
@Composable
416-
private fun PostListPopularSection(posts: List<Post>, navigateToArticle: (String) -> Unit) {
425+
private fun PostListPopularSection(posts: List<Post>, navigateToPost: (String) -> Unit) {
417426
Column {
418427
Text(
419428
modifier = Modifier.padding(16.dp),
@@ -430,7 +439,7 @@ private fun PostListPopularSection(posts: List<Post>, navigateToArticle: (String
430439
for (post in posts) {
431440
PostCardPopular(
432441
post,
433-
navigateToArticle,
442+
navigateToPost,
434443
)
435444
}
436445
}
@@ -443,13 +452,13 @@ private fun PostListPopularSection(posts: List<Post>, navigateToArticle: (String
443452
* Full-width list items that display "based on your history" for [PostList]
444453
*
445454
* @param posts (state) to display
446-
* @param navigateToArticle (event) request navigation to Article screen
455+
* @param navigateToPost (event) request navigation to Post screen
447456
*/
448457
@Composable
449-
private fun PostListHistorySection(posts: List<Post>, navigateToArticle: (String) -> Unit) {
458+
private fun PostListHistorySection(posts: List<Post>, navigateToPost: (String) -> Unit) {
450459
Column {
451460
posts.forEach { post ->
452-
PostCardHistory(post, navigateToArticle)
461+
PostCardHistory(post, navigateToPost)
453462
PostListDivider()
454463
}
455464
}

JetNews/app/src/main/java/com/example/jetnews/ui/home/PostCardYourNetwork.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ import com.example.jetnews.ui.theme.JetnewsTheme
5151

5252
@OptIn(ExperimentalMaterial3Api::class)
5353
@Composable
54-
fun PostCardPopular(post: Post, navigateToArticle: (String) -> Unit, modifier: Modifier = Modifier) {
54+
fun PostCardPopular(post: Post, navigateToPost: (String) -> Unit, modifier: Modifier = Modifier) {
5555
Card(
56-
onClick = { navigateToArticle(post.id) },
56+
onClick = { navigateToPost(post.id) },
5757
shape = MaterialTheme.shapes.medium,
5858
modifier = modifier
5959
.width(280.dp),

JetNews/app/src/main/java/com/example/jetnews/ui/home/PostCards.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ fun PostTitle(post: Post) {
8787
}
8888

8989
@Composable
90-
fun PostCardSimple(post: Post, navigateToArticle: (String) -> Unit, isFavorite: Boolean, onToggleFavorite: () -> Unit) {
90+
fun PostCardSimple(post: Post, navigateToPost: (String) -> Unit, isFavorite: Boolean, onToggleFavorite: () -> Unit) {
9191
val bookmarkAction = stringResource(if (isFavorite) R.string.unbookmark else R.string.bookmark)
9292
Row(
9393
modifier = Modifier
94-
.clickable(onClick = { navigateToArticle(post.id) })
94+
.clickable(onClick = { navigateToPost(post.id) })
9595
.semantics {
9696
// By defining a custom action, we tell accessibility services that this whole
9797
// composable has an action attached to it. The accessibility service can choose
@@ -128,12 +128,12 @@ fun PostCardSimple(post: Post, navigateToArticle: (String) -> Unit, isFavorite:
128128
}
129129

130130
@Composable
131-
fun PostCardHistory(post: Post, navigateToArticle: (String) -> Unit) {
131+
fun PostCardHistory(post: Post, navigateToPost: (String) -> Unit) {
132132
var openDialog by remember { mutableStateOf(false) }
133133

134134
Row(
135135
Modifier
136-
.clickable(onClick = { navigateToArticle(post.id) }),
136+
.clickable(onClick = { navigateToPost(post.id) }),
137137
) {
138138
PostImage(
139139
post = post,

JetNews/app/src/main/java/com/example/jetnews/ui/article/PostContent.kt renamed to JetNews/app/src/main/java/com/example/jetnews/ui/post/PostContent.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.example.jetnews.ui.article
17+
package com.example.jetnews.ui.post
1818

1919
import android.content.res.Configuration.UI_MODE_NIGHT_YES
2020
import androidx.compose.foundation.Image
@@ -146,7 +146,7 @@ private fun PostMetadata(metadata: Metadata, modifier: Modifier = Modifier) {
146146

147147
Text(
148148
text = stringResource(
149-
id = R.string.article_post_min_read,
149+
id = R.string.post_min_read,
150150
metadata.date, metadata.readTimeMinutes,
151151
),
152152
style = MaterialTheme.typography.bodySmall,

JetNews/app/src/main/java/com/example/jetnews/ui/post/PostRoute.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import androidx.lifecycle.viewmodel.compose.viewModel
3535
import androidx.navigation3.runtime.EntryProviderScope
3636
import androidx.navigation3.runtime.NavKey
3737
import com.example.jetnews.data.posts.PostsRepository
38-
import com.example.jetnews.ui.article.ArticleScreen
3938
import com.example.jetnews.ui.home.HomeKey
4039
import com.example.jetnews.ui.navigation.DeepLinkKey
4140
import com.example.jetnews.ui.navigation.ListDetailScene
@@ -106,7 +105,7 @@ fun PostRoute(
106105
}
107106
}
108107

109-
ArticleScreen(
108+
PostScreen(
110109
post = post,
111110
isExpandedScreen = isExpandedScreen,
112111
onBack = onBack,

0 commit comments

Comments
 (0)