Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import android.widget.ImageView
import androidx.annotation.DrawableRes
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
Expand All @@ -30,7 +29,6 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.InlineTextContent
import androidx.compose.foundation.text.appendInlineContent
import androidx.compose.material3.Icon
Expand Down Expand Up @@ -102,8 +100,6 @@ private const val ICON_MSG_SIZE_DP = 14
private const val ICON_MSG_SPACING_DP = 2
private const val THREAD_ICON_ID = "threadIcon"
private const val THREAD_ICON_SIZE_SP = 14
private const val UNREAD_THRESHOLD = 1000
private const val UNREAD_BUBBLE_STROKE_DP = 1.5f
private const val MILLIS_PER_SECOND = 1_000L

/** Groups the tap callbacks for [ConversationListItem] to keep the parameter count low. */
Expand Down Expand Up @@ -519,75 +515,12 @@ private fun ConversationLastMessageRow(
private fun UnreadBubble(model: ConversationModel, currentUser: User) {
if (model.unreadMessages <= 0) return

val text = if (model.unreadMessages >= UNREAD_THRESHOLD) {
stringResource(R.string.tooManyUnreadMessages)
} else {
model.unreadMessages.toString()
}

val isOneToOne = model.type == ConversationEnums.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL
val hasDmFlag = hasSpreedFeatureCapability(
currentUser.capabilities?.spreedCapability,
SpreedFeatures.DIRECT_MENTION_FLAG
)
val outlined = model.unreadMention && hasDmFlag && !model.unreadMentionDirect && !isOneToOne

when {
outlined -> OutlinedUnreadChip(text = text)
isOneToOne || model.unreadMention -> FilledUnreadChip(text = text)
else -> GreyUnreadChip(text = text)
}
}

@Composable
private fun FilledUnreadChip(text: String) {
Box(
modifier = Modifier
.background(MaterialTheme.colorScheme.primary, RoundedCornerShape(12.dp))
.padding(horizontal = 6.dp, vertical = 2.dp),
contentAlignment = Alignment.Center
) {
Text(
text = text,
color = MaterialTheme.colorScheme.onPrimary,
style = MaterialTheme.typography.labelSmall,
fontWeight = FontWeight.Bold
)
}
}

@Composable
private fun OutlinedUnreadChip(text: String) {
Box(
modifier = Modifier
.border(UNREAD_BUBBLE_STROKE_DP.dp, MaterialTheme.colorScheme.primary, RoundedCornerShape(12.dp))
.padding(horizontal = 6.dp, vertical = 2.dp),
contentAlignment = Alignment.Center
) {
Text(
text = text,
color = MaterialTheme.colorScheme.primary,
style = MaterialTheme.typography.labelSmall,
fontWeight = FontWeight.Bold
)
}
}

@Composable
private fun GreyUnreadChip(text: String) {
Box(
modifier = Modifier
.background(colorResource(R.color.conversation_unread_bubble), RoundedCornerShape(12.dp))
.padding(horizontal = 6.dp, vertical = 2.dp),
contentAlignment = Alignment.Center
) {
Text(
text = text,
color = colorResource(R.color.conversation_unread_bubble_text),
style = MaterialTheme.typography.labelSmall,
fontWeight = FontWeight.Bold
)
}
val style = unreadBadgeStyle(model, hasDmFlag) ?: return
UnreadCountBadge(count = model.unreadMessages, style = style)
}

@Suppress("LongMethod", "CyclomaticComplexMethod", "ReturnCount")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,25 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.platform.LocalViewConfiguration
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import com.nextcloud.talk.R
import com.nextcloud.talk.models.domain.ConversationModel
import com.nextcloud.talk.models.json.tags.ConversationTagDto
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collectLatest

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ConversationTagsRow(
tags: List<ConversationTagDto>,
tags: List<ConversationTagChip>,
selectedTagId: String?,
onTagSelected: (String?) -> Unit,
onManageTagsClick: () -> Unit,
Expand All @@ -61,12 +65,13 @@ fun ConversationTagsRow(
onLongClick = onManageTagsClick
)
}
items(tags, key = { it.id }) { tag ->
items(tags, key = { it.tag.id }) { (tag, unreadInfo) ->
val isSelected = tag.id == selectedTagId
val isFavorites = tag.type == ConversationTagDto.TYPE_FAVORITES
TagFilterChip(
selected = isSelected,
label = if (isFavorites) stringResource(R.string.nc_conversation_tags_favorites) else tag.name,
unreadInfo = unreadInfo,
onClick = { onTagSelected(if (isSelected) null else tag.id) },
onLongClick = onManageTagsClick
)
Expand All @@ -77,7 +82,13 @@ fun ConversationTagsRow(
/** Detects long-press via the chip's own interactionSource so its native ripple stays untouched. */
@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun TagFilterChip(selected: Boolean, label: String, onClick: () -> Unit, onLongClick: () -> Unit) {
private fun TagFilterChip(
selected: Boolean,
label: String,
onClick: () -> Unit,
onLongClick: () -> Unit,
unreadInfo: TagUnreadInfo? = null
) {
val interactionSource = remember { MutableInteractionSource() }
val hapticFeedback = LocalHapticFeedback.current
val longPressTimeoutMillis = LocalViewConfiguration.current.longPressTimeoutMillis
Expand All @@ -102,16 +113,67 @@ private fun TagFilterChip(selected: Boolean, label: String, onClick: () -> Unit,
suppressClick = false
},
label = { Text(label) },
trailingIcon = unreadInfo?.let { info ->
{
val description = pluralStringResource(
R.plurals.nc_conversation_tags_unread_conversations,
info.conversationCount,
info.conversationCount
)
UnreadCountBadge(
count = info.conversationCount,
style = info.style,
modifier = Modifier.clearAndSetSemantics { contentDescription = description }
)
}
},
interactionSource = interactionSource
)
}

/**
* Unread state of a tag filter chip: [conversationCount] is the number of conversations with this tag
* that have unread messages (not the number of unread messages), [style] is the most important
* badge style among those conversations (direct mention > group mention > plain unread).
*/
data class TagUnreadInfo(val conversationCount: Int, val style: UnreadBadgeStyle)

/** A tag filter chip; [unreadInfo] is null when no conversation with this tag has unread messages. */
data class ConversationTagChip(val tag: ConversationTagDto, val unreadInfo: TagUnreadInfo? = null)

/** Builds the chips for all [tags] that have at least one of the given [rooms]. */
fun buildConversationTagChips(
tags: List<ConversationTagDto>,
rooms: List<ConversationModel>,
hasDirectMentionFlag: Boolean
): List<ConversationTagChip> {
val distinctRooms = rooms.distinctBy { it.token }
return tags.mapNotNull { tag ->
val isFavorites = tag.type == ConversationTagDto.TYPE_FAVORITES
val taggedRooms = distinctRooms.filter { if (isFavorites) it.favorite else it.tagIds.contains(tag.id) }
if (taggedRooms.isEmpty()) return@mapNotNull null

val styles = taggedRooms.mapNotNull { unreadBadgeStyle(it, hasDirectMentionFlag) }
val unreadInfo = styles.maxOrNull()?.let { TagUnreadInfo(conversationCount = styles.size, style = it) }
ConversationTagChip(tag, unreadInfo)
}
}

private fun previewTags() =
listOf(
ConversationTagDto(id = "favorites", name = "", type = ConversationTagDto.TYPE_FAVORITES),
ConversationTagDto(id = "1", name = "Work", sortOrder = 0),
ConversationTagDto(id = "2", name = "Family", sortOrder = 1),
ConversationTagDto(id = "3", name = "Projects", sortOrder = 2)
ConversationTagChip(
ConversationTagDto(id = "favorites", name = "", type = ConversationTagDto.TYPE_FAVORITES),
TagUnreadInfo(conversationCount = 1, style = UnreadBadgeStyle.FILLED)
),
ConversationTagChip(
ConversationTagDto(id = "1", name = "Work", sortOrder = 0),
TagUnreadInfo(conversationCount = 3, style = UnreadBadgeStyle.OUTLINED)
),
ConversationTagChip(
ConversationTagDto(id = "2", name = "Family", sortOrder = 1),
TagUnreadInfo(conversationCount = 2, style = UnreadBadgeStyle.GREY)
),
ConversationTagChip(ConversationTagDto(id = "3", name = "Projects", sortOrder = 2))
)

@Preview(showBackground = true, name = "Light")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,15 @@ fun ConversationsListScreen(
val hasConversationTagsCapability = state.currentUser?.capabilities?.spreedCapability?.let {
CapabilitiesUtil.hasSpreedFeatureCapability(it, SpreedFeatures.CONVERSATION_TAGS)
} == true
val nonEmptyConversationTags = remember(conversationTags, visibleRooms) {
conversationTags.filter { tag ->
if (tag.type == ConversationTagDto.TYPE_FAVORITES) {
visibleRooms.any { it.favorite }
} else {
visibleRooms.any { it.tagIds.contains(tag.id) }
}
}
val hasDirectMentionFlag = CapabilitiesUtil.hasSpreedFeatureCapability(
state.currentUser?.capabilities?.spreedCapability,
SpreedFeatures.DIRECT_MENTION_FLAG
)
val conversationTagChips = remember(conversationTags, visibleRooms, hasDirectMentionFlag) {
buildConversationTagChips(conversationTags, visibleRooms, hasDirectMentionFlag)
}
val showConversationTagsRow = hasConversationTagsCapability &&
nonEmptyConversationTags.isNotEmpty() &&
conversationTagChips.isNotEmpty() &&
!isSearchActive &&
!showShareTo &&
!isForward
Expand Down Expand Up @@ -342,7 +340,7 @@ fun ConversationsListScreen(
tagsRowContent = if (showConversationTagsRow) {
{
ConversationTagsRow(
tags = nonEmptyConversationTags,
tags = conversationTagChips,
selectedTagId = selectedTagFilter,
onTagSelected = { tagId ->
val isFavorites = conversationTags.any {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Nextcloud Talk - Android Client
*
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/

package com.nextcloud.talk.conversationlist.ui

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.CircleShape
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.graphics.Color
import androidx.compose.ui.layout.layout
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.nextcloud.talk.R
import com.nextcloud.talk.models.domain.ConversationModel
import com.nextcloud.talk.models.json.conversations.ConversationEnums

private const val UNREAD_THRESHOLD = 1000
private const val UNREAD_BUBBLE_STROKE_DP = 1.5f

/** Visual emphasis of an unread counter, ordered from lowest to highest priority. */
enum class UnreadBadgeStyle {
/** Unread messages without a mention. */
GREY,

/** Unread group mention (e.g. @all) without a direct mention. */
OUTLINED,

/** Unread direct mention, or any unread message in a one-to-one conversation. */
FILLED
}

/** Returns the badge style for a conversation's unread counter, or null if it has no unread messages. */
fun unreadBadgeStyle(model: ConversationModel, hasDirectMentionFlag: Boolean): UnreadBadgeStyle? {
if (model.unreadMessages <= 0) return null

val isOneToOne = model.type == ConversationEnums.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL
val outlined = model.unreadMention && hasDirectMentionFlag && !model.unreadMentionDirect && !isOneToOne

return when {
outlined -> UnreadBadgeStyle.OUTLINED
isOneToOne || model.unreadMention -> UnreadBadgeStyle.FILLED
else -> UnreadBadgeStyle.GREY
}
}

@Composable
fun UnreadCountBadge(count: Int, style: UnreadBadgeStyle, modifier: Modifier = Modifier) {
val text = if (count >= UNREAD_THRESHOLD) {
stringResource(R.string.tooManyUnreadMessages)
} else {
count.toString()
}

val shape = CircleShape
val (boxModifier, textColor) = when (style) {
UnreadBadgeStyle.FILLED ->
Modifier.background(MaterialTheme.colorScheme.primary, shape) to MaterialTheme.colorScheme.onPrimary

UnreadBadgeStyle.OUTLINED ->
Modifier.border(UNREAD_BUBBLE_STROKE_DP.dp, MaterialTheme.colorScheme.primary, shape) to
MaterialTheme.colorScheme.primary

UnreadBadgeStyle.GREY ->
Modifier.background(colorResource(R.color.conversation_unread_bubble), shape) to
colorResource(R.color.conversation_unread_bubble_text)
}

UnreadBadgeBox(text = text, textColor = textColor, modifier = modifier.atLeastAsWideAsTall().then(boxModifier))
}

/** Makes single digit badges a circle, longer numbers stay a pill. */
private fun Modifier.atLeastAsWideAsTall(): Modifier =
layout { measurable, constraints ->
val height = measurable.minIntrinsicHeight(constraints.maxWidth)
val minWidth = height.coerceIn(constraints.minWidth, constraints.maxWidth)
val placeable = measurable.measure(constraints.copy(minWidth = minWidth))
layout(placeable.width, placeable.height) { placeable.placeRelative(0, 0) }
}

@Composable
private fun UnreadBadgeBox(text: String, textColor: Color, modifier: Modifier) {
Box(
modifier = modifier.padding(horizontal = 6.dp, vertical = 2.dp),
contentAlignment = Alignment.Center
) {
Text(
text = text,
color = textColor,
style = MaterialTheme.typography.labelSmall,
fontWeight = FontWeight.Bold
)
}
}
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,10 @@ How to translate with transifex:
<string name="archive_hint">Once a conversation is archived, it will be hidden by default. Select the filter \"Archived\" to view archived conversations. Direct mentions will still be received.</string>
<string name="unarchive_hint">Once a conversation is unarchived, it will be shown by default again.</string>
<string name="nc_conversation_tags_filter_all">All</string>
<plurals name="nc_conversation_tags_unread_conversations">
<item quantity="one">%d conversation with unread messages</item>
<item quantity="other">%d conversations with unread messages</item>
</plurals>
<string name="nc_conversation_tags">Tags</string>
<string name="nc_conversation_tags_manage">Manage tags</string>
<string name="nc_conversation_tags_new">New tag</string>
Expand Down
Loading
Loading