1717package com.google.samples.apps.nowinandroid.feature.bookmarks
1818
1919import androidx.compose.foundation.layout.Arrangement
20- import androidx.compose.foundation.layout.ExperimentalLayoutApi
20+ import androidx.compose.foundation.layout.Box
2121import androidx.compose.foundation.layout.PaddingValues
2222import androidx.compose.foundation.layout.Spacer
2323import androidx.compose.foundation.layout.WindowInsets
24+ import androidx.compose.foundation.layout.fillMaxHeight
2425import androidx.compose.foundation.layout.fillMaxSize
2526import androidx.compose.foundation.layout.fillMaxWidth
2627import androidx.compose.foundation.layout.safeDrawing
@@ -30,9 +31,10 @@ import androidx.compose.foundation.lazy.grid.GridCells.Adaptive
3031import androidx.compose.foundation.lazy.grid.GridItemSpan
3132import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
3233import androidx.compose.foundation.lazy.grid.rememberLazyGridState
33- import androidx.compose.material3.ExperimentalMaterial3Api
34+ import androidx.compose.material3.Text
3435import androidx.compose.runtime.Composable
3536import androidx.compose.runtime.getValue
37+ import androidx.compose.ui.Alignment
3638import androidx.compose.ui.Modifier
3739import androidx.compose.ui.platform.testTag
3840import androidx.compose.ui.res.stringResource
@@ -59,7 +61,6 @@ internal fun BookmarksRoute(
5961 )
6062}
6163
62- @OptIn(ExperimentalMaterial3Api ::class , ExperimentalLayoutApi ::class )
6364@Composable
6465fun BookmarksScreen (
6566 feedState : NewsFeedUiState ,
@@ -78,25 +79,41 @@ fun BookmarksScreen(
7879 .fillMaxSize()
7980 .testTag(" bookmarks:feed" )
8081 ) {
81- if (feedState is NewsFeedUiState .Loading ) {
82- item(span = { GridItemSpan (maxLineSpan) }) {
83- NiaLoadingWheel (
84- modifier = Modifier
85- .fillMaxWidth()
86- .wrapContentSize()
87- .testTag(" forYou:loading" ),
88- contentDesc = stringResource(id = R .string.saved_loading),
89- )
90- }
91- }
9282
93- newsFeed(
94- feedState = feedState,
95- onNewsResourcesCheckedChanged = { id, _ -> removeFromBookmarks(id) },
96- )
83+ when (feedState) {
84+ is NewsFeedUiState .Loading -> {
85+ item(span = { GridItemSpan (maxLineSpan) }) {
86+ NiaLoadingWheel (
87+ modifier = Modifier
88+ .fillMaxWidth()
89+ .wrapContentSize()
90+ .testTag(" forYou:loading" ),
91+ contentDesc = stringResource(id = R .string.saved_loading),
92+ )
93+ }
94+ }
9795
98- item(span = { GridItemSpan (maxLineSpan) }) {
99- Spacer (Modifier .windowInsetsBottomHeight(WindowInsets .safeDrawing))
96+ is NewsFeedUiState .Success -> {
97+ if (feedState.feed.isNotEmpty()) {
98+ newsFeed(
99+ feedState = feedState,
100+ onNewsResourcesCheckedChanged = { id, _ -> removeFromBookmarks(id) },
101+ )
102+ item(span = { GridItemSpan (maxLineSpan) }) {
103+ Spacer (Modifier .windowInsetsBottomHeight(WindowInsets .safeDrawing))
104+ }
105+ } else item(span = { GridItemSpan (maxLineSpan) }) {
106+ Box (
107+ modifier = Modifier
108+ .fillMaxHeight()
109+ .wrapContentSize()
110+ .testTag(" bookmarks:empty" ),
111+ contentAlignment = Alignment .Center
112+ ) {
113+ Text (text = stringResource(id = R .string.bookmarks_empty))
114+ }
115+ }
116+ }
100117 }
101118 }
102119}
0 commit comments