diff --git a/app/src/main/java/com/jerboa/ui/components/comment/CommentNode.kt b/app/src/main/java/com/jerboa/ui/components/comment/CommentNode.kt index dffeb4aa4..10fe847dc 100644 --- a/app/src/main/java/com/jerboa/ui/components/comment/CommentNode.kt +++ b/app/src/main/java/com/jerboa/ui/components/comment/CommentNode.kt @@ -6,6 +6,7 @@ import androidx.compose.animation.expandVertically import androidx.compose.animation.shrinkVertically import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.foundation.text.selection.SelectionContainer import androidx.compose.material.AlertDialog import androidx.compose.material.Divider @@ -102,15 +103,16 @@ fun CommentBodyPreview() { CommentBody(commentView = sampleCommentView, viewSource = false) } -@Composable -fun CommentNode( +fun LazyListScope.commentNodeItem( node: CommentNodeData, + isExpanded: (commentId: Int) -> Boolean, + toggleExpanded: (commentId: Int) -> Unit, moderators: List, onUpvoteClick: (commentView: CommentView) -> Unit, onDownvoteClick: (commentView: CommentView) -> Unit, onReplyClick: (commentView: CommentView) -> Unit, onSaveClick: (commentView: CommentView) -> Unit, - onMarkAsReadClick: (commentView: CommentView) -> Unit = {}, + onMarkAsReadClick: (commentView: CommentView) -> Unit, onEditCommentClick: (commentView: CommentView) -> Unit, onDeleteCommentClick: (commentView: CommentView) -> Unit, onPersonClick: (personId: Int) -> Unit, @@ -122,16 +124,8 @@ fun CommentNode( showRead: Boolean = false, account: Account? ) { - val offset = calculateCommentOffset(node.depth, 4) - - // The ones with a border on the left need a little extra padding - val offset2 = if (node.depth == null) { - LARGE_PADDING - } else { - XXL_PADDING - } - val borderColor = calculateBorderColor(node.depth) val commentView = node.commentView + val commentId = commentView.comment.id // These are necessary for instant comment voting val score = node.commentView.counts.score @@ -139,89 +133,97 @@ fun CommentNode( val upvotes = node.commentView.counts.upvotes val downvotes = node.commentView.counts.downvotes - var expanded by remember { mutableStateOf(true) } + val offset = calculateCommentOffset(node.depth, 4) // The ones with a border on + val offset2 = if (node.depth == null) { + LARGE_PADDING + } else { + XXL_PADDING + } - var viewSource by remember { mutableStateOf(false) } + item { + var viewSource by remember { mutableStateOf(false) } - val border = Border(SMALL_PADDING, borderColor) + val backgroundColor = MaterialTheme.colors.background + val borderColor = calculateBorderColor(backgroundColor, node.depth) + val border = Border(SMALL_PADDING, borderColor) - Column( - modifier = Modifier - .padding( - start = offset - ) - ) { - Divider() Column( - modifier = Modifier.border(start = border) + modifier = Modifier + .padding( + start = offset + ) ) { + Divider() Column( - modifier = Modifier.padding(start = offset2, end = LARGE_PADDING) + modifier = Modifier.border(start = border) ) { - if (showPostAndCommunityContext) { - PostAndCommunityContextHeader( - commentView = commentView, - onCommunityClick = onCommunityClick, - onPostClick = onPostClick - ) - } - CommentNodeHeader( - commentView = commentView, - onPersonClick = onPersonClick, - score = score, - myVote = myVote, - isModerator = isModerator(commentView.creator, moderators), - onLongClick = { - expanded = !expanded - } - ) - AnimatedVisibility( - visible = expanded, - enter = expandVertically(), - exit = shrinkVertically() + Column( + modifier = Modifier.padding(start = offset2, end = LARGE_PADDING) ) { - Column { - CommentBody( + if (showPostAndCommunityContext) { + PostAndCommunityContextHeader( commentView = commentView, - viewSource = viewSource - ) - CommentFooterLine( - commentView = commentView, - onUpvoteClick = { - onUpvoteClick(it) - }, - onDownvoteClick = { - onDownvoteClick(it) - }, - onViewSourceClick = { - viewSource = !viewSource - }, - onEditCommentClick = onEditCommentClick, - onDeleteCommentClick = onDeleteCommentClick, - onReplyClick = onReplyClick, - onSaveClick = onSaveClick, - onMarkAsReadClick = onMarkAsReadClick, - onReportClick = onReportClick, - onBlockCreatorClick = onBlockCreatorClick, - showRead = showRead, - myVote = myVote, - upvotes = upvotes, - downvotes = downvotes, - account = account + onCommunityClick = onCommunityClick, + onPostClick = onPostClick ) } + CommentNodeHeader( + commentView = commentView, + onPersonClick = onPersonClick, + score = score, + myVote = myVote, + isModerator = isModerator(commentView.creator, moderators), + onLongClick = { + toggleExpanded(commentId) + } + ) + AnimatedVisibility( + visible = isExpanded(commentId), + enter = expandVertically(), + exit = shrinkVertically() + ) { + Column { + CommentBody( + commentView = commentView, + viewSource = viewSource + ) + CommentFooterLine( + commentView = commentView, + onUpvoteClick = { + onUpvoteClick(it) + }, + onDownvoteClick = { + onDownvoteClick(it) + }, + onViewSourceClick = { + viewSource = !viewSource + }, + onEditCommentClick = onEditCommentClick, + onDeleteCommentClick = onDeleteCommentClick, + onReplyClick = onReplyClick, + onSaveClick = onSaveClick, + onMarkAsReadClick = onMarkAsReadClick, + onReportClick = onReportClick, + onBlockCreatorClick = onBlockCreatorClick, + showRead = showRead, + myVote = myVote, + upvotes = upvotes, + downvotes = downvotes, + account = account + ) + } + } } } } } - AnimatedVisibility( - visible = expanded, - enter = expandVertically(), - exit = shrinkVertically() - ) { + + if (isExpanded(commentId)) { node.children?.also { nodes -> - CommentNodes( + commentNodeItems( nodes = nodes, + toggleExpanded = toggleExpanded, + isExpanded = isExpanded, onUpvoteClick = onUpvoteClick, onDownvoteClick = onDownvoteClick, onSaveClick = onSaveClick, @@ -510,10 +512,9 @@ fun CommentOptionsDialogPreview() { ) } -@Composable -fun calculateBorderColor(depth: Int?): Color { +fun calculateBorderColor(defaultBackground: Color, depth: Int?): Color { return if (depth == null) { - MaterialTheme.colors.background + defaultBackground } else { colorList[depth.mod(colorList.size)] } diff --git a/app/src/main/java/com/jerboa/ui/components/comment/CommentNodes.kt b/app/src/main/java/com/jerboa/ui/components/comment/CommentNodes.kt index 6200a0575..253ae06a3 100644 --- a/app/src/main/java/com/jerboa/ui/components/comment/CommentNodes.kt +++ b/app/src/main/java/com/jerboa/ui/components/comment/CommentNodes.kt @@ -1,7 +1,10 @@ package com.jerboa.ui.components.comment -import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateListOf +import androidx.compose.runtime.remember import com.jerboa.CommentNodeData import com.jerboa.datatypes.* import com.jerboa.db.Account @@ -26,27 +29,82 @@ fun CommentNodes( showPostAndCommunityContext: Boolean = false, showRead: Boolean = false ) { - Column { - nodes.forEach { node -> - CommentNode( - node = node, - onUpvoteClick = onUpvoteClick, - onDownvoteClick = onDownvoteClick, - onReplyClick = onReplyClick, - onSaveClick = onSaveClick, - account = account, - moderators = moderators, - onMarkAsReadClick = onMarkAsReadClick, - onPersonClick = onPersonClick, - onCommunityClick = onCommunityClick, - onPostClick = onPostClick, - onEditCommentClick = onEditCommentClick, - onDeleteCommentClick = onDeleteCommentClick, - onReportClick = onReportClick, - onBlockCreatorClick = onBlockCreatorClick, - showPostAndCommunityContext = showPostAndCommunityContext, - showRead = showRead - ) - } + // Holds the un-expanded comment ids + val unExpandedComments = remember { mutableStateListOf() } + + LazyColumn { + commentNodeItems( + nodes = nodes, + isExpanded = { commentId -> !unExpandedComments.contains(commentId) }, + toggleExpanded = { commentId -> + if (unExpandedComments.contains(commentId)) { + unExpandedComments.remove(commentId) + } else { + unExpandedComments.add(commentId) + } + }, + onUpvoteClick = onUpvoteClick, + onDownvoteClick = onDownvoteClick, + onReplyClick = onReplyClick, + onSaveClick = onSaveClick, + account = account, + moderators = moderators, + onMarkAsReadClick = onMarkAsReadClick, + onPersonClick = onPersonClick, + onCommunityClick = onCommunityClick, + onPostClick = onPostClick, + onEditCommentClick = onEditCommentClick, + onDeleteCommentClick = onDeleteCommentClick, + onReportClick = onReportClick, + onBlockCreatorClick = onBlockCreatorClick, + showPostAndCommunityContext = showPostAndCommunityContext, + showRead = showRead + ) + } +} + +fun LazyListScope.commentNodeItems( + nodes: List, + isExpanded: (commentId: Int) -> Boolean, + toggleExpanded: (commentId: Int) -> Unit, + onUpvoteClick: (commentView: CommentView) -> Unit, + onDownvoteClick: (commentView: CommentView) -> Unit, + onReplyClick: (commentView: CommentView) -> Unit, + onSaveClick: (commentView: CommentView) -> Unit, + onMarkAsReadClick: (commentView: CommentView) -> Unit, + onEditCommentClick: (commentView: CommentView) -> Unit, + onDeleteCommentClick: (commentView: CommentView) -> Unit, + onReportClick: (commentView: CommentView) -> Unit, + onPersonClick: (personId: Int) -> Unit, + onCommunityClick: (community: CommunitySafe) -> Unit, + onBlockCreatorClick: (creator: PersonSafe) -> Unit, + onPostClick: (postId: Int) -> Unit, + account: Account? = null, + moderators: List, + showPostAndCommunityContext: Boolean = false, + showRead: Boolean = false +) { + nodes.forEach { node -> + commentNodeItem( + node = node, + isExpanded = isExpanded, + toggleExpanded = toggleExpanded, + onUpvoteClick = onUpvoteClick, + onDownvoteClick = onDownvoteClick, + onReplyClick = onReplyClick, + onSaveClick = onSaveClick, + account = account, + moderators = moderators, + onMarkAsReadClick = onMarkAsReadClick, + onPersonClick = onPersonClick, + onCommunityClick = onCommunityClick, + onPostClick = onPostClick, + onEditCommentClick = onEditCommentClick, + onDeleteCommentClick = onDeleteCommentClick, + onReportClick = onReportClick, + onBlockCreatorClick = onBlockCreatorClick, + showPostAndCommunityContext = showPostAndCommunityContext, + showRead = showRead + ) } } diff --git a/app/src/main/java/com/jerboa/ui/components/common/AppBars.kt b/app/src/main/java/com/jerboa/ui/components/common/AppBars.kt index f911ef597..3c66563fe 100644 --- a/app/src/main/java/com/jerboa/ui/components/common/AppBars.kt +++ b/app/src/main/java/com/jerboa/ui/components/common/AppBars.kt @@ -449,6 +449,7 @@ fun Modifier.simpleVerticalScrollbar( ): Modifier { val targetAlpha = if (state.isScrollInProgress) 0.5f else 0f val duration = if (state.isScrollInProgress) 150 else 500 + val color = MaterialTheme.colors.onBackground val alpha by animateFloatAsState( targetValue = targetAlpha, @@ -468,7 +469,7 @@ fun Modifier.simpleVerticalScrollbar( val scrollbarHeight = state.layoutInfo.visibleItemsInfo.size * elementHeight drawRect( - color = Color.LightGray, + color = color, topLeft = Offset(this.size.width - width.toPx(), scrollbarOffsetY), size = Size(width.toPx(), scrollbarHeight), alpha = alpha diff --git a/app/src/main/java/com/jerboa/ui/components/inbox/InboxActivity.kt b/app/src/main/java/com/jerboa/ui/components/inbox/InboxActivity.kt index 16fcd9fde..e1e8b4901 100644 --- a/app/src/main/java/com/jerboa/ui/components/inbox/InboxActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/inbox/InboxActivity.kt @@ -22,7 +22,7 @@ import com.google.accompanist.swiperefresh.rememberSwipeRefreshState import com.jerboa.* import com.jerboa.db.Account import com.jerboa.db.AccountViewModel -import com.jerboa.ui.components.comment.CommentNode +import com.jerboa.ui.components.comment.CommentNodes import com.jerboa.ui.components.comment.edit.CommentEditViewModel import com.jerboa.ui.components.comment.edit.commentEditClickWrapper import com.jerboa.ui.components.comment.reply.CommentReplyViewModel @@ -263,131 +263,119 @@ fun InboxTabs( } } ) { - LazyColumn( - state = listState, - modifier = Modifier - .fillMaxSize() - // .simpleVerticalScrollbar(listState) - ) { - items( - nodes, - key = { node -> node.commentView.comment.id } - ) { node -> - CommentNode( - node = node, - onUpvoteClick = { commentView -> - account?.also { acct -> - inboxViewModel.likeComment( - commentView = commentView, - voteType = VoteType.Upvote, - account = acct, - ctx = ctx - ) - } - }, - onDownvoteClick = { commentView -> - account?.also { acct -> - inboxViewModel.likeComment( - commentView = commentView, - voteType = VoteType.Downvote, - account = acct, - ctx = ctx - ) - } - }, - onReplyClick = { commentView -> - commentReplyClickWrapper( - commentReplyViewModel = commentReplyViewModel, - parentCommentView = commentView, - postId = commentView.post.id, - navController = navController - ) - }, - onEditCommentClick = { commentView -> - commentEditClickWrapper( - commentEditViewModel, - commentView, - navController - ) - }, - onDeleteCommentClick = { commentView -> - account?.also { acct -> - inboxViewModel.deleteComment( - commentView = commentView, - account = acct, - ctx = ctx - ) - } - }, - onReportClick = { commentView -> - commentReportClickWrapper( - createReportViewModel, - commentView.comment.id, - navController - ) - }, - onSaveClick = { commentView -> - account?.also { acct -> - inboxViewModel.saveComment( - commentView = commentView, - account = acct, - ctx = ctx - ) - } - }, - onBlockCreatorClick = { - account?.also { acct -> - inboxViewModel.blockCreator( - creator = it, - account = acct, - ctx = ctx - ) - } - }, - onMarkAsReadClick = { commentView -> - account?.also { acct -> - inboxViewModel.markReplyAsRead( - commentView = commentView, - account = acct, - ctx = ctx - ) - homeViewModel.updateUnreads(commentView) - } - }, - onPersonClick = { personId -> - personClickWrapper( - personProfileViewModel, - personId, - account, - navController, - ctx - ) - }, - onCommunityClick = { community -> - communityClickWrapper( - communityViewModel = communityViewModel, - communityId = community.id, - account = account, - navController = navController, - ctx = ctx - ) - }, - onPostClick = { postId -> - postClickWrapper( - postViewModel = postViewModel, - postId = postId, - account = account, - navController = navController, - ctx = ctx - ) - }, - showPostAndCommunityContext = true, - showRead = true, + CommentNodes( + nodes = nodes, + onUpvoteClick = { commentView -> + account?.also { acct -> + inboxViewModel.likeComment( + commentView = commentView, + voteType = VoteType.Upvote, + account = acct, + ctx = ctx + ) + } + }, + onDownvoteClick = { commentView -> + account?.also { acct -> + inboxViewModel.likeComment( + commentView = commentView, + voteType = VoteType.Downvote, + account = acct, + ctx = ctx + ) + } + }, + onReplyClick = { commentView -> + commentReplyClickWrapper( + commentReplyViewModel = commentReplyViewModel, + parentCommentView = commentView, + postId = commentView.post.id, + navController = navController + ) + }, + onEditCommentClick = { commentView -> + commentEditClickWrapper( + commentEditViewModel, + commentView, + navController + ) + }, + onDeleteCommentClick = { commentView -> + account?.also { acct -> + inboxViewModel.deleteComment( + commentView = commentView, + account = acct, + ctx = ctx + ) + } + }, + onReportClick = { commentView -> + commentReportClickWrapper( + createReportViewModel, + commentView.comment.id, + navController + ) + }, + onSaveClick = { commentView -> + account?.also { acct -> + inboxViewModel.saveComment( + commentView = commentView, + account = acct, + ctx = ctx + ) + } + }, + onBlockCreatorClick = { + account?.also { acct -> + inboxViewModel.blockCreator( + creator = it, + account = acct, + ctx = ctx + ) + } + }, + onMarkAsReadClick = { commentView -> + account?.also { acct -> + inboxViewModel.markReplyAsRead( + commentView = commentView, + account = acct, + ctx = ctx + ) + homeViewModel.updateUnreads(commentView) + } + }, + onPersonClick = { personId -> + personClickWrapper( + personProfileViewModel, + personId, + account, + navController, + ctx + ) + }, + onCommunityClick = { community -> + communityClickWrapper( + communityViewModel = communityViewModel, + communityId = community.id, account = account, - moderators = listOf() + navController = navController, + ctx = ctx ) - } - } + }, + onPostClick = { postId -> + postClickWrapper( + postViewModel = postViewModel, + postId = postId, + account = account, + navController = navController, + ctx = ctx + ) + }, + showPostAndCommunityContext = true, + showRead = true, + account = account, + moderators = listOf() + ) } } diff --git a/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt b/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt index c707f3155..52452f90f 100644 --- a/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt @@ -27,7 +27,7 @@ import com.jerboa.db.AccountViewModel import com.jerboa.isScrolledToEnd import com.jerboa.openLink import com.jerboa.scrollToTop -import com.jerboa.ui.components.comment.CommentNode +import com.jerboa.ui.components.comment.CommentNodes import com.jerboa.ui.components.comment.edit.CommentEditViewModel import com.jerboa.ui.components.comment.edit.commentEditClickWrapper import com.jerboa.ui.components.comment.reply.CommentReplyViewModel @@ -75,6 +75,7 @@ fun PersonProfileActivity( val ctx = LocalContext.current val accounts by accountViewModel.allAccounts.observeAsState() val account = getCurrentAccount(accounts = accounts) + val bottomAppBarScreen = if (savedMode) { "saved" } else { "profile" } Surface(color = MaterialTheme.colors.background) { Scaffold( @@ -133,7 +134,7 @@ fun PersonProfileActivity( }, bottomBar = { BottomAppBarAll( - screen = if (savedMode) { "saved" } else { "profile" }, + screen = bottomAppBarScreen, unreadCounts = homeViewModel.unreadCountResponse, onClickProfile = { account?.id?.also { @@ -461,119 +462,109 @@ fun UserTabs( } } ) { - LazyColumn( - state = listState, - modifier = Modifier.fillMaxSize() - // .simpleVerticalScrollbar(listState) - ) { - items( - nodes, - key = { node -> node.commentView.comment.id } - ) { node -> - CommentNode( - node = node, - onUpvoteClick = { commentView -> - account?.also { acct -> - personProfileViewModel.likeComment( - commentView = commentView, - voteType = VoteType.Upvote, - account = acct, - ctx = ctx - ) - } - }, - onDownvoteClick = { commentView -> - account?.also { acct -> - personProfileViewModel.likeComment( - commentView = commentView, - voteType = VoteType.Downvote, - account = acct, - ctx = ctx - ) - } - }, - onReplyClick = { commentView -> - commentReplyClickWrapper( - commentReplyViewModel = commentReplyViewModel, - parentCommentView = commentView, - postId = commentView.post.id, - navController = navController - ) - }, - onSaveClick = { commentView -> - account?.also { acct -> - personProfileViewModel.saveComment( - commentView = commentView, - account = acct, - ctx = ctx - ) - } - }, - onPersonClick = { personId -> - personClickWrapper( - personProfileViewModel, - personId, - account, - navController, - ctx - ) - }, - onCommunityClick = { community -> - communityClickWrapper( - communityViewModel = communityViewModel, - communityId = community.id, - account = account, - navController = navController, - ctx = ctx - ) - }, - onPostClick = { postId -> - postClickWrapper( - postViewModel = postViewModel, - postId = postId, - account = account, - navController = navController, - ctx = ctx - ) - }, - onEditCommentClick = { commentView -> - commentEditClickWrapper( - commentEditViewModel, - commentView, - navController - ) - }, - onDeleteCommentClick = { commentView -> - account?.also { acct -> - personProfileViewModel.deleteComment( - commentView = commentView, - account = acct, - ctx = ctx - ) - } - }, - onReportClick = { commentView -> - commentReportClickWrapper( - createReportViewModel, - commentView.comment.id, - navController - ) - }, - onBlockCreatorClick = { - account?.also { acct -> - personProfileViewModel.blockPerson( - person = it, - account = acct, - ctx = ctx - ) - } - }, - showPostAndCommunityContext = true, + CommentNodes( + nodes = nodes, + onMarkAsReadClick = {}, + onUpvoteClick = { commentView -> + account?.also { acct -> + personProfileViewModel.likeComment( + commentView = commentView, + voteType = VoteType.Upvote, + account = acct, + ctx = ctx + ) + } + }, + onDownvoteClick = { commentView -> + account?.also { acct -> + personProfileViewModel.likeComment( + commentView = commentView, + voteType = VoteType.Downvote, + account = acct, + ctx = ctx + ) + } + }, + onReplyClick = { commentView -> + commentReplyClickWrapper( + commentReplyViewModel = commentReplyViewModel, + parentCommentView = commentView, + postId = commentView.post.id, + navController = navController + ) + }, + onSaveClick = { commentView -> + account?.also { acct -> + personProfileViewModel.saveComment( + commentView = commentView, + account = acct, + ctx = ctx + ) + } + }, + onPersonClick = { personId -> + personClickWrapper( + personProfileViewModel, + personId, + account, + navController, + ctx + ) + }, + onCommunityClick = { community -> + communityClickWrapper( + communityViewModel = communityViewModel, + communityId = community.id, account = account, - moderators = listOf() + navController = navController, + ctx = ctx ) - } - } + }, + onPostClick = { postId -> + postClickWrapper( + postViewModel = postViewModel, + postId = postId, + account = account, + navController = navController, + ctx = ctx + ) + }, + onEditCommentClick = { commentView -> + commentEditClickWrapper( + commentEditViewModel, + commentView, + navController + ) + }, + onDeleteCommentClick = { commentView -> + account?.also { acct -> + personProfileViewModel.deleteComment( + commentView = commentView, + account = acct, + ctx = ctx + ) + } + }, + onReportClick = { commentView -> + commentReportClickWrapper( + createReportViewModel, + commentView.comment.id, + navController + ) + }, + onBlockCreatorClick = { + account?.also { acct -> + personProfileViewModel.blockPerson( + person = it, + account = acct, + ctx = ctx + ) + } + }, + showPostAndCommunityContext = true, + account = account, + moderators = listOf() + ) } } } diff --git a/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt b/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt index 5a42746f0..a1dadf614 100644 --- a/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt @@ -5,7 +5,6 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material.LinearProgressIndicator import androidx.compose.material.MaterialTheme @@ -22,13 +21,14 @@ import com.jerboa.VoteType import com.jerboa.db.AccountViewModel import com.jerboa.isModerator import com.jerboa.openLink -import com.jerboa.ui.components.comment.CommentNode +import com.jerboa.ui.components.comment.commentNodeItems import com.jerboa.ui.components.comment.edit.CommentEditViewModel import com.jerboa.ui.components.comment.edit.commentEditClickWrapper import com.jerboa.ui.components.comment.reply.CommentReplyViewModel import com.jerboa.ui.components.comment.reply.commentReplyClickWrapper import com.jerboa.ui.components.common.SimpleTopAppBar import com.jerboa.ui.components.common.getCurrentAccount +import com.jerboa.ui.components.common.simpleVerticalScrollbar import com.jerboa.ui.components.community.CommunityViewModel import com.jerboa.ui.components.community.communityClickWrapper import com.jerboa.ui.components.person.PersonProfileViewModel @@ -62,6 +62,9 @@ fun PostActivity( .postView.value !== null ) + // Holds expanded comment ids + val unExpandedComments = remember { mutableStateListOf() } + val listState = rememberLazyListState() Surface(color = MaterialTheme.colors.background) { @@ -88,11 +91,10 @@ fun PostActivity( } ) { postViewModel.postView.value?.also { postView -> - // TODO LazyColumn and scrollbar is laggy here LazyColumn( state = listState, modifier = Modifier.padding(padding) - // .simpleVerticalScrollbar(listState) + .simpleVerticalScrollbar(listState) ) { item { PostListing( @@ -197,105 +199,108 @@ fun PostActivity( isModerator = isModerator(postView.creator, postViewModel.moderators) ) } - // Can't really do scrolling well here either because of tree - items( - postViewModel.commentTree, - key = { node -> node.commentView.comment.id } - ) { node -> - CommentNode( - node = node, - onUpvoteClick = { commentView -> - account?.also { acct -> - postViewModel.likeComment( - commentView = commentView, - voteType = VoteType.Upvote, - account = acct, - ctx = ctx - ) - } - }, - onDownvoteClick = { commentView -> - account?.also { acct -> - postViewModel.likeComment( - commentView = commentView, - voteType = VoteType.Downvote, - account = acct, - ctx = ctx - ) - } - }, - onReplyClick = { commentView -> - commentReplyClickWrapper( - commentReplyViewModel = commentReplyViewModel, - parentCommentView = commentView, - postId = commentView.post.id, - navController = navController + commentNodeItems( + nodes = postViewModel.commentTree, + isExpanded = { commentId -> !unExpandedComments.contains(commentId) }, + toggleExpanded = { commentId -> + if (unExpandedComments.contains(commentId)) { + unExpandedComments.remove(commentId) + } else { + unExpandedComments.add(commentId) + } + }, + onMarkAsReadClick = {}, + onUpvoteClick = { commentView -> + account?.also { acct -> + postViewModel.likeComment( + commentView = commentView, + voteType = VoteType.Upvote, + account = acct, + ctx = ctx ) - }, - onSaveClick = { commentView -> - account?.also { acct -> - postViewModel.saveComment( - commentView = commentView, - account = acct, - ctx = ctx - ) - } - }, - onPersonClick = { personId -> - personClickWrapper( - personProfileViewModel, - personId, - account, - navController, - ctx + } + }, + onDownvoteClick = { commentView -> + account?.also { acct -> + postViewModel.likeComment( + commentView = commentView, + voteType = VoteType.Downvote, + account = acct, + ctx = ctx ) - }, - onEditCommentClick = { commentView -> - commentEditClickWrapper( - commentEditViewModel, - commentView, - navController + } + }, + onReplyClick = { commentView -> + commentReplyClickWrapper( + commentReplyViewModel = commentReplyViewModel, + parentCommentView = commentView, + postId = commentView.post.id, + navController = navController + ) + }, + onSaveClick = { commentView -> + account?.also { acct -> + postViewModel.saveComment( + commentView = commentView, + account = acct, + ctx = ctx ) - }, - onDeleteCommentClick = { commentView -> - account?.also { acct -> - postViewModel.deleteComment( - commentView = commentView, - account = acct, - ctx = ctx - ) - } - }, - onReportClick = { commentView -> - commentReportClickWrapper( - createReportViewModel, - commentView.comment.id, - navController + } + }, + onPersonClick = { personId -> + personClickWrapper( + personProfileViewModel, + personId, + account, + navController, + ctx + ) + }, + onEditCommentClick = { commentView -> + commentEditClickWrapper( + commentEditViewModel, + commentView, + navController + ) + }, + onDeleteCommentClick = { commentView -> + account?.also { acct -> + postViewModel.deleteComment( + commentView = commentView, + account = acct, + ctx = ctx ) - }, - onBlockCreatorClick = { - account?.also { acct -> - postViewModel.blockCreator( - creator = it, - account = acct, - ctx = ctx - ) - } - }, - onCommunityClick = { community -> - communityClickWrapper( - communityViewModel, - community.id, - account, - navController, - ctx + } + }, + onReportClick = { commentView -> + commentReportClickWrapper( + createReportViewModel, + commentView.comment.id, + navController + ) + }, + onBlockCreatorClick = { + account?.also { acct -> + postViewModel.blockCreator( + creator = it, + account = acct, + ctx = ctx ) - }, - onPostClick = {}, // Do nothing - account = account, - moderators = postViewModel.moderators - ) - } + } + }, + onCommunityClick = { community -> + communityClickWrapper( + communityViewModel, + community.id, + account, + navController, + ctx + ) + }, + onPostClick = {}, // Do nothing + account = account, + moderators = postViewModel.moderators + ) } } } diff --git a/app/src/main/java/com/jerboa/ui/components/post/PostListings.kt b/app/src/main/java/com/jerboa/ui/components/post/PostListings.kt index 29d502567..2aade1468 100644 --- a/app/src/main/java/com/jerboa/ui/components/post/PostListings.kt +++ b/app/src/main/java/com/jerboa/ui/components/post/PostListings.kt @@ -18,6 +18,7 @@ import com.jerboa.datatypes.PostView import com.jerboa.datatypes.samplePostView import com.jerboa.db.Account import com.jerboa.isScrolledToEnd +import com.jerboa.ui.components.common.simpleVerticalScrollbar @Composable fun PostListings( @@ -51,7 +52,7 @@ fun PostListings( state = listState, modifier = Modifier .padding(padding) - // .simpleVerticalScrollbar(listState) + .simpleVerticalScrollbar(listState) ) { // TODO this should be a .also? item {