From 13585ca0be1ae808849821b17517440a9c67964c Mon Sep 17 00:00:00 2001 From: Stypox Date: Mon, 11 Nov 2024 16:15:36 +0100 Subject: [PATCH] Avoid drawing surface background twice for comments fragment --- .../video/comment/CommentSection.kt | 96 +++++++++---------- 1 file changed, 47 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentSection.kt b/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentSection.kt index f1740c70a9..33c4e21395 100644 --- a/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentSection.kt +++ b/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentSection.kt @@ -48,71 +48,69 @@ private fun CommentSection( val nestedScrollInterop = rememberNestedScrollInteropConnection() val state = rememberLazyListState() - Surface(color = MaterialTheme.colorScheme.background) { - LazyColumnThemedScrollbar(state = state) { - LazyColumn( - modifier = Modifier.nestedScroll(nestedScrollInterop), - state = state - ) { - when (uiState) { - is Resource.Loading -> { - item { - LoadingIndicator(modifier = Modifier.padding(top = 8.dp)) - } + LazyColumnThemedScrollbar(state = state) { + LazyColumn( + modifier = Modifier.nestedScroll(nestedScrollInterop), + state = state + ) { + when (uiState) { + is Resource.Loading -> { + item { + LoadingIndicator(modifier = Modifier.padding(top = 8.dp)) } + } - is Resource.Success -> { - val commentInfo = uiState.data - val count = commentInfo.commentCount + is Resource.Success -> { + val commentInfo = uiState.data + val count = commentInfo.commentCount - if (commentInfo.isCommentsDisabled) { - item { - NoItemsMessage(R.string.comments_are_disabled) - } - } else if (count == 0) { + if (commentInfo.isCommentsDisabled) { + item { + NoItemsMessage(R.string.comments_are_disabled) + } + } else if (count == 0) { + item { + NoItemsMessage(R.string.no_comments) + } + } else { + // do not show anything if the comment count is unknown + if (count >= 0) { item { - NoItemsMessage(R.string.no_comments) + Text( + modifier = Modifier + .padding(start = 12.dp, end = 12.dp, bottom = 4.dp), + text = pluralStringResource(R.plurals.comments, count, count), + maxLines = 1, + style = MaterialTheme.typography.titleMedium + ) } - } else { - // do not show anything if the comment count is unknown - if (count >= 0) { + } + + when (comments.loadState.refresh) { + is LoadState.Loading -> { item { - Text( - modifier = Modifier - .padding(start = 12.dp, end = 12.dp, bottom = 4.dp), - text = pluralStringResource(R.plurals.comments, count, count), - maxLines = 1, - style = MaterialTheme.typography.titleMedium - ) + LoadingIndicator(modifier = Modifier.padding(top = 8.dp)) } } - when (comments.loadState.refresh) { - is LoadState.Loading -> { - item { - LoadingIndicator(modifier = Modifier.padding(top = 8.dp)) - } - } - - is LoadState.Error -> { - item { - NoItemsMessage(R.string.error_unable_to_load_comments) - } + is LoadState.Error -> { + item { + NoItemsMessage(R.string.error_unable_to_load_comments) } + } - else -> { - items(comments.itemCount) { - Comment(comment = comments[it]!!) {} - } + else -> { + items(comments.itemCount) { + Comment(comment = comments[it]!!) {} } } } } + } - is Resource.Error -> { - item { - NoItemsMessage(R.string.error_unable_to_load_comments) - } + is Resource.Error -> { + item { + NoItemsMessage(R.string.error_unable_to_load_comments) } } }