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