Skip to content

Commit bbc5460

Browse files
authored
Merge pull request #427 from LinX64/bookmarks_empty_data
Handling empty bookmarks on Saved view
2 parents 13ff24e + e61d915 commit bbc5460

File tree

2 files changed

+38
-20
lines changed

2 files changed

+38
-20
lines changed

feature/bookmarks/src/main/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreen.kt

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
package com.google.samples.apps.nowinandroid.feature.bookmarks
1818

1919
import androidx.compose.foundation.layout.Arrangement
20-
import androidx.compose.foundation.layout.ExperimentalLayoutApi
20+
import androidx.compose.foundation.layout.Box
2121
import androidx.compose.foundation.layout.PaddingValues
2222
import androidx.compose.foundation.layout.Spacer
2323
import androidx.compose.foundation.layout.WindowInsets
24+
import androidx.compose.foundation.layout.fillMaxHeight
2425
import androidx.compose.foundation.layout.fillMaxSize
2526
import androidx.compose.foundation.layout.fillMaxWidth
2627
import androidx.compose.foundation.layout.safeDrawing
@@ -30,9 +31,10 @@ import androidx.compose.foundation.lazy.grid.GridCells.Adaptive
3031
import androidx.compose.foundation.lazy.grid.GridItemSpan
3132
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
3233
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
33-
import androidx.compose.material3.ExperimentalMaterial3Api
34+
import androidx.compose.material3.Text
3435
import androidx.compose.runtime.Composable
3536
import androidx.compose.runtime.getValue
37+
import androidx.compose.ui.Alignment
3638
import androidx.compose.ui.Modifier
3739
import androidx.compose.ui.platform.testTag
3840
import androidx.compose.ui.res.stringResource
@@ -59,7 +61,6 @@ internal fun BookmarksRoute(
5961
)
6062
}
6163

62-
@OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class)
6364
@Composable
6465
fun 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
}

feature/bookmarks/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@
2020
<string name="top_app_bar_title">Saved</string>
2121
<string name="top_app_bar_action_search">Search</string>
2222
<string name="top_app_bar_action_menu">Menu</string>
23+
<string name="bookmarks_empty">No bookmarks yet!</string>
2324
</resources>

0 commit comments

Comments
 (0)