@@ -2,17 +2,16 @@ package org.schabi.newpipe.compose.comment
22
33import android.content.res.Configuration
44import androidx.compose.foundation.layout.Column
5+ import androidx.compose.foundation.layout.padding
56import androidx.compose.foundation.lazy.LazyColumn
67import androidx.compose.foundation.lazy.rememberLazyListState
78import androidx.compose.material3.HorizontalDivider
89import androidx.compose.material3.MaterialTheme
910import androidx.compose.material3.Surface
1011import androidx.compose.material3.Text
1112import androidx.compose.runtime.Composable
12- import androidx.compose.runtime.derivedStateOf
13- import androidx.compose.runtime.getValue
14- import androidx.compose.runtime.remember
1513import androidx.compose.ui.Alignment
14+ import androidx.compose.ui.Modifier
1615import androidx.compose.ui.res.stringResource
1716import androidx.compose.ui.tooling.preview.Preview
1817import androidx.compose.ui.tooling.preview.PreviewParameter
@@ -26,8 +25,8 @@ import androidx.paging.compose.collectAsLazyPagingItems
2625import kotlinx.coroutines.flow.Flow
2726import kotlinx.coroutines.flow.flowOf
2827import my.nanihadesuka.compose.LazyColumnScrollbar
29- import my.nanihadesuka.compose.ScrollbarSettings
3028import org.schabi.newpipe.R
29+ import org.schabi.newpipe.compose.status.LoadingIndicator
3130import org.schabi.newpipe.compose.theme.AppTheme
3231import org.schabi.newpipe.extractor.comments.CommentsInfoItem
3332import org.schabi.newpipe.extractor.stream.Description
@@ -38,26 +37,30 @@ fun CommentSection(
3837 parentComment : CommentsInfoItem ? = null,
3938 commentsFlow : Flow <PagingData <CommentsInfoItem >>
4039) {
41- val comments = commentsFlow.collectAsLazyPagingItems()
42- val itemCount by remember { derivedStateOf { comments.itemCount } }
43-
4440 Surface (color = MaterialTheme .colorScheme.background) {
41+ val comments = commentsFlow.collectAsLazyPagingItems()
4542 val refresh = comments.loadState.refresh
46- if (itemCount == 0 && refresh !is LoadState .Loading ) {
47- NoCommentsMessage ((refresh as ? LoadState .Error )?.error)
48- } else {
49- val listState = rememberLazyListState()
43+ val listState = rememberLazyListState()
5044
51- LazyColumnScrollbar (state = listState, settings = ScrollbarSettings .Default ) {
52- LazyColumn (state = listState) {
53- if (parentComment != null ) {
54- item {
55- CommentRepliesHeader (comment = parentComment)
56- HorizontalDivider (thickness = 1 .dp)
57- }
45+ LazyColumnScrollbar (state = listState) {
46+ LazyColumn (state = listState) {
47+ if (parentComment != null ) {
48+ item {
49+ CommentRepliesHeader (comment = parentComment)
50+ HorizontalDivider (thickness = 1 .dp)
5851 }
52+ }
5953
60- items(itemCount) {
54+ if (comments.itemCount == 0 ) {
55+ item {
56+ if (refresh is LoadState .Loading ) {
57+ LoadingIndicator (modifier = Modifier .padding(top = 8 .dp))
58+ } else {
59+ NoCommentsMessage ((refresh as ? LoadState .Error )?.error)
60+ }
61+ }
62+ } else {
63+ items(comments.itemCount) {
6164 Comment (comment = comments[it]!! )
6265 }
6366 }
0 commit comments