fix: clean up BookmarksGrid - use Success type directly, add Uri import

Co-Authored-By: Claude <noreply@anthropic.com>
pull/2125/head
Rohit Karadkar 3 months ago
parent ccd12a78d1
commit 9955be921c

@ -16,6 +16,7 @@
package com.google.samples.apps.nowinandroid.feature.bookmarks.impl package com.google.samples.apps.nowinandroid.feature.bookmarks.impl
import android.net.Uri
import androidx.annotation.VisibleForTesting import androidx.annotation.VisibleForTesting
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
@ -190,7 +191,7 @@ private fun LoadingState(modifier: Modifier = Modifier) {
@Composable @Composable
private fun BookmarksGrid( private fun BookmarksGrid(
feedState: NewsFeedUiState, feedState: Success,
removeFromBookmarks: (String) -> Unit, removeFromBookmarks: (String) -> Unit,
onNewsResourceViewed: (String) -> Unit, onNewsResourceViewed: (String) -> Unit,
onTopicClick: (String) -> Unit, onTopicClick: (String) -> Unit,
@ -213,8 +214,7 @@ private fun BookmarksGrid(
.fillMaxSize() .fillMaxSize()
.testTag("bookmarks:feed"), .testTag("bookmarks:feed"),
) { ) {
if (feedState is Success) { items(
items(
items = feedState.feed, items = feedState.feed,
key = { it.id }, key = { it.id },
contentType = { "newsFeedItem" }, contentType = { "newsFeedItem" },
@ -237,7 +237,7 @@ private fun BookmarksGrid(
) )
launchCustomChromeTab( launchCustomChromeTab(
context, context,
android.net.Uri.parse(userNewsResource.url), Uri.parse(userNewsResource.url),
backgroundColor, backgroundColor,
) )
onNewsResourceViewed(userNewsResource.id) onNewsResourceViewed(userNewsResource.id)
@ -261,15 +261,11 @@ private fun BookmarksGrid(
} }
} }
} }
}
item(span = StaggeredGridItemSpan.FullLine) { item(span = StaggeredGridItemSpan.FullLine) {
Spacer(Modifier.windowInsetsBottomHeight(WindowInsets.safeDrawing)) Spacer(Modifier.windowInsetsBottomHeight(WindowInsets.safeDrawing))
} }
} }
val itemsAvailable = when (feedState) { val itemsAvailable = feedState.feed.size
Loading -> 1
is Success -> feedState.feed.size
}
val scrollbarState = scrollableState.scrollbarState( val scrollbarState = scrollableState.scrollbarState(
itemsAvailable = itemsAvailable, itemsAvailable = itemsAvailable,
) )

Loading…
Cancel
Save