enhancement: highlight inbox unread items (#185)

This commit is contained in:
Diego Beraldin 2023-12-03 09:24:21 +01:00 committed by GitHub
parent e5f45222bb
commit 9938b80b6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 81 additions and 20 deletions

View File

@ -23,6 +23,7 @@ object CornerSize {
}
object IconSize {
val xs = 10.dp
val s = 20.dp
val m = 26.dp
val l = 30.dp

View File

@ -1,14 +1,21 @@
package com.github.diegoberaldin.raccoonforlemmy.core.commonui.components
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.FiberManualRecord
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.IconSize
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.PersonMentionModel
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
@ -43,10 +50,24 @@ fun InboxCardHeader(
append(mention.post.title)
}
}
Text(
modifier = Modifier.padding(vertical = Spacing.xs, horizontal = Spacing.xs),
text = header,
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onBackground,
)
Row(
modifier = Modifier.padding(end = Spacing.s),
verticalAlignment = Alignment.CenterVertically,
) {
Text(
modifier = Modifier
.weight(1f)
.padding(vertical = Spacing.xs, horizontal = Spacing.xs),
text = header,
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onBackground,
)
if (!mention.read) {
Icon(
modifier = Modifier.size(IconSize.xs),
imageVector = Icons.Filled.FiberManualRecord,
contentDescription = null,
)
}
}
}

View File

@ -178,6 +178,18 @@ class InboxMentionsViewModel(
}
)
}
} else {
mvi.updateState {
it.copy(
mentions = currentState.mentions.map { m ->
if (m.id == mention.id) {
m.copy(read = read)
} else {
m
}
}
)
}
}
updateUnreadItems()
}

View File

@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.FiberManualRecord
import androidx.compose.material.icons.filled.MoreHoriz
import androidx.compose.material.icons.filled.Schedule
import androidx.compose.material3.Icon
@ -49,6 +50,7 @@ import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.UserModel
internal fun ChatCard(
user: UserModel?,
autoLoadImages: Boolean = true,
read: Boolean = true,
lastMessage: String,
lastMessageDate: String? = null,
modifier: Modifier = Modifier,
@ -75,8 +77,6 @@ internal fun ChatCard(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(Spacing.m),
) {
if (creatorAvatar.isNotEmpty()) {
CustomImage(
modifier = Modifier
@ -111,19 +111,33 @@ internal fun ChatCard(
}
Column(
modifier = Modifier.weight(1f),
verticalArrangement = Arrangement.spacedBy(Spacing.xxs)
) {
// user name
Text(
text = buildString {
append(creatorName)
if (creatorHost.isNotEmpty()) {
append("@$creatorHost")
}
},
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurface,
)
Row(
modifier = Modifier.padding(end = Spacing.m),
verticalAlignment = Alignment.CenterVertically,
) {
// user name
Text(
modifier = Modifier.weight(1f),
text = buildString {
append(creatorName)
if (creatorHost.isNotEmpty()) {
append("@$creatorHost")
}
},
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurface,
)
if (!read) {
Icon(
modifier = Modifier.size(IconSize.xs),
imageVector = Icons.Filled.FiberManualRecord,
contentDescription = null,
)
}
}
ScaledContent {
// last message text
PostCardTitle(

View File

@ -114,13 +114,14 @@ class InboxMessagesScreen : Tab {
items(
items = uiState.chats,
key = {
it.id.toString() + it.updateDate + uiState.unreadOnly
it.id.toString() + it.updateDate + it.read + uiState.unreadOnly
},
) { chat ->
ChatCard(
user = chat.otherUser(uiState.currentUserId),
autoLoadImages = uiState.autoLoadImages,
lastMessage = chat.content.orEmpty(),
read = chat.read,
lastMessageDate = chat.publishDate,
onOpenUser = rememberCallbackArgs { user ->
navigationCoordinator.pushScreen(

View File

@ -188,6 +188,18 @@ class InboxRepliesViewModel(
}
)
}
} else {
mvi.updateState {
it.copy(
replies = currentState.replies.map { r ->
if (r.id == mention.id) {
r.copy(read = read)
} else {
r
}
}
)
}
}
updateUnreadItems()
}