@@ -12,7 +12,6 @@ import androidx.compose.material3.MaterialTheme
1212import androidx.compose.material3.Surface
1313import androidx.compose.material3.Text
1414import androidx.compose.runtime.Composable
15- import androidx.compose.runtime.LaunchedEffect
1615import androidx.compose.runtime.getValue
1716import androidx.compose.ui.Alignment
1817import androidx.compose.ui.Modifier
@@ -31,7 +30,6 @@ import kotlinx.coroutines.flow.flowOf
3130import org.schabi.newpipe.R
3231import org.schabi.newpipe.error.ErrorInfo
3332import org.schabi.newpipe.error.UserAction
34- import org.schabi.newpipe.extractor.Page
3533import org.schabi.newpipe.extractor.comments.CommentsInfoItem
3634import org.schabi.newpipe.extractor.stream.Description
3735import org.schabi.newpipe.ui.components.common.ErrorPanel
@@ -46,28 +44,18 @@ import org.schabi.newpipe.viewmodels.util.Resource
4644@Composable
4745fun CommentSection (commentsViewModel : CommentsViewModel = viewModel()) {
4846 val state by commentsViewModel.uiState.collectAsStateWithLifecycle()
49- val liveChatItems by commentsViewModel.liveChatItems.collectAsStateWithLifecycle()
50- CommentSection (state, commentsViewModel.comments, liveChatItems)
47+ CommentSection (state, commentsViewModel.comments)
5148}
5249
5350@Composable
5451private fun CommentSection (
5552 uiState : Resource <CommentInfo >,
56- commentsFlow : Flow <PagingData <CommentsInfoItem >>,
57- liveChatItems : List <CommentsInfoItem >
53+ commentsFlow : Flow <PagingData <CommentsInfoItem >>
5854) {
5955 val comments = commentsFlow.collectAsLazyPagingItems()
6056 val nestedScrollInterop = rememberNestedScrollInteropConnection()
6157 val state = rememberLazyListState()
6258
63- // Auto-scroll to top when new live chat messages arrive
64- val isLiveChat = uiState is Resource .Success && uiState.data.isLiveChat
65- LaunchedEffect (liveChatItems.size) {
66- if (isLiveChat && liveChatItems.isNotEmpty()) {
67- state.scrollToItem(0 )
68- }
69- }
70-
7159 LazyColumnThemedScrollbar (state = state) {
7260 LazyColumn (
7361 modifier = Modifier
@@ -86,17 +74,16 @@ private fun CommentSection(
8674 val commentInfo = uiState.data
8775 val count = commentInfo.commentCount
8876
89- if (commentInfo.isCommentsDisabled && ! commentInfo.isLiveChat ) {
77+ if (commentInfo.isCommentsDisabled) {
9078 item {
9179 EmptyStateComposable (
9280 spec = EmptyStateSpec .DisabledComments ,
9381 modifier = Modifier
9482 .fillMaxWidth()
9583 .heightIn(min = 128 .dp)
96-
9784 )
9885 }
99- } else if (count == 0 && ! commentInfo.isLiveChat ) {
86+ } else if (count == 0 ) {
10087 item {
10188 EmptyStateComposable (
10289 spec = EmptyStateSpec .NoComments ,
@@ -106,8 +93,7 @@ private fun CommentSection(
10693 )
10794 }
10895 } else {
109- // Show title for regular comments, but not for live chat
110- if (count >= 0 && ! commentInfo.isLiveChat) {
96+ if (count >= 0 ) {
11197 item {
11298 Text (
11399 modifier = Modifier
@@ -119,66 +105,47 @@ private fun CommentSection(
119105 }
120106 }
121107
122- if (commentInfo.isLiveChat) {
123- // Live chat: render items directly without Paging 3
124- if (liveChatItems.isEmpty()) {
108+ when (val refresh = comments.loadState.refresh) {
109+ is LoadState .Loading -> {
125110 item {
126- EmptyStateComposable (
127- spec = EmptyStateSpec .NoComments ,
128- modifier = Modifier
129- .fillMaxWidth()
130- .heightIn(min = 128 .dp)
131- )
132- }
133- } else {
134- items(liveChatItems.size, key = { liveChatItems[it].commentId }) {
135- Comment (comment = liveChatItems[it]) {}
111+ LoadingIndicator (modifier = Modifier .padding(top = 8 .dp))
136112 }
137113 }
138- } else {
139- // Normal comments via Paging 3
140- when (val refresh = comments.loadState.refresh) {
141- is LoadState .Loading -> {
142- item {
143- LoadingIndicator (modifier = Modifier .padding(top = 8 .dp))
114+
115+ is LoadState .Error -> {
116+ val errorInfo = ErrorInfo (
117+ throwable = refresh.error,
118+ userAction = UserAction .REQUESTED_COMMENTS ,
119+ request = " comments"
120+ )
121+
122+ item {
123+ Box (
124+ modifier = Modifier
125+ .fillMaxWidth()
126+ ) {
127+ ErrorPanel (
128+ errorInfo = errorInfo,
129+ onRetry = { comments.retry() },
130+ modifier = Modifier .align(Alignment .Center )
131+ )
144132 }
145133 }
134+ }
146135
147- is LoadState .Error -> {
148- val errorInfo = ErrorInfo (
149- throwable = refresh.error,
150- userAction = UserAction .REQUESTED_COMMENTS ,
151- request = " comments"
152- )
153-
136+ else -> {
137+ if (comments.itemCount == 0 ) {
154138 item {
155- Box (
139+ EmptyStateComposable (
140+ spec = EmptyStateSpec .NoComments ,
156141 modifier = Modifier
157142 .fillMaxWidth()
158- ) {
159- ErrorPanel (
160- errorInfo = errorInfo,
161- onRetry = { comments.retry() },
162- modifier = Modifier .align(Alignment .Center )
163- )
164- }
143+ .heightIn(min = 128 .dp)
144+ )
165145 }
166- }
167-
168- else -> {
169- if (comments.itemCount == 0 ) {
170- item {
171- EmptyStateComposable (
172- spec = EmptyStateSpec .NoComments ,
173- modifier = Modifier
174- .fillMaxWidth()
175- .heightIn(min = 128 .dp)
176- )
177- }
178- } else {
179- items(comments.itemCount) {
180- Comment (comment = comments[it]!! ) {}
181- }
146+ } else {
147+ items(comments.itemCount) {
148+ Comment (comment = comments[it]!! ) {}
182149 }
183150 }
184151 }
@@ -217,7 +184,7 @@ private fun CommentSection(
217184private fun CommentSectionLoadingPreview () {
218185 AppTheme {
219186 Surface {
220- CommentSection (uiState = Resource .Loading , commentsFlow = flowOf(), liveChatItems = emptyList() )
187+ CommentSection (uiState = Resource .Loading , commentsFlow = flowOf())
221188 }
222189 }
223190}
@@ -233,7 +200,7 @@ private fun CommentSectionSuccessPreview() {
233200 Description .PLAIN_TEXT
234201 ),
235202 uploaderName = " Test" ,
236- replies = Page (" " ),
203+ replies = org.schabi.newpipe.extractor. Page (" " ),
237204 replyCount = 10
238205 )
239206 ) + (2 .. 10 ).map {
@@ -253,12 +220,10 @@ private fun CommentSectionSuccessPreview() {
253220 comments = comments,
254221 nextPage = null ,
255222 commentCount = 10 ,
256- isCommentsDisabled = false ,
257- isLiveChat = false
223+ isCommentsDisabled = false
258224 )
259225 ),
260- commentsFlow = flowOf(PagingData .from(comments)),
261- liveChatItems = emptyList()
226+ commentsFlow = flowOf(PagingData .from(comments))
262227 )
263228 }
264229 }
@@ -270,7 +235,7 @@ private fun CommentSectionSuccessPreview() {
270235private fun CommentSectionErrorPreview () {
271236 AppTheme {
272237 Surface {
273- CommentSection (uiState = Resource .Error (RuntimeException ()), commentsFlow = flowOf(), liveChatItems = emptyList() )
238+ CommentSection (uiState = Resource .Error (RuntimeException ()), commentsFlow = flowOf())
274239 }
275240 }
276241}
0 commit comments