A fully functional Android app built entirely with Kotlin and Jetpack Compose
Added the check for empty list on Success
Mohsen Rznae61d9156db98
diff --git a/feature/bookmarks/src/main/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreen.kt b/feature/bookmarks/src/main/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreen.ktindex 6c45c4314..560378370 100644--- a/feature/bookmarks/src/main/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreen.kt+++ b/feature/bookmarks/src/main/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreen.kt@@ -17,10 +17,11 @@package com.google.samples.apps.nowinandroid.feature.bookmarksimport androidx.compose.foundation.layout.Arrangement-import androidx.compose.foundation.layout.ExperimentalLayoutApi+import androidx.compose.foundation.layout.Boximport androidx.compose.foundation.layout.PaddingValuesimport androidx.compose.foundation.layout.Spacerimport androidx.compose.foundation.layout.WindowInsets+import androidx.compose.foundation.layout.fillMaxHeightimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.fillMaxWidthimport androidx.compose.foundation.layout.safeDrawing@@ -30,9 +31,10 @@ import androidx.compose.foundation.lazy.grid.GridCells.Adaptiveimport androidx.compose.foundation.lazy.grid.GridItemSpanimport androidx.compose.foundation.lazy.grid.LazyVerticalGridimport androidx.compose.foundation.lazy.grid.rememberLazyGridState-import androidx.compose.material3.ExperimentalMaterial3Api+import androidx.compose.material3.Textimport androidx.compose.runtime.Composableimport androidx.compose.runtime.getValue+import androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.platform.testTagimport androidx.compose.ui.res.stringResource@@ -59,7 +61,6 @@ internal fun BookmarksRoute()}-@OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class)@Composablefun BookmarksScreen(feedState: NewsFeedUiState,@@ -78,25 +79,41 @@ fun BookmarksScreen(.fillMaxSize().testTag("bookmarks:feed")) {- if (feedState is NewsFeedUiState.Loading) {- item(span = { GridItemSpan(maxLineSpan) }) {- NiaLoadingWheel(- modifier = Modifier- .fillMaxWidth()- .wrapContentSize()- .testTag("forYou:loading"),- contentDesc = stringResource(id = R.string.saved_loading),- )- }- }- newsFeed(- feedState = feedState,- onNewsResourcesCheckedChanged = { id, _ -> removeFromBookmarks(id) },- )+ when (feedState) {+ is NewsFeedUiState.Loading -> {+ item(span = { GridItemSpan(maxLineSpan) }) {+ NiaLoadingWheel(+ modifier = Modifier+ .fillMaxWidth()+ .wrapContentSize()+ .testTag("forYou:loading"),+ contentDesc = stringResource(id = R.string.saved_loading),+ )+ }+ }- item(span = { GridItemSpan(maxLineSpan) }) {- Spacer(Modifier.windowInsetsBottomHeight(WindowInsets.safeDrawing))+ is NewsFeedUiState.Success -> {+ if (feedState.feed.isNotEmpty()) {+ newsFeed(+ feedState = feedState,+ onNewsResourcesCheckedChanged = { id, _ -> removeFromBookmarks(id) },+ )+ item(span = { GridItemSpan(maxLineSpan) }) {+ Spacer(Modifier.windowInsetsBottomHeight(WindowInsets.safeDrawing))+ }+ } else item(span = { GridItemSpan(maxLineSpan) }) {+ Box(+ modifier = Modifier+ .fillMaxHeight()+ .wrapContentSize()+ .testTag("bookmarks:empty"),+ contentAlignment = Alignment.Center+ ) {+ Text(text = stringResource(id = R.string.bookmarks_empty))+ }+ }+ }}}}