From a53af77705b8186e13b3b06a51e4bb0250be5ba6 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sun, 7 Jul 2024 23:42:19 +0530 Subject: [PATCH] feat(common): visually distinguish between read and unread comments --- .../claw/common/comments/CommentEntry.kt | 18 ++++-------------- .../msfjarvis/claw/common/comments/Comments.kt | 14 +++++++++++++- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentEntry.kt b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentEntry.kt index e7de53cd..4e4c7cbb 100644 --- a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentEntry.kt +++ b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentEntry.kt @@ -30,11 +30,8 @@ import androidx.compose.runtime.produceState import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.text.AnnotatedString -import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.buildAnnotatedString -import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow -import androidx.compose.ui.text.withStyle import androidx.compose.ui.unit.dp import com.github.michaelbull.result.coroutines.runSuspendCatching import com.github.michaelbull.result.onSuccess @@ -140,7 +137,10 @@ internal fun CommentEntry( modifier .fillMaxWidth() .clickable { toggleExpanded(commentNode) } - .background(MaterialTheme.colorScheme.background) + .background( + if (commentNode.isUnread) MaterialTheme.colorScheme.surfaceBright + else MaterialTheme.colorScheme.background + ) .padding( start = CommentEntryPadding * commentNode.indentLevel, end = CommentEntryPadding, @@ -154,7 +154,6 @@ internal fun CommentEntry( buildCommenterString( commenterName = comment.user, score = comment.score, - isUnread = commentNode.isUnread, createdAt = comment.createdAt, updatedAt = comment.updatedAt, ), @@ -176,7 +175,6 @@ internal fun CommentEntry( fun buildCommenterString( commenterName: String, score: Int, - isUnread: Boolean, createdAt: TemporalAccessor, updatedAt: TemporalAccessor, ): AnnotatedString { @@ -215,13 +213,5 @@ fun buildCommenterString( append(updatedRelative.toString()) append(')') } - if (isUnread) { - append(' ') - withStyle( - style = SpanStyle(fontWeight = FontWeight.Bold, color = MaterialTheme.colorScheme.error) - ) { - append("(unread)") - } - } } } diff --git a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/Comments.kt b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/Comments.kt index 2f97361c..7520c396 100644 --- a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/Comments.kt +++ b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/Comments.kt @@ -6,6 +6,7 @@ */ package dev.msfjarvis.claw.common.comments +import android.widget.Toast import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxSize @@ -22,6 +23,7 @@ import androidx.compose.runtime.produceState import androidx.compose.runtime.toMutableStateList import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp @@ -49,8 +51,18 @@ private fun CommentsPageInternal( openUserProfile: (String) -> Unit, modifier: Modifier = Modifier, ) { + val context = LocalContext.current val commentNodes = createListNode(details.comments, commentState).toMutableStateList() - LaunchedEffect(key1 = commentNodes) { markSeenComments(details.shortId, details.comments) } + LaunchedEffect(key1 = commentNodes) { + if (details.comments.isNotEmpty() && !commentState?.commentIds.isNullOrEmpty()) { + val unreadCount = details.comments.size - (commentState?.commentIds?.size ?: 0) + if (unreadCount > 0) { + val text = "$unreadCount unread comments" + Toast.makeText(context, text, Toast.LENGTH_SHORT).show() + } + } + markSeenComments(details.shortId, details.comments) + } Surface(color = MaterialTheme.colorScheme.surfaceVariant) { LazyColumn(modifier = modifier, contentPadding = PaddingValues(bottom = 24.dp)) {