Skip to content

A fully functional Android app built entirely with Kotlin and Jetpack Compose

Merge branch 'main' into takahirom/rename-topicBody/2023-07-13

Milosz Moczkowski89a1294c633d
diff --cc feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/TopicScreen.kt
index a9c69f6b1,075e7f881..3dbbe7da8
--- a/feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/TopicScreen.kt
+++ b/feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/TopicScreen.kt
@@@ -97,45 -105,77 +105,77 @@@ internal fun TopicScreen
) {
val state = rememberLazyListState()
TrackScrollJank(scrollableState = state, stateName = "topic:screen")
- LazyColumn(
- state = state,
+ Box(
modifier = modifier,
- horizontalAlignment = Alignment.CenterHorizontally,
) {
- item {
- Spacer(Modifier.windowInsetsTopHeight(WindowInsets.safeDrawing))
- }
- when (topicUiState) {
- TopicUiState.Loading -> item {
- NiaLoadingWheel(
- modifier = modifier,
- contentDesc = stringResource(id = string.topic_loading),
- )
+ LazyColumn(
+ state = state,
+ horizontalAlignment = Alignment.CenterHorizontally,
+ ) {
+ item {
+ Spacer(Modifier.windowInsetsTopHeight(WindowInsets.safeDrawing))
}
+ when (topicUiState) {
+ TopicUiState.Loading -> item {
+ NiaLoadingWheel(
+ modifier = modifier,
+ contentDesc = stringResource(id = string.topic_loading),
+ )
+ }
- TopicUiState.Error -> TODO()
- is TopicUiState.Success -> {
- item {
- TopicToolbar(
- onBackClick = onBackClick,
- onFollowClick = onFollowClick,
- uiState = topicUiState.followableTopic,
+ TopicUiState.Error -> TODO()
+ is TopicUiState.Success -> {
+ item {
+ TopicToolbar(
+ onBackClick = onBackClick,
+ onFollowClick = onFollowClick,
+ uiState = topicUiState.followableTopic,
+ )
+ }
- TopicBody(
++ topicBody(
+ name = topicUiState.followableTopic.topic.name,
+ description = topicUiState.followableTopic.topic.longDescription,
+ news = newsUiState,
+ imageUrl = topicUiState.followableTopic.topic.imageUrl,
+ onBookmarkChanged = onBookmarkChanged,
+ onNewsResourceViewed = onNewsResourceViewed,
+ onTopicClick = onTopicClick,
)
}
- topicBody(
- name = topicUiState.followableTopic.topic.name,
- description = topicUiState.followableTopic.topic.longDescription,
- news = newsUiState,
- imageUrl = topicUiState.followableTopic.topic.imageUrl,
- onBookmarkChanged = onBookmarkChanged,
- onNewsResourceViewed = onNewsResourceViewed,
- onTopicClick = onTopicClick,
- )
+ }
+ item {
+ Spacer(Modifier.windowInsetsBottomHeight(WindowInsets.safeDrawing))
}
}
- item {
- Spacer(Modifier.windowInsetsBottomHeight(WindowInsets.safeDrawing))
- }
+ val itemsAvailable = topicItemsSize(topicUiState, newsUiState)
+ val scrollbarState = state.scrollbarState(
+ itemsAvailable = itemsAvailable,
+ )
+ state.DraggableScrollbar(
+ modifier = Modifier
+ .fillMaxHeight()
+ .windowInsetsPadding(WindowInsets.systemBars)
+ .padding(horizontal = 2.dp)
+ .align(Alignment.CenterEnd),
+ state = scrollbarState,
+ orientation = Orientation.Vertical,
+ onThumbMoved = state.rememberDraggableScroller(
+ itemsAvailable = itemsAvailable,
+ ),
+ )
+ }
+ }
+
+ private fun topicItemsSize(
+ topicUiState: TopicUiState,
+ newsUiState: NewsUiState,
+ ) = when (topicUiState) {
+ TopicUiState.Error -> 0 // Nothing
+ TopicUiState.Loading -> 1 // Loading bar
+ is TopicUiState.Success -> when (newsUiState) {
+ NewsUiState.Error -> 0 // Nothing
+ NewsUiState.Loading -> 1 // Loading bar
+ is NewsUiState.Success -> 2 + newsUiState.news.size // Toolbar, header
}
}