1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-22 02:53:09 +01:00

Added scrollbar to comment section

This commit is contained in:
Isira Seneviratne 2024-06-21 19:28:31 +05:30
parent 9c52e039ee
commit 93310955f2
2 changed files with 29 additions and 27 deletions

View File

@ -294,6 +294,7 @@ dependencies {
implementation 'androidx.activity:activity-compose' implementation 'androidx.activity:activity-compose'
implementation 'androidx.compose.ui:ui-tooling-preview' implementation 'androidx.compose.ui:ui-tooling-preview'
implementation 'androidx.compose.ui:ui-text:1.7.0-beta03' // Needed for parsing HTML to AnnotatedString implementation 'androidx.compose.ui:ui-text:1.7.0-beta03' // Needed for parsing HTML to AnnotatedString
implementation 'com.github.nanihadesuka:LazyColumnScrollbar:2.1.0'
// Paging // Paging
implementation 'androidx.paging:paging-rxjava3:3.3.0' implementation 'androidx.paging:paging-rxjava3:3.3.0'

View File

@ -2,6 +2,7 @@ package org.schabi.newpipe.fragments.list.comments
import android.content.res.Configuration import android.content.res.Configuration
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.HorizontalDivider
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
@ -10,6 +11,8 @@ import androidx.paging.PagingData
import androidx.paging.compose.collectAsLazyPagingItems import androidx.paging.compose.collectAsLazyPagingItems
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.flowOf
import my.nanihadesuka.compose.LazyColumnScrollbar
import my.nanihadesuka.compose.ScrollbarSettings
import org.schabi.newpipe.extractor.comments.CommentsInfoItem import org.schabi.newpipe.extractor.comments.CommentsInfoItem
import org.schabi.newpipe.extractor.stream.Description import org.schabi.newpipe.extractor.stream.Description
import org.schabi.newpipe.ui.theme.AppTheme import org.schabi.newpipe.ui.theme.AppTheme
@ -20,17 +23,20 @@ fun CommentSection(
parentComment: CommentsInfoItem? = null, parentComment: CommentsInfoItem? = null,
) { ) {
val replies = flow.collectAsLazyPagingItems() val replies = flow.collectAsLazyPagingItems()
val listState = rememberLazyListState()
LazyColumn { LazyColumnScrollbar(state = listState, settings = ScrollbarSettings.Default) {
if (parentComment != null) { LazyColumn(state = listState) {
item { if (parentComment != null) {
CommentRepliesHeader(comment = parentComment) item {
HorizontalDivider(thickness = 1.dp) CommentRepliesHeader(comment = parentComment)
HorizontalDivider(thickness = 1.dp)
}
} }
}
items(replies.itemCount) { items(replies.itemCount) {
Comment(comment = replies[it]!!) Comment(comment = replies[it]!!)
}
} }
} }
} }
@ -39,15 +45,13 @@ fun CommentSection(
@Preview(name = "Dark mode", uiMode = Configuration.UI_MODE_NIGHT_YES) @Preview(name = "Dark mode", uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable @Composable
private fun CommentSectionPreview() { private fun CommentSectionPreview() {
val comment1 = CommentsInfoItem( val comments = (0..100).map {
commentText = Description("This is a comment", Description.PLAIN_TEXT), CommentsInfoItem(
uploaderName = "Test", commentText = Description("Comment $it", Description.PLAIN_TEXT),
) uploaderName = "Test"
val comment2 = CommentsInfoItem( )
commentText = Description("This is another comment.<br>This is another line.", Description.HTML), }
uploaderName = "Test 2", val flow = flowOf(PagingData.from(comments))
)
val flow = flowOf(PagingData.from(listOf(comment1, comment2)))
AppTheme { AppTheme {
CommentSection(flow = flow) CommentSection(flow = flow)
@ -65,16 +69,13 @@ private fun CommentRepliesPreview() {
isPinned = true, isPinned = true,
isHeartedByUploader = true isHeartedByUploader = true
) )
val replies = (0..100).map {
val reply1 = CommentsInfoItem( CommentsInfoItem(
commentText = Description("This is a reply", Description.PLAIN_TEXT), commentText = Description("Reply $it", Description.PLAIN_TEXT),
uploaderName = "Test 2", uploaderName = "Test"
) )
val reply2 = CommentsInfoItem( }
commentText = Description("This is another reply.<br>This is another line.", Description.HTML), val flow = flowOf(PagingData.from(replies))
uploaderName = "Test 3",
)
val flow = flowOf(PagingData.from(listOf(reply1, reply2)))
AppTheme { AppTheme {
CommentSection(parentComment = comment, flow = flow) CommentSection(parentComment = comment, flow = flow)